Search in sources :

Example 6 with AbstractFeature

use of org.apache.cxf.feature.AbstractFeature in project cxf by apache.

the class LoadDistributorTest method createBean.

protected JAXRSClientFactoryBean createBean(String address, FailoverFeature feature) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(address);
    List<AbstractFeature> features = new ArrayList<>();
    features.add(feature);
    bean.setFeatures(features);
    return bean;
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature)

Example 7 with AbstractFeature

use of org.apache.cxf.feature.AbstractFeature in project fabric8 by jboss-fuse.

the class CxfRsFailOverClientServerTest method testClientServer.

@Test
public void testClientServer() throws Exception {
    assertNotNull(bus);
    // The bus is load the feature
    JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
    factory.setResourceClasses(CustomerService.class);
    factory.setAddress("http://localhost:9000/fail/server");
    factory.setBus(bus);
    factory.create();
    factory = new JAXRSServerFactoryBean();
    factory.setServiceClass(CustomerService.class);
    factory.setResourceClasses(CustomerService.class);
    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);
    }
    JAXRSClientFactoryBean clientFactory = new JAXRSClientFactoryBean();
    clientFactory.setServiceClass(CustomerServiceResources.class);
    // The address is not the actual address that the client will access
    clientFactory.setAddress("http://someotherplace");
    List<AbstractFeature> features = new ArrayList<>();
    // 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 = clientFactory.getOutInterceptors();
    outInterceptor.add(new TransportFailureInterceptor());
    clientFactory.setOutInterceptors(outInterceptor);
    CustomerServiceResources proxy = clientFactory.create(CustomerServiceResources.class);
    Customer response = proxy.getCustomer("123");
    assertEquals("Get a wrong customer name", "John", response.getName());
    response = proxy.getCustomer("123");
    assertEquals("Get a wrong customer name", "John", response.getName());
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) Message(org.apache.cxf.message.Message) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 8 with AbstractFeature

use of org.apache.cxf.feature.AbstractFeature in project fabric8 by jboss-fuse.

the class LoadBalanceClientServerTest 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/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>();
    features.add(feature);
    // we need to setup the feature on the clientfactory
    clientFactory.setFeatures(features);
    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);
    // Try to call the hello proxy which is created by Spring with setting feature on the bus
    response = helloProxy.sayHello();
    assertEquals("Get a wrong response", "Hello", response);
}
Also used : JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Test(org.junit.Test)

Example 9 with AbstractFeature

use of org.apache.cxf.feature.AbstractFeature in project cxf by apache.

the class JAXRSSoapBookTest method serverFaultInInterceptorTest.

private void serverFaultInInterceptorTest(String param) {
    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();
    WebClient.getConfig(proxy).getRequestContext().put("org.apache.cxf.transport.no_io_exceptions", false);
    try {
        // 321 is special case - causes error code of 525
        proxy.getBook(Long.valueOf(param));
        fail("Method should have thrown an exception");
    } catch (Exception e) {
        assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled());
        if ("322".equals(param)) {
            // In interceptors not called when checked exception thrown from server
            assertTrue("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
        } else {
            assertFalse("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled());
        }
        assertTrue("Client In Fault In Interceptor not 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)

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