Example #1
0
  @Override
  public ClientResponse apply(final ClientRequest jerseyRequest) throws ProcessingException {
    final Request jettyRequest = translateRequest(jerseyRequest);
    final Map<String, String> clientHeadersSnapshot =
        writeOutBoundHeaders(jerseyRequest.getHeaders(), jettyRequest);
    final ContentProvider entity = getBytesProvider(jerseyRequest);
    if (entity != null) {
      jettyRequest.content(entity);
    }

    try {
      final ContentResponse jettyResponse = jettyRequest.send();
      HeaderUtils.checkHeaderChanges(
          clientHeadersSnapshot,
          jerseyRequest.getHeaders(),
          JettyConnector.this.getClass().getName());

      final javax.ws.rs.core.Response.StatusType status =
          jettyResponse.getReason() == null
              ? Statuses.from(jettyResponse.getStatus())
              : Statuses.from(jettyResponse.getStatus(), jettyResponse.getReason());

      final ClientResponse jerseyResponse = new ClientResponse(status, jerseyRequest);
      processResponseHeaders(jettyResponse.getHeaders(), jerseyResponse);
      try {
        jerseyResponse.setEntityStream(new HttpClientResponseInputStream(jettyResponse));
      } catch (final IOException e) {
        LOGGER.log(Level.SEVERE, null, e);
      }

      return jerseyResponse;
    } catch (final Exception e) {
      throw new ProcessingException(e);
    }
  }
Example #2
0
  private static Map<String, String> writeOutBoundHeaders(
      final MultivaluedMap<String, Object> headers, final Request request) {
    Map<String, String> stringHeaders = HeaderUtils.asStringHeadersSingleValue(headers);

    for (Map.Entry<String, String> e : stringHeaders.entrySet()) {
      request.getHeaders().add(e.getKey(), e.getValue());
    }
    return stringHeaders;
  }