Search in sources :

Example 1 with ClientConfiguration

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

the class RESTClient method useNewRESTServiceWithOldClient.

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

Example 2 with ClientConfiguration

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

the class RESTClient method useOldRESTServiceWithNewClientAndXPath.

/**
 * New REST client uses old REST service
 */
public void useOldRESTServiceWithNewClientAndXPath() throws Exception {
    List<Object> providers = createJAXRSProviders();
    String address = "http://localhost:" + port + "/examples/direct/rest/customerservice";
    WebClient client = WebClient.create(address, providers);
    // 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(client);
    addTransformInterceptors(config.getInInterceptors(), config.getOutInterceptors(), true);
    System.out.println("Consuming old RESTful CustomerService with new client and XPath");
    customer.v2.Customer customer = createNewCustomer("Smith New to Old REST, XPath");
    client.path("customer");
    client.type("application/xml");
    client.put(customer);
    XMLSource source = client.query("name", "Smith New to Old REST, XPath").get(XMLSource.class);
    customer.v2.Customer xmlCustomer = source.getNode("/ns:customer", Collections.singletonMap("ns", "http://customer/v2"), customer.v2.Customer.class);
    printNewCustomerDetails(xmlCustomer);
}
Also used : WebClient(org.apache.cxf.jaxrs.client.WebClient) XMLSource(org.apache.cxf.jaxrs.ext.xml.XMLSource) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Example 3 with ClientConfiguration

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

the class LocatorFeatureTest method initializeClientConfiguration.

@Test
public void initializeClientConfiguration() throws EndpointException {
    LocatorClientEnabler enabler = new LocatorClientEnabler();
    enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
    enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
    ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
    expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
    replayAll();
    EndpointInfo ei = new EndpointInfo();
    Service service = new org.apache.cxf.service.ServiceImpl();
    Endpoint endpoint = new EndpointImpl(busMock, service, ei);
    endpoint.put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
    ClientConfiguration client = new ClientConfiguration();
    LocatorTargetSelector selector = new LocatorTargetSelector();
    selector.setEndpoint(endpoint);
    client.setConduitSelector(selector);
    LocatorFeatureImpl lf = new LocatorFeatureImpl();
    lf.setLocatorRegistrar(locatorRegistrarMock);
    lf.setClientEnabler(enabler);
    lf.initialize((ConduitSelectorHolder) client, busMock);
    Assert.assertTrue(((LocatorTargetSelector) client.getConduitSelector()).getStrategy() instanceof RandomSelectionStrategy);
}
Also used : ClientLifeCycleManagerImpl(org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl) Service(org.apache.cxf.service.Service) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Example 4 with ClientConfiguration

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

the class LocatorFeatureTest method initializeInterceptorProvider.

@Test
public void initializeInterceptorProvider() throws EndpointException {
    LocatorClientEnabler enabler = new LocatorClientEnabler();
    enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
    enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
    ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
    expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
    replayAll();
    EndpointInfo ei = new EndpointInfo();
    Service service = new org.apache.cxf.service.ServiceImpl();
    Endpoint endpoint = new EndpointImpl(busMock, service, ei);
    endpoint.put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
    ClientConfiguration client = new ClientConfiguration();
    LocatorTargetSelector selector = new LocatorTargetSelector();
    selector.setEndpoint(endpoint);
    client.setConduitSelector(selector);
    LocatorFeatureImpl lf = new LocatorFeatureImpl();
    lf.setLocatorRegistrar(locatorRegistrarMock);
    lf.setClientEnabler(enabler);
    lf.initialize((InterceptorProvider) client, busMock);
    Assert.assertTrue(((LocatorTargetSelector) client.getConduitSelector()).getStrategy() instanceof RandomSelectionStrategy);
}
Also used : ClientLifeCycleManagerImpl(org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl) Service(org.apache.cxf.service.Service) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Example 5 with ClientConfiguration

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

the class AmbariClientBuilder method build.

/**
 * Build a client proxy, for a specific proxy type.
 *
 * @param proxyType proxy type class
 * @return client proxy stub
 */
protected <T> T build(Class<T> proxyType) {
    String address = generateAddress();
    T rootResource;
    // We want to ensure that the shared bean isn't set concurrently in multiple callers
    synchronized (AmbariClientBuilder.class) {
        JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType));
        bean.setAddress(address);
        if (username != null) {
            bean.setUsername(username);
            bean.setPassword(password);
        }
        if (enableLogging) {
            bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature()));
        }
        rootResource = bean.create(proxyType);
    }
    boolean isTlsEnabled = address.startsWith("https://");
    ClientConfiguration config = WebClient.getConfig(rootResource);
    HTTPConduit conduit = (HTTPConduit) config.getConduit();
    if (isTlsEnabled) {
        TLSClientParameters tlsParams = new TLSClientParameters();
        if (!validateCerts) {
            tlsParams.setTrustManagers(new TrustManager[] { new AcceptAllTrustManager() });
        } else if (trustManagers != null) {
            tlsParams.setTrustManagers(trustManagers);
        }
        tlsParams.setDisableCNCheck(!validateCn);
        conduit.setTlsClientParameters(tlsParams);
    }
    HTTPClientPolicy policy = conduit.getClient();
    policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
    policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
    return rootResource;
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) LoggingFeature(org.apache.cxf.feature.LoggingFeature) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration)

Aggregations

ClientConfiguration (org.apache.cxf.jaxrs.client.ClientConfiguration)24 WebClient (org.apache.cxf.jaxrs.client.WebClient)15 Test (org.junit.Test)7 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)5 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)5 ProcessingException (javax.ws.rs.ProcessingException)2 Client (javax.ws.rs.client.Client)2 WebTarget (javax.ws.rs.client.WebTarget)2 ClientLifeCycleManagerImpl (org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl)2 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)2 LoggingFeature (org.apache.cxf.feature.LoggingFeature)2 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)2 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)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