Search in sources :

Example 11 with ClientConfiguration

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!!!
    }
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ProcessingException(javax.ws.rs.ProcessingException) WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Example 12 with ClientConfiguration

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;
}
Also used : WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 13 with ClientConfiguration

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;
}
Also used : ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 14 with ClientConfiguration

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));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) WebClient(org.apache.cxf.jaxrs.client.WebClient) Client(javax.ws.rs.client.Client) WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Example 15 with ClientConfiguration

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));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) WebClient(org.apache.cxf.jaxrs.client.WebClient) Client(javax.ws.rs.client.Client) WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Aggregations

ClientConfiguration (org.apache.cxf.jaxrs.client.ClientConfiguration)21 WebClient (org.apache.cxf.jaxrs.client.WebClient)14 Test (org.junit.Test)6 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)3 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)3 Client (javax.ws.rs.client.Client)2 WebTarget (javax.ws.rs.client.WebTarget)2 ClientLifeCycleManagerImpl (org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl)2 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)2 Service (org.apache.cxf.service.Service)2 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)2 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProcessingException (javax.ws.rs.ProcessingException)1 Response (javax.ws.rs.core.Response)1 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)1 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)1