Search in sources :

Example 76 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean 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 77 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project alliance by codice.

the class MockNsili method startWebServer.

public void startWebServer(int port) {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(MockWebService.class);
    sf.setAddress("http://localhost:" + port + "/");
    sf.create();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Example 78 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project tomee by apache.

the class CXFNonSpringJaxrsServlet method createServerFromApplication.

protected void createServerFromApplication(String applicationNames, ServletConfig servletConfig) throws ServletException {
    boolean ignoreApplicationPath = isIgnoreApplicationPath(servletConfig);
    String[] classNames = applicationNames.split(getParameterSplitChar(servletConfig));
    if (classNames.length > 1 && ignoreApplicationPath) {
        throw new ServletException("\"" + IGNORE_APP_PATH_PARAM + "\" parameter must be set to false for multiple Applications be supported");
    }
    for (String cName : classNames) {
        ApplicationInfo providerApp = createApplicationInfo(cName, servletConfig);
        Application app = providerApp.getProvider();
        JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, ignoreApplicationPath, getStaticSubResolutionValue(servletConfig), isAppResourceLifecycleASingleton(app, servletConfig), getBus());
        String splitChar = getParameterSplitChar(servletConfig);
        setAllInterceptors(bean, servletConfig, splitChar);
        setInvoker(bean, servletConfig);
        setExtensions(bean, servletConfig);
        setDocLocation(bean, servletConfig);
        setSchemasLocations(bean, servletConfig);
        List<?> providers = getProviders(servletConfig, splitChar);
        bean.setProviders(providers);
        List<? extends Feature> features = getFeatures(servletConfig, splitChar);
        bean.getFeatures().addAll(features);
        bean.setBus(getBus());
        bean.setApplicationInfo(providerApp);
        bean.create();
    }
}
Also used : ServletException(javax.servlet.ServletException) ApplicationInfo(org.apache.cxf.jaxrs.model.ApplicationInfo) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Application(javax.ws.rs.core.Application)

Example 79 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project tomee by apache.

the class CXFNonSpringJaxrsServlet method createServerFromApplication.

protected void createServerFromApplication(ServletConfig servletConfig) throws ServletException {
    Application app = getApplication();
    JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, isIgnoreApplicationPath(servletConfig), getStaticSubResolutionValue(servletConfig), isAppResourceLifecycleASingleton(app, servletConfig), getBus());
    String splitChar = getParameterSplitChar(servletConfig);
    setAllInterceptors(bean, servletConfig, splitChar);
    setInvoker(bean, servletConfig);
    setExtensions(bean, servletConfig);
    setDocLocation(bean, servletConfig);
    setSchemasLocations(bean, servletConfig);
    List<?> providers = getProviders(servletConfig, splitChar);
    bean.setProviders(providers);
    List<? extends Feature> features = getFeatures(servletConfig, splitChar);
    bean.getFeatures().addAll(features);
    bean.setBus(getBus());
    bean.setApplication(getApplication());
    bean.create();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Application(javax.ws.rs.core.Application)

Example 80 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project tomee by apache.

the class CxfRsHttpListener method deploy.

private void deploy(final String contextRoot, final Class<?> clazz, final String address, final ResourceProvider rp, final Object serviceBean, final Application application, final Invoker invoker, final Collection<Object> additionalProviders, final ServiceConfiguration configuration, final WebBeansContext webBeansContext) {
    final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
    try {
        final JAXRSServerFactoryBean factory = newFactory(address, createServiceJmxName(clazz.getClassLoader()), createEndpointName(application));
        configureFactory(additionalProviders, configuration, factory, webBeansContext, application);
        factory.setResourceClasses(clazz);
        context = contextRoot;
        if (context == null) {
            context = "";
        }
        if (!context.startsWith("/")) {
            context = "/" + context;
        }
        if (rp != null) {
            factory.setResourceProvider(rp);
        }
        if (application != null) {
            factory.setApplication(application);
        }
        if (invoker != null) {
            factory.setInvoker(invoker);
        }
        if (serviceBean != null) {
            factory.setServiceBean(serviceBean);
        } else {
            factory.setServiceClass(clazz);
        }
        factory.setTransportId("http://cxf.apache.org/transports/http/sse");
        server = factory.create();
        destination = (HttpDestination) server.getDestination();
        fireServerCreated(oldLoader);
    } finally {
        if (oldLoader != null) {
            CxfUtil.clearBusLoader(oldLoader);
        }
    }
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Aggregations

JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)126 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)65 Bus (org.apache.cxf.Bus)21 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)18 ArrayList (java.util.ArrayList)15 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)14 Test (org.junit.Test)13 HashMap (java.util.HashMap)10 Server (org.apache.cxf.endpoint.Server)10 Application (javax.ws.rs.core.Application)9 Before (org.junit.Before)8 Map (java.util.Map)7 IOException (java.io.IOException)5 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)5 ResourceProvider (org.apache.cxf.jaxrs.lifecycle.ResourceProvider)5 Bean (org.springframework.context.annotation.Bean)5 InputStream (java.io.InputStream)4 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)4 Feature (org.apache.cxf.feature.Feature)4 JAXRSBindingFactory (org.apache.cxf.jaxrs.JAXRSBindingFactory)4