当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientResponse.bodyHandler方法代码示例

本文整理汇总了Java中io.vertx.core.http.HttpClientResponse.bodyHandler方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientResponse.bodyHandler方法的具体用法?Java HttpClientResponse.bodyHandler怎么用?Java HttpClientResponse.bodyHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.http.HttpClientResponse的用法示例。


在下文中一共展示了HttpClientResponse.bodyHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: syncHandlerEx

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
private Handler<RestResponse> syncHandlerEx(CountDownLatch countDownLatch, Holder<ResponseWrapper> holder) {
  return restResponse -> {
    RequestContext requestContext = restResponse.getRequestContext();
    HttpClientResponse response = restResponse.getResponse();
    if (response == null) {
      // 请求失败,触发请求SC的其他实例
      if (!requestContext.isRetry()) {
        retry(requestContext, syncHandlerEx(countDownLatch, holder));
      } else {
        countDownLatch.countDown();
      }

      return;
    }

    response.bodyHandler(bodyBuffer -> {
      ResponseWrapper responseWrapper = new ResponseWrapper();
      responseWrapper.response = response;
      responseWrapper.bodyBuffer = bodyBuffer;
      holder.value = responseWrapper;
      countDownLatch.countDown();
    });
  };
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:ServiceRegistryClientImpl.java

示例2: handleResponse

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
void handleResponse(Invocation invocation, HttpClientResponse clientResponse,
    AsyncResponse asyncResp) {
  clientResponse.bodyHandler(responseBuf -> {
    // 此时是在网络线程中,不应该就地处理,通过dispatcher转移线程
    invocation.getResponseExecutor().execute(() -> {
      try {
        HttpServletResponseEx responseEx =
            new VertxClientResponseToHttpServletResponse(clientResponse, responseBuf);
        for (HttpClientFilter filter : httpClientFilters) {
          Response response = filter.afterReceiveResponse(invocation, responseEx);
          if (response != null) {
            asyncResp.complete(response);
            return;
          }
        }
      } catch (Throwable e) {
        asyncResp.fail(invocation.getInvocationType(), e);
      }
    });
  });
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:22,代码来源:VertxHttpMethod.java

示例3: handleError

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
default void handleError(HttpClientResponse response) {
	response.bodyHandler(bh -> {
		String body = bh.toString();
		if (log.isDebugEnabled()) {
			log.debug(body);
		}

		log.error("Request failed with statusCode {" + response.statusCode() + "} statusMessage {" + response.statusMessage() + "} {" + body
				+ "} for method {" + getMethod() + "} and uri {" + getUri() + "}");

		// Try to parse the body data and fail using the extracted exception.
		try {
			JsonObject responseObj = new JsonObject(body);
			getFuture().fail(new MeshRestClientJsonObjectException(response.statusCode(), response.statusMessage(), responseObj));
			return;
		} catch (Exception e) {
			if (log.isDebugEnabled()) {
				log.debug("Could not deserialize response {" + body + "}.", e);
			}
		}

		getFuture().fail(new MeshRestClientMessageException(response.statusCode(), response.statusMessage()));
		return;
	});

}
 
开发者ID:gentics,项目名称:mesh,代码行数:27,代码来源:JsonObjectErrorHandler.java

示例4: handleError

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
 * Handler method which should be invoked for HTTP responses other than 2xx, 3xx status code.
 * 
 * @param response
 */
default void handleError(HttpClientResponse response) {
	response.bodyHandler(bh -> {
		String body = bh.toString();
		if (log.isDebugEnabled()) {
			log.debug(body);
		}

		log.error("Request failed with statusCode {" + response.statusCode() + "} statusMessage {" + response.statusMessage() + "} {" + body
				+ "} for method {" + getMethod() + "} and uri {" + getUri() + "}");

		// Try to parse the body data and fail using the extracted exception.
		try {
			GenericMessageResponse responseMessage = JsonUtil.readValue(body, GenericMessageResponse.class);
			getFuture().fail(new MeshRestClientMessageException(response.statusCode(), response.statusMessage(), responseMessage));
			return;
		} catch (Exception e) {
			if (log.isDebugEnabled()) {
				log.debug("Could not deserialize response {" + body + "}.", e);
			}
		}

		getFuture().fail(new MeshRestClientMessageException(response.statusCode(), response.statusMessage()));
		return;
	});
}
 
开发者ID:gentics,项目名称:mesh,代码行数:31,代码来源:GenericMessageErrorHandler.java

示例5: syncHandler

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Handler<RestResponse> syncHandler(CountDownLatch countDownLatch, Class<T> cls,
    Holder<T> holder) {
  return restResponse -> {
    RequestContext requestContext = restResponse.getRequestContext();
    HttpClientResponse response = restResponse.getResponse();
    if (response == null) {
      // 请求失败,触发请求SC的其他实例
      if (!requestContext.isRetry()) {
        retry(requestContext, syncHandler(countDownLatch, cls, holder));
      } else {
        countDownLatch.countDown();
      }
      return;
    }
    response.bodyHandler(
        bodyBuffer -> {
          if (cls.getName().equals(HttpClientResponse.class.getName())) {
            holder.value = (T) response;
            countDownLatch.countDown();
            return;
          }
          try {
            holder.value =
                JsonUtils.readValue(bodyBuffer.getBytes(), cls);
          } catch (Exception e) {
            LOGGER.warn("read value failed and response message is {}",
                bodyBuffer.toString());
          }
          countDownLatch.countDown();
        });
  };
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:34,代码来源:ServiceRegistryClientImpl.java

示例6: syncHandlerForInstances

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
private <T> Handler<RestResponse> syncHandlerForInstances(CountDownLatch countDownLatch,
    MicroserviceInstances mInstances) {
  return restResponse -> {
    RequestContext requestContext = restResponse.getRequestContext();
    HttpClientResponse response = restResponse.getResponse();
    if (response == null) {
      // 请求失败,触发请求SC的其他实例
      if (!requestContext.isRetry()) {
        retry(requestContext, syncHandlerForInstances(countDownLatch, mInstances));
      } else {
        countDownLatch.countDown();
      }
      return;
    }
    response.bodyHandler(
        bodyBuffer -> {
          try {
            mInstances.setRevision(response.getHeader("X-Resource-Revision"));
            switch (response.statusCode()) {
              case 304:
                mInstances.setNeedRefresh(false);
                break;
              case 200:
                mInstances
                    .setInstancesResponse(JsonUtils.readValue(bodyBuffer.getBytes(), FindInstancesResponse.class));
                break;
              default:
                LOGGER.warn(bodyBuffer.toString());
                break;
            }
          } catch (Exception e) {
            LOGGER.warn("read value failed and response message is {}", bodyBuffer.toString());
          }
          countDownLatch.countDown();
        });
  };
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:38,代码来源:ServiceRegistryClientImpl.java

示例7: bodyObject

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
 * Similar to {@link #body} except that it also parses the body buffer to a {@link JsonObject}
 * @param response the response from a http call
 * @return A {@link Future} that will resolve to a {@link JsonObject} if no HTTP errors or exceptions
 */
static Future<JsonObject> bodyObject(HttpClientResponse response) {
  Future<JsonObject> result = Future.future();
  response.bodyHandler(buffer -> {
    try {
      JsonObject jo = buffer.toJsonObject();
      result.complete(jo);
    } catch (Throwable err) {
      result.fail(err);
    }
  });
  return result;
}
 
开发者ID:dazraf,项目名称:vertx-futures,代码行数:18,代码来源:HttpFutures.java

示例8: bodyArray

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
 * Similar to {@link #body} except that it also parses the body buffer to a {@link JsonArray}
 * @param response the response from a http call
 * @return A {@link Future} that will resolve to a {@link JsonArray} if no HTTP errors or exceptions
 */
static Future<JsonArray> bodyArray(HttpClientResponse response) {
  Future<JsonArray> result = Future.future();
  response.bodyHandler(buffer -> {
    try {
      JsonArray ja = buffer.toJsonArray();
      result.complete(ja);
    } catch (Throwable err) {
      result.fail(err);
    }
  });
  return result;
}
 
开发者ID:dazraf,项目名称:vertx-futures,代码行数:18,代码来源:HttpFutures.java

示例9: checkGeoJsonResponse

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
private void checkGeoJsonResponse(HttpClientResponse response, TestContext context, Handler<JsonObject> handler) {
  response.bodyHandler(body -> {
    JsonObject returned = body.toJsonObject();
    context.assertNotNull(returned);
    context.assertTrue(returned.containsKey("geometries"));
    handler.handle(returned);
  });
}
 
开发者ID:georocket,项目名称:georocket,代码行数:9,代码来源:StoreEndpointTest.java

示例10: handleSuccess

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Override
public void handleSuccess(HttpClientResponse rh) {

	WebRootResponse response = new WebRootResponse();
	NodeDownloadResponse downloadResponse = new NodeDownloadResponse();
	String contentType = rh.getHeader(MeshHeaders.WEBROOT_RESPONSE_TYPE);
	if (contentType == null) {
		future.fail("The {" + MeshHeaders.WEBROOT_RESPONSE_TYPE + "} header was not set correctly.");
		return;
	}
	if (contentType.startsWith("node")) {
		// Delegate the response to the json handler
		ModelResponseHandler<NodeResponse> handler = new ModelResponseHandler<>(NodeResponse.class, getMethod(), contentType);
		handler.handle(rh);
		handler.getFuture().setHandler(rh2 -> {
			if (rh2.failed()) {
				future.fail(rh2.cause());
			} else {
				response.setNodeResponse(rh2.result());
				future.complete(response);
			}
		});
	} else {
		downloadResponse.setContentType(contentType);
		String disposition = rh.getHeader("content-disposition");
		String filename = disposition.substring(disposition.indexOf("=") + 1);
		downloadResponse.setFilename(filename);

		rh.bodyHandler(buffer -> {
			downloadResponse.setBuffer(buffer);
			response.setDownloadResponse(downloadResponse);
			future.complete(response);
		});
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:36,代码来源:WebRootResponseHandler.java

示例11: handleSuccess

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
 * Handle the mesh response. This method will deserialise the JSON response.
 */
public void handleSuccess(HttpClientResponse response) {
	String contentType = response.getHeader("Content-Type");
	//FIXME TODO in theory it would also be possible that a customer uploads JSON into mesh. In those cases we would also need to return it directly (without parsing)
	if (contentType == null && response.statusCode() == NO_CONTENT.code()) {
		if (log.isDebugEnabled()) {
			log.debug("Got {" + NO_CONTENT.code() + "} response.");
		}
		future.complete();
	} else if (contentType != null && contentType.startsWith(HttpConstants.APPLICATION_JSON)) {
		response.bodyHandler(bh -> {
			String json = bh.toString();
			if (log.isDebugEnabled()) {
				log.debug(json);
			}
			try {
				T restObj = JsonUtil.readValue(json, classOfT);
				future.complete(restObj);
			} catch (Exception e) {
				log.error("Failed to deserialize json to class {" + classOfT + "}", e);
				future.fail(e);
			}
		});
	} else {
		//TODO move regular string success handler into dedicated interface
		if (classOfT.isAssignableFrom(String.class)) {
			response.bodyHandler(buffer -> {
				future.complete((T) buffer.toString());
			});
		} else {
			response.bodyHandler(buffer -> {
				future.fail(new RuntimeException("Request can't be handled by this handler since the content type was {" + contentType + "}"));
			});
		}
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:39,代码来源:ModelResponseHandler.java

示例12: handleSuccess

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Override
public void handleSuccess(HttpClientResponse rh) {
	NodeDownloadResponse response = new NodeDownloadResponse();
	String contentType = rh.getHeader(HttpHeaders.CONTENT_TYPE.toString());
	response.setContentType(contentType);
	String disposition = rh.getHeader("content-disposition");
	String filename = disposition.substring(disposition.indexOf("=") + 1);
	response.setFilename(filename);

	rh.bodyHandler(buffer -> {
		response.setBuffer(buffer);
		future.complete(response);
	});
}
 
开发者ID:gentics,项目名称:mesh,代码行数:15,代码来源:MeshBinaryResponseHandler.java

示例13: handleSuccess

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
default void handleSuccess(HttpClientResponse response) {
	String contentType = response.getHeader("Content-Type");
	// FIXME TODO in theory it would also be possible that a customer uploads JSON into mesh. In those cases we would also need to return it directly
	// (without parsing)
	if (contentType == null && response.statusCode() == NO_CONTENT.code()) {
		if (log.isDebugEnabled()) {
			log.debug("Got {" + NO_CONTENT.code() + "} response.");
		}
		getFuture().complete();
	} else if (contentType.startsWith(HttpConstants.APPLICATION_JSON)) {
		response.bodyHandler(bh -> {
			String json = bh.toString();
			if (log.isDebugEnabled()) {
				log.debug(json);
			}
			try {
				getFuture().setBodyJson(json);
				getFuture().complete(new JsonObject(json));
			} catch (Exception e) {
				log.error("Failed to deserialize json", e);
				getFuture().fail(e);
			}
		});
	} else {
		response.bodyHandler(buffer -> {
			getFuture().fail(new RuntimeException("Request can't be handled by this handler since the content type was {" + contentType + "}"));
		});
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:30,代码来源:JsonObjectSuccessHandler.java

示例14: processText

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
private void processText(HttpClientResponse resp) {
    resp.bodyHandler(
            buffer -> {
                try {
                    parser.parse(url, buffer.toString());
                } catch (Exception e) {
                    logger.error("Failed to parse {}: {}", url, e.getMessage());
                } finally {
                    processResult();
                }
            });
}
 
开发者ID:ljie-PI,项目名称:tentacles,代码行数:13,代码来源:Downloadable.java

示例15: body

import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
 * Given a {@link HttpClientResponse} returns a {@link Future Future&lt;Buffer&gt;} for retrieving the body of the request as a {@link Buffer}
 * @param response the response from a http call
 * @return A future that will resolve to a {@link Buffer} if the Http response is not a HTTP error status
 */
static Future<Buffer> body(HttpClientResponse response) {
  Future<Buffer> result = Future.future();
  response.bodyHandler(result::complete);
  return result;
}
 
开发者ID:dazraf,项目名称:vertx-futures,代码行数:11,代码来源:HttpFutures.java


注:本文中的io.vertx.core.http.HttpClientResponse.bodyHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。