use of org.apache.cxf.feature.AbstractFeature in project fabric8 by jboss-fuse.
the class CxfRsLoadBalanceClientServerTest method testClientServer.
@Test
public void testClientServer() throws Exception {
assertNotNull(bus);
assertNotNull(feature);
// Publish the services
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setResourceClasses(CustomerService.class);
factory.setAddress("http://localhost:9000/simple/server");
factory.setBus(bus);
factory.create();
// sleep a while to let the service be published
for (int i = 0; i < 100; i++) {
if (!feature.getLoadBalanceStrategy().getAlternateAddressList().isEmpty()) {
break;
}
Thread.sleep(100);
}
// create the JAXRS client
JAXRSClientFactoryBean clientFactory = new JAXRSClientFactoryBean();
clientFactory.setServiceClass(CustomerServiceResources.class);
clientFactory.setAddress("http://someotherplace");
List<AbstractFeature> features = new ArrayList<AbstractFeature>();
features.add(feature);
// we need to setup the feature on the clientfactory
clientFactory.setFeatures(features);
CustomerServiceResources proxy = clientFactory.create(CustomerServiceResources.class);
Customer response = proxy.getCustomer("123");
assertEquals("Get a wrong customer name", "John", response.getName());
}
use of org.apache.cxf.feature.AbstractFeature in project fabric8 by jboss-fuse.
the class FailOverClientServerTest method testClientServer.
@Test
public void testClientServer() throws Exception {
assertNotNull(bus);
// The bus is load the feature
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceBean(new HelloImpl());
factory.setAddress("http://localhost:9000/fail/server");
factory.setBus(bus);
factory.create();
factory = new JaxWsServerFactoryBean();
factory.setServiceBean(new HelloImpl());
factory.setAddress("http://localhost:9000/simple/server");
factory.setBus(bus);
factory.create();
// sleep a while to let the service be published
for (int i = 0; i < 100; i++) {
if (!feature.getLoadBalanceStrategy().getAlternateAddressList().isEmpty()) {
break;
}
Thread.sleep(100);
}
JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
clientFactory.setServiceClass(Hello.class);
// The address is not the actual address that the client will access
clientFactory.setAddress("http://someotherplace");
List<AbstractFeature> features = new ArrayList<AbstractFeature>();
// add the instance of FabricLoadBalancerFeature into features list
features.add(feature);
// we need to setup the feature on the clientfactory
clientFactory.setFeatures(features);
// set this interceptor to simulate the Transport level exception
List<Interceptor<? extends Message>> outInterceptor = new ArrayList<Interceptor<? extends Message>>();
outInterceptor.add(new TransportFailureInterceptor());
clientFactory.setOutInterceptors(outInterceptor);
Hello hello = clientFactory.create(Hello.class);
String response = hello.sayHello();
assertEquals("Get a wrong response", "Hello", response);
response = hello.sayHello();
assertEquals("Get a wrong response", "Hello", response);
}
use of org.apache.cxf.feature.AbstractFeature in project cxf by apache.
the class JAXRSSoapBookTest method testClientFaultOutInterceptor.
@Test
public void testClientFaultOutInterceptor() throws Exception {
// testing faults created by client out interceptor chain handled correctly
String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(baseAddress);
bean.setResourceClass(BookStoreJaxrsJaxws.class);
final boolean addBadOutInterceptor = true;
TestFeature testFeature = new TestFeature(addBadOutInterceptor);
List<AbstractFeature> features = new ArrayList<>();
features.add(testFeature);
bean.setFeatures(features);
BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws) bean.create();
try {
// 321 is special case - causes error code of 525
proxy.getBook(Long.valueOf("123"));
fail("Method should have thrown an exception");
} catch (Exception e) {
assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
assertFalse("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
assertTrue("Wrong exception caught", "fault from bad interceptor".equals(e.getCause().getMessage()));
assertTrue("Client In Fault In Interceptor was invoked", testFeature.faultInInterceptorCalled());
}
}
use of org.apache.cxf.feature.AbstractFeature in project cxf by apache.
the class JAXRSSoapBookTest method testAddFeatureToClient.
@Test
public void testAddFeatureToClient() throws Exception {
String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(baseAddress);
bean.setResourceClass(BookStoreJaxrsJaxws.class);
TestFeature testFeature = new TestFeature();
List<AbstractFeature> features = new ArrayList<>();
features.add(testFeature);
bean.setFeatures(features);
BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws) bean.create();
Book b = proxy.getBook(Long.valueOf("123"));
assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
assertTrue("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
assertEquals(123, b.getId());
assertEquals("CXF in Action", b.getName());
}
use of org.apache.cxf.feature.AbstractFeature in project cxf by apache.
the class SimpleBatchSTSClient method createClient.
protected void createClient() throws BusException, EndpointException {
if (client != null) {
return;
}
bus.getExtension(Configurer.class).configureBean(name, this);
if (wsdlLocation != null) {
WSDLServiceFactory factory = new WSDLServiceFactory(bus, wsdlLocation, serviceName);
SourceDataBinding dataBinding = new SourceDataBinding();
factory.setDataBinding(dataBinding);
Service service = factory.create();
service.setDataBinding(dataBinding);
EndpointInfo ei = service.getEndpointInfo(endpointName);
Endpoint endpoint = new EndpointImpl(bus, service, ei);
client = new ClientImpl(bus, endpoint);
} else {
Endpoint endpoint = STSUtils.createSTSEndpoint(bus, namespace, null, location, soapVersion, policy, endpointName);
client = new ClientImpl(bus, endpoint);
}
client.getInFaultInterceptors().addAll(inFault);
client.getInInterceptors().addAll(in);
client.getOutInterceptors().addAll(out);
client.getOutFaultInterceptors().addAll(outFault);
in = null;
out = null;
inFault = null;
outFault = null;
if (features != null) {
for (AbstractFeature f : features) {
f.initialize(client, bus);
}
}
}
Aggregations