org.apache.http.impl.client.AbstractResponseHandler Java Examples

The following examples show how to use org.apache.http.impl.client.AbstractResponseHandler. 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: EngineRule.java    From camunda-external-task-client-java with Apache License 2.0 6 votes vote down vote up
protected <T> ResponseHandler<T> handleResponse(final Class<T> responseDtoClass) {
  return new AbstractResponseHandler<T>() {
    @Override
    public T handleEntity(HttpEntity responseEntity) {
      T deserializedResponse = null;
      if (!responseDtoClass.isAssignableFrom(Void.class)) {
        try {
          deserializedResponse = deserializeResponse(responseEntity, responseDtoClass);
          EntityUtils.consume(responseEntity);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return deserializedResponse;
    }
  };
}
 
Example #2
Source File: SyndesisHttpClient.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public InputStream executeGET(String url, Header... headers) throws IOException{
    HttpGet request = new HttpGet(url);
    if (headers != null) {
        for (Header header : headers) {
            request.addHeader(header);
        }
    }
    addDefaultHeaders(request);

    HttpResponse response = this.client.execute(request);
    ResponseHandler<InputStream> handler = new AbstractResponseHandler<InputStream>(){
        @Override
        public InputStream handleEntity(final HttpEntity entity) throws IOException {
            return entity.getContent();
        }
    };
    return handler.handleResponse(response);
}
 
Example #3
Source File: SyndesisHttpClient.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public InputStream executePOST(String url, String payload) throws IOException{
    HttpPost request = new HttpPost(url);
    addDefaultHeaders(request);
    request.setEntity(new StringEntity(payload));
    HttpResponse response = this.client.execute(request);
    ResponseHandler<InputStream> handler = new AbstractResponseHandler<InputStream>(){
        @Override
        public InputStream handleEntity(final HttpEntity entity) throws IOException {
            return entity.getContent();
        }
    };
    return handler.handleResponse(response);
}
 
Example #4
Source File: SyndesisHttpClient.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public InputStream executeDELETE(String url) throws IOException {
    HttpDelete request = new HttpDelete(url);
    addDefaultHeaders(request);
    HttpResponse response = this.client.execute(request);
    ResponseHandler<InputStream> handler = new AbstractResponseHandler<InputStream>(){
        @Override
        public InputStream handleEntity(final HttpEntity entity) throws IOException {
            return entity.getContent();
        }
    };
    return handler.handleResponse(response);
}
 
Example #5
Source File: ResponseHandlerFactory.java    From LiquidDonkey with MIT License 5 votes vote down vote up
/**
 * Returns an entity to function result response handler.
 *
 * @param <R> the function return type, not null
 * @param function the function to apply to the response entity, not null
 * @return an entity to function result response handler, not null
 */
public static <R> ResponseHandler<R> of(IOFunction<InputStream, R> function) {
    Objects.requireNonNull(function);

    return new AbstractResponseHandler<R>() {

        @Override
        public R handleEntity(HttpEntity entity) throws IOException {
            try (InputStream inputStream = entity.getContent()) {
                return function.apply(inputStream);
            }
        }
    };
}
 
Example #6
Source File: ResponseHandlerFactory.java    From LiquidDonkey with MIT License 5 votes vote down vote up
/**
 * Returns an entity to byte array response handler.
 *
 * @return an entity to byte array response handler, not null
 */
public static ResponseHandler<byte[]> toByteArray() {
    return new AbstractResponseHandler<byte[]>() {

        @Override
        public byte[] handleEntity(HttpEntity entity) throws IOException {
            return EntityUtils.toByteArray(entity);
        }
    };
}