Search in sources :

Example 1 with CustomerContext

use of org.apache.cxf.jaxrs.Customer.CustomerContext in project cxf by apache.

the class JAXRSUtilsTest method testInjectCustomContext.

@Test
public void testInjectCustomContext() throws Exception {
    final CustomerContext contextImpl = new CustomerContext() {

        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) {
            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());
}
Also used : Message(org.apache.cxf.message.Message) Server(org.apache.cxf.endpoint.Server) Customer(org.apache.cxf.jaxrs.Customer) CustomerContext(org.apache.cxf.jaxrs.Customer.CustomerContext) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Test(org.junit.Test)

Aggregations

Server (org.apache.cxf.endpoint.Server)1 Customer (org.apache.cxf.jaxrs.Customer)1 CustomerContext (org.apache.cxf.jaxrs.Customer.CustomerContext)1 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)1 Message (org.apache.cxf.message.Message)1 Test (org.junit.Test)1