Java Code Examples for io.vertx.core.http.HttpClientResponse#handler()

The following examples show how to use io.vertx.core.http.HttpClientResponse#handler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockerModuleHandle.java    From okapi with Apache License 2.0 6 votes vote down vote up
private void handle204(HttpClientResponse res, String msg,
                       Handler<AsyncResult<Void>> future) {
  Buffer body = Buffer.buffer();
  res.handler(body::appendBuffer);
  res.endHandler(d -> {
    if (res.statusCode() == 204) {
      future.handle(Future.succeededFuture());
    } else {
      String m = msg + " HTTP error "
          + res.statusCode() + "\n"
          + body.toString();
      logger.error(m);
      future.handle(Future.failedFuture(m));
    }
  });
}
 
Example 2
Source File: HttpClientComponentImpl.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(HttpClientResponse response) {
    this.response = response;

    // The interface stipulates accumulating the whole body,
    // And as of 3.2.2 the convenience bodyHandler method doesn't always work reliably for some reason... So a DIY version.
    response.handler((Handler<Buffer>) buff -> {
        if (body == null) {
        	body = Buffer.buffer(buff.length()).appendBuffer(buff);
        } else {
        	body.appendBuffer(buff);
        }
    });

    response.endHandler((Handler<Void>) v -> {
        responseHandler.handle(AsyncResultImpl
                .<IHttpClientResponse> create(HttpClientResponseImpl.this));
    });

    response.exceptionHandler(exception -> {
    	logger.error("Exception in HttpClientResponseImpl: {0}", exception.getMessage()); //$NON-NLS-1$
    	responseHandler.handle(AsyncResultImpl.create(exception));
    });
}
 
Example 3
Source File: ProxyService.java    From okapi with Apache License 2.0 5 votes vote down vote up
private static void storeResponseInfo(ProxyContext pc, ModuleInstance mi,
                                      HttpClientResponse res) {
  String phase = mi.getRoutingEntry().getPhase();
  // It was a real handler, remember the response code and headers
  if (mi.isHandler()) {
    pc.setHandlerRes(res.statusCode());
    pc.getHandlerHeaders().setAll(res.headers());
  } else if (XOkapiHeaders.FILTER_AUTH.equalsIgnoreCase(phase)) {
    pc.setAuthRes(res.statusCode());
    pc.getAuthHeaders().setAll(res.headers());
    pc.setAuthResBody(Buffer.buffer());
    res.handler(data -> pc.getAuthResBody().appendBuffer(data));
  }
}