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

The following examples show how to use javax.ws.rs.client.ClientRequestContext#setUri() . 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: 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 2
Source File: TLAddPathClientRequestFilter.java    From microprofile-rest-client with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
    URI updatedUri = UriBuilder.fromUri(clientRequestContext.getUri())
                               .path("/" + TLAsyncInvocationInterceptorFactory.getTlInt())
                               .build();
    clientRequestContext.setUri(updatedUri);
}
 
Example 3
Source File: RoboZonkyFilter.java    From robozonky with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(final ClientRequestContext clientRequestContext) {
    requestHeaders.forEach((k, v) -> clientRequestContext.getHeaders()
        .putSingle(k, v));
    clientRequestContext.setUri(rebuild(clientRequestContext.getUri()));
    logger.trace("Request {} {}.", clientRequestContext.getMethod(), clientRequestContext.getUri());
}
 
Example 4
Source File: VespaClientBuilderFactory.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public void filter(ClientRequestContext requestContext) {
    requestContext.setUri(rewriteUri(requestContext.getUri()));
}