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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations