Package org.apache.cxf.jaxrs

Examples of org.apache.cxf.jaxrs.JAXRSServerFactoryBean


        if (applicationClass != null) {
            createServerFromApplication(applicationClass, servletConfig);
            return;
        }
       
        JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
        bean.setBus(getBus());
       
        String address = servletConfig.getInitParameter(SERVICE_ADDRESS_PARAM);
        if (address == null) {
            address = "/";
        }
        bean.setAddress(address);
       
        bean.setStaticSubresourceResolution(getStaticSubResolutionValue(servletConfig));
       
        String modelRef = servletConfig.getInitParameter(USER_MODEL_PARAM);
        if (modelRef != null) {
            bean.setModelRef(modelRef.trim());
        }
       
        setSchemasLocations(bean, servletConfig);
        setAllInterceptors(bean, servletConfig);
       
        Map<Class, Map<String, String>> resourceClasses =
            getServiceClasses(servletConfig, modelRef != null);
        Map<Class, ResourceProvider> resourceProviders =
            getResourceProviders(servletConfig, resourceClasses);
       
        List<?> providers = getProviders(servletConfig);
               
        bean.setResourceClasses(new ArrayList<Class>(resourceClasses.keySet()));
        bean.setProviders(providers);
        for (Map.Entry<Class, ResourceProvider> entry : resourceProviders.entrySet()) {
            bean.setResourceProvider(entry.getKey(), entry.getValue());
        }
        setExtensions(bean, servletConfig);
               
        bean.create();
    }
View Full Code Here


        cName = getClassNameAndProperties(cName, props);
        Class<?> appClass = loadClass(cName, "Application");
        Application app = (Application)createSingletonInstance(appClass, props, servletConfig);
       
        String ignoreParam = servletConfig.getInitParameter(IGNORE_APP_PATH_PARAM);
        JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app,
                                            MessageUtils.isTrue(ignoreParam),
                                            getStaticSubResolutionValue(servletConfig));
        setAllInterceptors(bean, servletConfig);
        setExtensions(bean, servletConfig);
        setSchemasLocations(bean, servletConfig);
       
        bean.setBus(getBus());
        bean.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

   

public class MultipartServer extends AbstractBusTestServerBase {
    public static final String PORT = allocatePort(MultipartServer.class);
    protected void run() {
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setResourceClasses(MultipartStore.class);
        sf.setProperties(Collections.<String, Object>singletonMap(
                AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
                String.valueOf(1024 * 1024 * 10)));
        //default lifecycle is per-request, change it to singleton
        sf.setResourceProvider(MultipartStore.class,
                               new SingletonResourceProvider(new MultipartStore()));
        sf.setAddress("http://localhost:" + PORT + "/");

        sf.create();       
    }
View Full Code Here

    @Ignore
    public static class Server extends AbstractBusTestServerBase {       

        protected void run() {
            JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
            sf.setAddress("http://localhost:" + PORT + "/");
           
            UserResource ur = new UserResource();
            ur.setName(BookStoreNoAnnotations.class.getName());
            ur.setPath("/bookstoreNoAnnotations");
            UserOperation op = new UserOperation();
            op.setPath("/books/{id}");
            op.setName("getBook");
            op.setVerb("GET");
            op.setParameters(Collections.singletonList(new Parameter(ParameterType.PATH, "id")));
           
            UserOperation op2 = new UserOperation();
            op2.setPath("/books/{id}/chapter");
            op2.setName("getBookChapter");
            op2.setParameters(Collections.singletonList(new Parameter(ParameterType.PATH, "id")));
           
            List<UserOperation> ops = new ArrayList<UserOperation>();
            ops.add(op);
            ops.add(op2);
           
            ur.setOperations(ops);
           
            UserResource ur2 = new UserResource();
            ur2.setName(ChapterNoAnnotations.class.getName());
            UserOperation op3 = new UserOperation();
            op3.setPath("/");
            op3.setName("getItself");
            op3.setVerb("GET");
            ur2.setOperations(Collections.singletonList(op3));
           
            sf.setModelBeans(ur, ur2);
           
            String modelRef = "classpath:/org/apache/cxf/systest/jaxrs/resources/resources2.xml";
            sf.setModelRefWithServiceClass(modelRef, BookStoreNoAnnotationsInterface.class);
            sf.setServiceBean(new BookStoreNoAnnotationsImpl());
            sf.create();

        }
View Full Code Here

    @BeforeClass
    public static void beforeClass() throws Exception {
        // disable logging for server startup
        configureLogging("resources/logging_atompush_disabled.properties");

        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setResourceClasses(JAXRSLoggingAtomPushTest.Resource.class);
        sf.setAddress("http://localhost:" + PORT + "/");
        sf.setProviders(Arrays.asList(new AtomFeedProvider(), new AtomEntryProvider()));
        server = sf.create();
        server.start();
    }
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 p = new BinaryDataProvider();
        p.setProduceMediaTypes(Collections.singletonList("application/bar"));
        p.setEnableBuffering(true);
        providers.add(p);
        JAXBElementProvider jaxbProvider = new JAXBElementProvider();
        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());
        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

        createEndpoint(ADDRESS2);
        createEndpoint(ADDRESS3);
    }
   
    private void createEndpoint(String address) {
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setResourceClasses(BookStore.class);
        sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), false));
        sf.setAddress(address);
        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.