Search in sources :

Example 6 with ClientConfiguration

use of org.apache.cxf.jaxrs.client.ClientConfiguration in project components by Talend.

the class AmbariClientBuilder method closeClient.

/**
 * Closes the transport level conduit in the client. Reopening a new connection, requires creating a new client
 * object using the build() method in this builder.
 *
 * @param root The resource returned by the build() method of this builder class
 */
public static void closeClient(ApiRootResource root) {
    ClientConfiguration config = WebClient.getConfig(root);
    HTTPConduit conduit = config.getHttpConduit();
    if (conduit == null) {
        throw new IllegalArgumentException("Client is not using the HTTP transport");
    }
    conduit.close();
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 7 with ClientConfiguration

use of org.apache.cxf.jaxrs.client.ClientConfiguration in project pinpoint by naver.

the class CxfClientIT method test.

@Test
public void test() throws Exception {
    String address = getADDRESS();
    String json = "{\"id\" : 12345, \"name\" : \"victor\"}";
    WebClient client = WebClient.create(address, true);
    ClientConfiguration configuration = WebClient.getConfig(client);
    // add logging interceptor
    configuration.getInInterceptors().add(new LoggingInInterceptor());
    configuration.getOutInterceptors().add(new LoggingOutInterceptor());
    client.path("/test1").accept("application/json").type("application/json; charset=UTF-8").post(json).close();
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.ignoreServiceType("JDK_HTTPURLCONNECTOR");
    verifier.verifyTrace(event("CXF_MESSAGE_SENDER", MessageSenderInterceptor.class.getDeclaredMethod("handleMessage", Message.class)));
    verifier.verifyTrace(event("CXF_LOGGING_OUT", LoggingOutInterceptor.class.getDeclaredMethod("formatLoggingMessage", LoggingMessage.class), annotation("cxf.address", address + "/test1"), annotation("cxf.http.method", "POST"), annotation("cxf.content.type", "application/json; charset=UTF-8"), annotation("cxf.headers", "{Accept=[application/json], Content-Type=[application/json; charset=UTF-8]}"), annotation("cxf.payload", "{\"id\" : 12345, \"name\" : \"victor\"}")));
    // verifier.verifyTrace(event("CXF_LOGGING_IN", LoggingInInterceptor.class.getDeclaredMethod("formatLoggingMessage", LoggingMessage.class),
    // annotation("cxf.response.code", "200"),
    // annotation("cxf.encoding", "ISO-8859-1"),
    // annotation("cxf.content.type", "text/html"),
    // annotation("cxf.headers", "{connection=[keep-alive], Content-Length=[2], content-type=[text/html], Date=[" + new Date() + "]}"),
    // annotation("cxf.payload", "{}")
    // ));
    verifier.verifyTraceCount(1);
    client.close();
}
Also used : LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Example 8 with ClientConfiguration

use of org.apache.cxf.jaxrs.client.ClientConfiguration in project ddf by codice.

the class SecureCxfClientFactoryImpl method getNewClient.

private T getNewClient() {
    T clientImpl = interfaceClass.equals(WebClient.class) ? (T) clientFactory.create() : JAXRSClientFactory.fromClient(clientFactory.create(), interfaceClass);
    ClientConfiguration clientConfig = WebClient.getConfig(clientImpl);
    clientConfig.getRequestContext().put(Message.MAINTAIN_SESSION, Boolean.TRUE);
    configureConduit(clientConfig);
    configureTimeouts(clientConfig, connectionTimeout, receiveTimeout);
    return clientImpl;
}
Also used : WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 9 with ClientConfiguration

use of org.apache.cxf.jaxrs.client.ClientConfiguration in project midpoint by Evolveum.

the class RestServiceInitializer method prepareClient.

protected WebClient prepareClient(String username, String password) {
    List providers = new ArrayList<>();
    providers.add(getProvider());
    // ,
    WebClient client = WebClient.create(ENDPOINT_ADDRESS, providers);
    // provider);
    ClientConfiguration clientConfig = WebClient.getConfig(client);
    clientConfig.getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
    client.accept(getAcceptHeader());
    client.type(getContentType());
    createAuthorizationHeader(client, username, password);
    return client;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 10 with ClientConfiguration

use of org.apache.cxf.jaxrs.client.ClientConfiguration in project ddf by codice.

the class SecureCxfClientFactory method getNewClient.

private T getNewClient() {
    T clientImpl = interfaceClass.equals(WebClient.class) ? (T) clientFactory.create() : JAXRSClientFactory.fromClient(clientFactory.create(), interfaceClass);
    ClientConfiguration clientConfig = WebClient.getConfig(clientImpl);
    clientConfig.getRequestContext().put(Message.MAINTAIN_SESSION, Boolean.TRUE);
    configureConduit(clientConfig);
    configureTimeouts(clientConfig, connectionTimeout, receiveTimeout);
    return clientImpl;
}
Also used : WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

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