public ResteasyClientBuilderImpl useAsyncHttpEngine() { this.httpEngine = new ApacheHttpAsyncClient4Engine(HttpAsyncClients.createSystem(), true); return this; }
@Override public Response invoke(Invocation request) { // Doing blocking requests with an async httpclient is quite useless. // But it is better to use the same httpclient in any case just for sharing+configuring only one connectionpool. Future<ClientResponse> future = submit((ClientInvocation)request, false, null, new ResultExtractor<ClientResponse>() { @Override public ClientResponse extractResult(ClientResponse response) { return response; } }); try { return future.get(); } catch (InterruptedException e) { future.cancel(true); throw clientException(e, null); } catch (ExecutionException e) { throw clientException(e.getCause(), null); } }
private static HttpUriRequest buildHttpRequest(ClientInvocation request) { // Writers may change headers. Thus buffer the content before committing the headers. // For simplicity's sake the content is buffered in memory. File-buffering (ZeroCopyConsumer...) would be // possible, but resource management is error-prone. HttpRequestBase httpRequest = createHttpMethod(request.getUri(), request.getMethod()); if (request.getEntity() != null) { byte[] requestContent = requestContent(request); ByteArrayEntity entity = new ByteArrayEntity(requestContent); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, request.getHeaders().getMediaType().toString())); commitHeaders(request, httpRequest); ((HttpEntityEnclosingRequest) httpRequest).setEntity(entity); } else { commitHeaders(request, httpRequest); } return httpRequest; }
ClientInvocation request, boolean buffered, InvocationCallback<T> callback, ResultExtractor<T> extractor) HttpUriRequest httpRequest = buildHttpRequest(request);
ClientInvocation request, boolean buffered, InvocationCallback<T> callback, ResultExtractor<T> extractor) HttpUriRequest httpRequest = buildHttpRequest(request);
private static HttpUriRequest buildHttpRequest(ClientInvocation request) { // Writers may change headers. Thus buffer the content before committing the headers. // For simplicity's sake the content is buffered in memory. File-buffering (ZeroCopyConsumer...) would be // possible, but resource management is error-prone. HttpRequestBase httpRequest = createHttpMethod(request.getUri(), request.getMethod()); if (request.getEntity() != null) { byte[] requestContent = requestContent(request); ByteArrayEntity entity = new ByteArrayEntity(requestContent); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, request.getHeaders().getMediaType().toString())); commitHeaders(request, httpRequest); ((HttpEntityEnclosingRequest) httpRequest).setEntity(entity); } else { commitHeaders(request, httpRequest); } return httpRequest; }
@Override public ClientResponse invoke(ClientInvocation request) { // Doing blocking requests with an async httpclient is quite useless. // But it is better to use the same httpclient in any case just for sharing+configuring only one connectionpool. Future<ClientResponse> future = submit(request, false, null, new ResultExtractor<ClientResponse>() { @Override public ClientResponse extractResult(ClientResponse response) { return response; } }); try { return future.get(); } catch (InterruptedException e) { future.cancel(true); throw clientException(e, null); } catch (ExecutionException e) { throw clientException(e.getCause(), null); } }
public ResteasyClientBuilder useAsyncHttpEngine() { this.httpEngine = new ApacheHttpAsyncClient4Engine(HttpAsyncClients.createSystem(), true); return this; }
ClientInvocation request, boolean buffered, InvocationCallback<T> callback, ResultExtractor<T> extractor) HttpUriRequest httpRequest = buildHttpRequest(request);
private static HttpUriRequest buildHttpRequest(ClientInvocation request) { // Writers may change headers. Thus buffer the content before committing the headers. // For simplicity's sake the content is buffered in memory. File-buffering (ZeroCopyConsumer...) would be // possible, but resource management is error-prone. HttpRequestBase httpRequest = createHttpMethod(request.getUri(), request.getMethod()); if (request.getEntity() != null) { byte[] requestContent = requestContent(request); ByteArrayEntity entity = new ByteArrayEntity(requestContent); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, request.getHeaders().getMediaType().toString())); commitHeaders(request, httpRequest); ((HttpEntityEnclosingRequest) httpRequest).setEntity(entity); } else { commitHeaders(request, httpRequest); } return httpRequest; }
@Override public ClientResponse invoke(ClientInvocation request) { // Doing blocking requests with an async httpclient is quite useless. // But it is better to use the same httpclient in any case just for sharing+configuring only one connectionpool. Future<ClientResponse> future = submit(request, false, null, new ResultExtractor<ClientResponse>() { @Override public ClientResponse extractResult(ClientResponse response) { return response; } }); try { return future.get(); } catch (InterruptedException e) { future.cancel(true); throw clientException(e, null); } catch (ExecutionException e) { throw clientException(e.getCause(), null); } }
public ResteasyClientBuilder useAsyncHttpEngine() { this.httpEngine = new ApacheHttpAsyncClient4Engine(HttpAsyncClients.createSystem(), true); return this; }