コード例 #1
0
    @Override
    public ClientResponse apply(ClientRequest requestContext) {
      final ClientResponse responseContext = new ClientResponse(Response.Status.OK, requestContext);

      final String headerValue = requestContext.getHeaderString(CsrfProtectionFilter.HEADER_NAME);
      if (headerValue != null) {
        responseContext.header(CsrfProtectionFilter.HEADER_NAME, headerValue);
      }
      return responseContext;
    }
コード例 #2
0
  /**
   * Build a new Apache's {@link org.apache.http.client.methods.HttpUriRequest} from Jersey's {@link
   * org.glassfish.jersey.client.ClientRequest}
   *
   * <p>Convert a method, URI, body, headers and override a user-agent if necessary
   *
   * @param jerseyRequest representation of an HTTP request in Jersey
   * @return a new {@link org.apache.http.client.methods.HttpUriRequest}
   */
  private HttpUriRequest buildApacheRequest(ClientRequest jerseyRequest) {
    final RequestBuilder builder =
        RequestBuilder.create(jerseyRequest.getMethod())
            .setUri(jerseyRequest.getUri())
            .setEntity(getHttpEntity(jerseyRequest));
    for (String headerName : jerseyRequest.getHeaders().keySet()) {
      builder.addHeader(headerName, jerseyRequest.getHeaderString(headerName));
    }

    final Optional<RequestConfig> requestConfig = addJerseyRequestConfig(jerseyRequest);
    requestConfig.ifPresent(builder::setConfig);

    return builder.build();
  }