/**
   * Get an Apache's {@link org.apache.http.HttpEntity} from Jersey's {@link
   * org.glassfish.jersey.client.ClientRequest}
   *
   * <p>Create a custom HTTP entity, because Jersey doesn't provide a request stream or a byte
   * buffer.
   *
   * @param jerseyRequest representation of an HTTP request in Jersey
   * @return a correct {@link org.apache.http.HttpEntity} implementation
   */
  private HttpEntity getHttpEntity(ClientRequest jerseyRequest) {
    if (jerseyRequest.getEntity() == null) {
      return null;
    }

    return chunkedEncodingEnabled
        ? new JerseyRequestHttpEntity(jerseyRequest)
        : new BufferedJerseyRequestHttpEntity(jerseyRequest);
  }
Ejemplo n.º 2
0
  private ContentProvider getStreamProvider(final ClientRequest clientRequest) {
    final Object entity = clientRequest.getEntity();

    if (entity == null) {
      return null;
    }

    final OutputStreamContentProvider streamContentProvider = new OutputStreamContentProvider();
    clientRequest.setStreamProvider(
        new OutboundMessageContext.StreamProvider() {
          @Override
          public OutputStream getOutputStream(final int contentLength) throws IOException {
            return streamContentProvider.getOutputStream();
          }
        });

    try {
      clientRequest.writeEntity();
    } catch (final IOException e) {
      throw new ProcessingException("Failed to write request entity.", e);
    }
    return streamContentProvider;
  }