Search in sources :

Example 16 with ClientConfiguration

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

the class SyncopeClient method getService.

/**
 * Creates an instance of the given service class, with configured content type and authentication.
 *
 * @param <T> any service class
 * @param serviceClass service class reference
 * @return service instance of the given reference class
 */
public <T> T getService(final Class<T> serviceClass) {
    synchronized (restClientFactory) {
        restClientFactory.setServiceClass(serviceClass);
        T serviceInstance = restClientFactory.create(serviceClass);
        Client client = WebClient.client(serviceInstance);
        client.type(mediaType).accept(mediaType);
        ClientConfiguration config = WebClient.getConfig(client);
        config.getRequestContext().put(HEADER_SPLIT_PROPERTY, true);
        config.getRequestContext().put(URLConnectionHTTPConduit.HTTPURL_CONNECTION_METHOD_REFLECTION, true);
        if (useCompression) {
            config.getInInterceptors().add(new GZIPInInterceptor());
            config.getOutInterceptors().add(new GZIPOutInterceptor());
        }
        return serviceInstance;
    }
}
Also used : GZIPOutInterceptor(org.apache.cxf.transport.common.gzip.GZIPOutInterceptor) GZIPInInterceptor(org.apache.cxf.transport.common.gzip.GZIPInInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) Client(org.apache.cxf.jaxrs.client.Client) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 17 with ClientConfiguration

use of org.apache.cxf.jaxrs.client.ClientConfiguration in project tesb-rt-se by Talend.

the class RESTClient method useOldRESTServiceWithNewClient.

/**
 * New REST client uses old REST service
 */
public void useOldRESTServiceWithNewClient() throws Exception {
    List<Object> providers = createJAXRSProviders();
    org.customer.service.CustomerService customerService = JAXRSClientFactory.createFromModel("http://localhost:" + port + "/examples/direct/rest", org.customer.service.CustomerService.class, "classpath:/model/CustomerService-jaxrs.xml", providers, null);
    // The outgoing new Customer data needs to be transformed for
    // the old service to understand it and the response from the old service
    // needs to be transformed for this new client to understand it.
    ClientConfiguration config = WebClient.getConfig(customerService);
    addTransformInterceptors(config.getInInterceptors(), config.getOutInterceptors(), true);
    System.out.println("Using old RESTful CustomerService with new client");
    customer.v2.Customer customer = createNewCustomer("Smith New to Old REST");
    customerService.updateCustomer(customer);
    customer = customerService.getCustomerByName("Smith New to Old REST");
    printNewCustomerDetails(customer);
}
Also used : ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 18 with ClientConfiguration

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

the class AbstractRestServiceInitializer method prepareClient.

protected WebClient prepareClient(String username, String password) {
    WebClient client = WebClient.create(ENDPOINT_ADDRESS, Collections.singletonList(getProvider()));
    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 : WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 19 with ClientConfiguration

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

the class TestSchemaRestService method prepareClient.

@Override
protected WebClient prepareClient(String username, String password) {
    WebClient client = WebClient.create(ENDPOINT_ADDRESS, Arrays.asList(jsonProvider, new PrimitiveTextProvider<>()));
    ClientConfiguration clientConfig = WebClient.getConfig(client);
    clientConfig.getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
    client.accept(MediaType.APPLICATION_JSON_TYPE);
    createAuthorizationHeader(client, username, password);
    return client;
}
Also used : PrimitiveTextProvider(org.apache.cxf.jaxrs.provider.PrimitiveTextProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 20 with ClientConfiguration

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

the class TestSecurityQuestionChallengeResponse method getUserAdministrator.

private Response getUserAdministrator(String authorizationHeader) {
    WebClient client = WebClient.create(ENDPOINT_ADDRESS, Arrays.asList(getProvider()));
    ClientConfiguration clientConfig = WebClient.getConfig(client);
    clientConfig.getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
    client.accept(getAcceptHeader());
    client.type(getContentType());
    client.authorization(authorizationHeader);
    client.path("/users/" + SystemObjectsType.USER_ADMINISTRATOR.value());
    Response response = client.get();
    return response;
}
Also used : Response(javax.ws.rs.core.Response) 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