use of org.apache.cxf.jaxrs.client.ClientConfiguration in project cxf by apache.
the class JAXRSAsyncClientTest method testPatchBookTimeout.
@Test
public void testPatchBookTimeout() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/patch";
WebClient wc = WebClient.create(address);
wc.type("application/xml");
ClientConfiguration clientConfig = WebClient.getConfig(wc);
clientConfig.getRequestContext().put("use.async.http.conduit", true);
HTTPClientPolicy clientPolicy = clientConfig.getHttpConduit().getClient();
clientPolicy.setReceiveTimeout(500);
clientPolicy.setConnectionTimeout(500);
try {
Book book = wc.invoke("PATCH", new Book("Timeout", 123L), Book.class);
fail("should throw an exception due to timeout, instead got " + book);
} catch (javax.ws.rs.ProcessingException e) {
// expected!!!
}
}
use of org.apache.cxf.jaxrs.client.ClientConfiguration in project cxf by apache.
the class HTraceTracingCustomHeadersTest method createWebClient.
protected WebClient createWebClient(final String url, final Object... providers) {
final WebClient client = WebClient.create("http://localhost:" + PORT + url, Arrays.asList(providers)).accept(MediaType.APPLICATION_JSON);
if (providers.length > 0) {
final ClientConfiguration config = WebClient.getConfig(client);
config.getRequestContext().put(TracerHeaders.HEADER_SPAN_ID, CUSTOM_HEADER_SPAN_ID);
}
return client;
}
use of org.apache.cxf.jaxrs.client.ClientConfiguration in project cxf by apache.
the class ClientImplTest method doesClientConfigHaveMyInterceptor.
private boolean doesClientConfigHaveMyInterceptor(WebClient webClient) {
ClientConfiguration clientConfigAfterPath = WebClient.getConfig(webClient);
boolean foundMyInterceptor = false;
for (Interceptor<?> i : clientConfigAfterPath.getOutInterceptors()) {
if (MY_INTERCEPTOR_NAME.equals(i.toString())) {
foundMyInterceptor = true;
break;
}
}
return foundMyInterceptor;
}
use of org.apache.cxf.jaxrs.client.ClientConfiguration in project cxf by apache.
the class ClientImplTest method testClientConfigCopiedOnPathCallWithTemplates.
/**
* This test checks that we do not lose track of registered interceptors
* on the original client implementation after we create a new impl with
* the path(...) method - particularly when the path passed in to the
* path(...) method contains a template.
*/
@Test
public void testClientConfigCopiedOnPathCallWithTemplates() {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target("http://localhost:8080/");
WebClient webClient = getWebClient(webTarget);
ClientConfiguration clientConfig = WebClient.getConfig(webClient);
clientConfig.setOutInterceptors(Arrays.asList(new MyInterceptor()));
assertTrue("Precondition failed - original WebTarget is missing expected interceptor", doesClientConfigHaveMyInterceptor(webClient));
WebTarget webTargetAfterPath = webTarget.path("/rest/{key}/").resolveTemplate("key", "myKey");
WebClient webClientAfterPath = getWebClient(webTargetAfterPath);
assertTrue("New WebTarget is missing expected interceptor specified on 'parent' WebTarget's client impl", doesClientConfigHaveMyInterceptor(webClientAfterPath));
}
use of org.apache.cxf.jaxrs.client.ClientConfiguration in project cxf by apache.
the class ClientImplTest method testTemplateInInitialTarget.
/**
* Similar to <code>testClientConfigCopiedOnPathCallWithTemplates</code>,
* this test uses a template, but in the initial call to target(). At this
* point, the WebTargetImpl's targetClient field will be null, so we need
* this test to ensure that there are no null pointers when creating and
* using a template on the first call to target().
*/
@Test
public void testTemplateInInitialTarget() {
String address = "http://localhost:8080/bookstore/{a}/simple";
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(address).resolveTemplate("a", "bookheaders");
webTarget.request("application/xml").header("a", "b");
WebClient webClient = getWebClient(webTarget);
ClientConfiguration clientConfig = WebClient.getConfig(webClient);
clientConfig.setOutInterceptors(Arrays.asList(new MyInterceptor()));
assertTrue("Precondition failed - original WebTarget is missing expected interceptor", doesClientConfigHaveMyInterceptor(webClient));
WebTarget webTargetAfterPath = webTarget.path("/rest/{key}/").resolveTemplate("key", "myKey");
WebClient webClientAfterPath = getWebClient(webTargetAfterPath);
assertTrue("New WebTarget is missing expected interceptor specified on 'parent' WebTarget's client impl", doesClientConfigHaveMyInterceptor(webClientAfterPath));
}
Aggregations