Search in sources :

Example 1 with CustomerApplication

use of org.apache.cxf.jaxrs.CustomerApplication in project cxf by apache.

the class JAXRSUtilsTest method testInjectApplicationInPerRequestResource.

@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(createMessage());
    assertNull(customer.getApplication1());
    assertNull(customer.getApplication2());
    invokeCustomerMethod(cri, customer, server);
    assertSame(app, customer.getApplication1());
    assertSame(app, customer.getApplication2());
    assertTrue(proxy.get() instanceof UriInfo);
}
Also used : ThreadLocalProxy(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy) Server(org.apache.cxf.endpoint.Server) CustomerApplication(org.apache.cxf.jaxrs.CustomerApplication) Customer(org.apache.cxf.jaxrs.Customer) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) UriInfo(javax.ws.rs.core.UriInfo) ThreadLocalUriInfo(org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo) Test(org.junit.Test)

Example 2 with CustomerApplication

use of org.apache.cxf.jaxrs.CustomerApplication in project cxf by apache.

the class JAXRSUtilsTest method testInjectApplicationInSingleton.

@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);
}
Also used : ThreadLocalProxy(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy) Server(org.apache.cxf.endpoint.Server) CustomerApplication(org.apache.cxf.jaxrs.CustomerApplication) Customer(org.apache.cxf.jaxrs.Customer) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) UriInfo(javax.ws.rs.core.UriInfo) ThreadLocalUriInfo(org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo) Test(org.junit.Test)

Aggregations

UriInfo (javax.ws.rs.core.UriInfo)2 Server (org.apache.cxf.endpoint.Server)2 Customer (org.apache.cxf.jaxrs.Customer)2 CustomerApplication (org.apache.cxf.jaxrs.CustomerApplication)2 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)2 ThreadLocalProxy (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy)2 ThreadLocalUriInfo (org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo)2 Test (org.junit.Test)2 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)1