Search in sources :

Example 1 with AbstractFeature

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());
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature) Test(org.junit.Test)

Example 2 with AbstractFeature

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);
}
Also used : Message(org.apache.cxf.message.Message) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 3 with AbstractFeature

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());
    }
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 4 with AbstractFeature

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());
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature) Test(org.junit.Test)

Example 5 with AbstractFeature

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);
        }
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) AbstractFeature(org.apache.cxf.feature.AbstractFeature) Configurer(org.apache.cxf.configuration.Configurer) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding)

Aggregations

AbstractFeature (org.apache.cxf.feature.AbstractFeature)9 ArrayList (java.util.ArrayList)8 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)6 Test (org.junit.Test)6 BookStoreJaxrsJaxws (org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws)3 NotFoundException (javax.ws.rs.NotFoundException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)2 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)2 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)2 Message (org.apache.cxf.message.Message)2 Configurer (org.apache.cxf.configuration.Configurer)1 SourceDataBinding (org.apache.cxf.databinding.source.SourceDataBinding)1 ClientImpl (org.apache.cxf.endpoint.ClientImpl)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)1 Service (org.apache.cxf.service.Service)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 WSDLServiceFactory (org.apache.cxf.wsdl11.WSDLServiceFactory)1