Package org.apache.cxf.jaxrs

Examples of org.apache.cxf.jaxrs.JAXRSServerFactoryBean


    @Ignore
    public static class Server extends AbstractBusTestServerBase {       

        protected void run() {
            JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
            sf.setResourceClasses(BookStore.class);
            sf.setResourceProvider(BookStore.class,
                                   new SingletonResourceProvider(new BookStore()));
            JAXBElementProvider p1 = new JAXBElementProvider();
            p1.setEnableBuffering(true);
            p1.setEnableStreaming(true);
           
            JAXBElementProvider p2 = new CustomJaxbProvider();
            p2.setProduceMediaTypes(Collections.singletonList("text/xml"));
           
            List<Object> providers = new ArrayList<Object>();
            providers.add(p1);
            providers.add(p2);
            sf.setProviders(providers);
            sf.setAddress("http://localhost:" + PORT + "/");
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put("org.apache.cxf.serviceloader-context", "true");
            sf.setProperties(properties);
            sf.create();

        }
View Full Code Here


            public String get() {
                return "customerContext";
            }
           
        };
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        Customer customer = new Customer();
        sf.setServiceBeanObjects(customer);
        sf.setProvider(new ContextProvider<CustomerContext>() {
            public CustomerContext createContext(Message message) {
                // TODO Auto-generated method stub
                return contextImpl;
            }
        });
        sf.setStart(false);
        Server s = sf.create()
        assertTrue(customer.getCustomerContext() instanceof ThreadLocalProxy<?>);
        invokeCustomerMethod(sf.getServiceFactory().getClassResourceInfo().get(0),
                             customer, s);
        CustomerContext context = customer.getCustomerContext();
        assertEquals("customerContext", context.get());
    }
View Full Code Here

    }
   
    @Test
    public void testInjectApplicationInSingleton() throws Exception {
        CustomerApplication app = new CustomerApplication();
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        Customer customer = new Customer();
        sf.setServiceBeanObjects(customer);
        sf.setApplication(app);
        sf.setStart(false);
        Server server = sf.create()
        assertSame(app, customer.getApplication1());
        assertSame(app, customer.getApplication2());
        @SuppressWarnings("unchecked")
        ThreadLocalProxy<UriInfo> proxy = (ThreadLocalProxy<UriInfo>)app.getUriInfo();
        assertNotNull(proxy);
        invokeCustomerMethod(sf.getServiceFactory().getClassResourceInfo().get(0),
                             customer, server);
        assertSame(app, customer.getApplication2());
        assertTrue(proxy.get() instanceof UriInfo);
    }
View Full Code Here

    }
   
    @Test
    public void testInjectApplicationInPerRequestResource() throws Exception {
        CustomerApplication app = new CustomerApplication();
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setServiceClass(Customer.class);
        sf.setApplication(app);
        sf.setStart(false);
        Server server = sf.create()
       
        @SuppressWarnings("unchecked")
        ThreadLocalProxy<UriInfo> proxy = (ThreadLocalProxy<UriInfo>)app.getUriInfo();
        assertNotNull(proxy);
       
        ClassResourceInfo cri = sf.getServiceFactory().getClassResourceInfo().get(0);
       
        Customer customer = (Customer)cri.getResourceProvider().getInstance(
             new MessageImpl());
       
        assertNull(customer.getApplication1());
View Full Code Here

                resourceClasses.add(o.getClass());
                map.put(o.getClass(), new SingletonResourceProvider(o));
            }
        }
       
        JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
        String address = "/";
        if (!ignoreAppPath) {
            ApplicationPath appPath = app.getClass().getAnnotation(ApplicationPath.class);
            if (appPath != null) {
                address = appPath.value().length() == 0 ? "/" : appPath.value();
            }
        }
        bean.setAddress(address);
        bean.setStaticSubresourceResolution(staticSubresourceResolution);
        bean.setResourceClasses(resourceClasses);
        bean.setProviders(providers);
        for (Map.Entry<Class<?>, ResourceProvider> entry : map.entrySet()) {
            bean.setResourceProvider(entry.getKey(), entry.getValue());
        }
        bean.setApplication(app);
       
        return bean;
    }
View Full Code Here

   *
   * @see junit.framework.TestCase#setUp()
   */
  @Override
  protected void setUp() throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(TikaResource.class);
    sf.setResourceProvider(TikaResource.class,
        new SingletonResourceProvider(new TikaResource()));
    sf.setAddress(endPoint + "/");
    BindingFactoryManager manager = sf.getBus().getExtension(
        BindingFactoryManager.class);
    JAXRSBindingFactory factory = new JAXRSBindingFactory();
    factory.setBus(sf.getBus());
    manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID,
        factory);
    server = sf.create();
  }
View Full Code Here

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("tikaserver", options);
        System.exit(-1);
      }

      JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
      sf.setResourceClasses(MetadataResource.class, TikaResource.class, UnpackerResource.class, TikaVersion.class);

      List providers = new ArrayList();
      providers.add(new TarWriter());
      providers.add(new ZipWriter());
      providers.add(new TikaExceptionMapper());
      providers.add(new SingletonResourceProvider(new MetadataResource()));
      providers.add(new SingletonResourceProvider(new TikaResource()));
      providers.add(new SingletonResourceProvider(new UnpackerResource()));
      providers.add(new SingletonResourceProvider(new TikaVersion()));
      sf.setProviders(providers);
      sf.setAddress("http://localhost:" + TikaServerCli.DEFAULT_PORT + "/");
      BindingFactoryManager manager = sf.getBus().getExtension(
        BindingFactoryManager.class);
      JAXRSBindingFactory factory = new JAXRSBindingFactory();
      factory.setBus(sf.getBus());
      manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID,
        factory);
      Server server = sf.create();
      logger.info("Started");
    } catch (Exception ex) {
      logger.fatal("Can't start", ex);
      System.exit(-1);
    }
View Full Code Here

    @Ignore
    public static class Server extends AbstractBusTestServerBase {       

        protected void run() {
            JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
            sf.setResourceClasses(BookStore.class);
            sf.setResourceProvider(BookStore.class,
                                   new SingletonResourceProvider(new BookStore()));
            JAXBElementProvider<?> p1 = new JAXBElementProvider<Object>();
            p1.setEnableBuffering(true);
            p1.setEnableStreaming(true);
           
            JAXBElementProvider<?> p2 = new CustomJaxbProvider();
            p2.setProduceMediaTypes(Collections.singletonList("text/xml"));
           
            List<Object> providers = new ArrayList<Object>();
            providers.add(p1);
            providers.add(p2);
            sf.setProviders(providers);
            sf.setAddress("http://localhost:" + PORT + "/");
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put("org.apache.cxf.serviceloader-context", "true");
            sf.setProperties(properties);
            sf.create();

        }
View Full Code Here

                resourceClasses.add(o.getClass());
                map.put(o.getClass(), new SingletonResourceProvider(o));
            }
        }
       
        JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
        String address = "/";
        if (!ignoreAppPath) {
            ApplicationPath appPath = app.getClass().getAnnotation(ApplicationPath.class);
            if (appPath != null) {
                address = appPath.value().length() == 0 ? "/" : appPath.value();
            }
        }
        bean.setAddress(address);
        bean.setStaticSubresourceResolution(staticSubresourceResolution);
        bean.setResourceClasses(resourceClasses);
        bean.setProviders(providers);
        for (Map.Entry<Class<?>, ResourceProvider> entry : map.entrySet()) {
            bean.setResourceProvider(entry.getKey(), entry.getValue());
        }
        bean.setApplication(app);
       
        return bean;
    }
View Full Code Here

   
public class BookServer extends AbstractBusTestServerBase {
    public static final String PORT = allocatePort(BookServer.class);

    protected void run() {
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setResourceClasses(BookStore.class, SimpleBookStore.class, BookStorePerRequest.class);
       
        List<Object> providers = new ArrayList<Object>();
       
        //default lifecycle is per-request, change it to singleton
        BinaryDataProvider<Object> p = new BinaryDataProvider<Object>();
        p.setProduceMediaTypes(Collections.singletonList("application/bar"));
        p.setEnableBuffering(true);
        providers.add(p);
        JAXBElementProvider<?> jaxbProvider = new JAXBElementProvider<Object>();
        Map<String, String> jaxbElementClassMap = new HashMap<String, String>();
        jaxbElementClassMap.put(BookNoXmlRootElement.class.getName(), "BookNoXmlRootElement");
        jaxbProvider.setJaxbElementClassMap(jaxbElementClassMap);
        providers.add(jaxbProvider);
        providers.add(new FormatResponseHandler());
        providers.add(new GenericHandlerWriter());
        providers.add(new FaultyRequestHandler());
        providers.add(new SearchContextProvider());
        sf.setProviders(providers);
        List<Interceptor<? extends Message>> outInts = new ArrayList<Interceptor<? extends Message>>();
        outInts.add(new CustomOutInterceptor());
        sf.setOutInterceptors(outInts);
        List<Interceptor<? extends Message>> outFaultInts = new ArrayList<Interceptor<? extends Message>>();
        outFaultInts.add(new CustomOutFaultInterceptor());
        sf.setOutFaultInterceptors(outFaultInts);
        sf.setResourceProvider(BookStore.class,
                               new SingletonResourceProvider(new BookStore(), true));
        sf.setAddress("http://localhost:" + PORT + "/");

        sf.create();       
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.JAXRSServerFactoryBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.