Java Code Examples for javax.ws.rs.client.ClientRequestContext#getMethod()

The following examples show how to use javax.ws.rs.client.ClientRequestContext#getMethod() . 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: HttpClientProducer.java    From hawkular-apm with Apache License 2.0 6 votes vote down vote up
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
    final HttpClientRequest httpClientRequest = new HttpClientRequest() {
        @Override
        public void addHeader(String s, String s1) {
            clientRequestContext.getHeaders().add(s, s1);
        }

        @Override
        public URI getUri() {
            return clientRequestContext.getUri();
        }

        @Override
        public String getHttpMethod() {
            return clientRequestContext.getMethod();
        }
    };
    requestInterceptor.handle(new HttpClientRequestAdapter(httpClientRequest, spanNameProvider));
}
 
Example 2
Source File: JAXRS20ClientServerBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void filter(ClientRequestContext rc) throws IOException {
    String method = rc.getMethod();
    String expectedMethod = null;
    if (rc.getAcceptableMediaTypes().contains(MediaType.valueOf("text/mistypedxml"))
        && rc.getHeaders().getFirst("THEMETHOD") != null) {
        expectedMethod = MediaType.TEXT_XML_TYPE.equals(rc.getMediaType()) ? "DELETE" : "GET";
        rc.setUri(URI.create("http://localhost:" + PORT + "/bookstore/books2"));
        rc.setMethod(rc.getHeaders().getFirst("THEMETHOD").toString());
        if ("GET".equals(expectedMethod)) {
            rc.getHeaders().putSingle("Content-Type", "text/xml");
        }
    } else {
        expectedMethod = "POST";
    }


    if (!expectedMethod.equals(method)) {
        throw new RuntimeException();
    }
    if ("GET".equals(expectedMethod)) {
        rc.setEntity(new Book("book", 560L));
    } else {
        rc.setEntity(new Book("book", ((Book)rc.getEntity()).getId() + 5));
    }
}
 
Example 3
Source File: NewRelicClientException.java    From newrelic-alerts-configurator with Apache License 2.0 5 votes vote down vote up
private static String formatMessage(ClientRequestContext request, ClientResponseContext response) {
    String method = request.getMethod();
    String url = request.getUri().toString();
    int statusCode = response.getStatus();
    String statusText = response.getStatusInfo().getReasonPhrase();
    return String.format("%s %s: %d %s", method, url, statusCode, statusText);
}
 
Example 4
Source File: CustomHttpMethodFilter.java    From microprofile-rest-client with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
    String httpMethod = clientRequestContext.getMethod();
    if ("MYMETHOD".equals(httpMethod)) {
        clientRequestContext.abortWith(Response.ok(httpMethod).build());
    }
    else {
        clientRequestContext.abortWith(Response.status(405).entity(httpMethod).build());
    }
}
 
Example 5
Source File: BraveClientProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(final ClientRequestContext requestContext) throws IOException {
    final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getStringHeaders(),
        requestContext.getUri(), requestContext.getMethod());

    if (holder != null) {
        requestContext.setProperty(TRACE_SPAN, holder);
    }
}
 
Example 6
Source File: OpenTracingClientProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(final ClientRequestContext requestContext) throws IOException {
    final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getStringHeaders(),
        requestContext.getUri(), requestContext.getMethod());

    if (holder != null) {
        requestContext.setProperty(TRACE_SPAN, holder);
    }
}
 
Example 7
Source File: CreateSignatureInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(ClientRequestContext requestContext) {
    // Only sign the request if we have no Body.
    if (requestContext.getEntity() == null) {
        String method = requestContext.getMethod();
        String path = requestContext.getUri().getPath();

        performSignature(requestContext.getHeaders(), path, method);
    }
}
 
Example 8
Source File: JaxrsClientExtractor.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public String getMethod(ClientRequestContext request) {
  return request.getMethod();
}