Search in sources :

Example 6 with Customer

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

the class ProviderFactoryTest method testParameterHandlerProvider.

@Test
public void testParameterHandlerProvider() throws Exception {
    ProviderFactory pf = ServerProviderFactory.getInstance();
    ParamConverterProvider h = new CustomerParameterHandler();
    pf.registerUserProvider(h);
    ParamConverter<Customer> h2 = pf.createParameterHandler(Customer.class, Customer.class, null, new MessageImpl());
    assertSame(h2, h);
}
Also used : Customer(org.apache.cxf.jaxrs.Customer) ParamConverterProvider(javax.ws.rs.ext.ParamConverterProvider) MessageImpl(org.apache.cxf.message.MessageImpl) PriorityCustomerParameterHandler(org.apache.cxf.jaxrs.PriorityCustomerParameterHandler) CustomerParameterHandler(org.apache.cxf.jaxrs.CustomerParameterHandler) Test(org.junit.Test)

Example 7 with Customer

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

the class JAXRSUtilsTest method testPerRequestContextFields.

@Test
public void testPerRequestContextFields() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("postConstruct", new Class[] {}), cri);
    Customer c = new Customer();
    Message m = createMessage();
    m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
    HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
    m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
    InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
    assertSame(UriInfoImpl.class, c.getUriInfo2().getClass());
    assertSame(HttpHeadersImpl.class, c.getHeaders().getClass());
    assertSame(RequestImpl.class, c.getRequest().getClass());
    assertSame(SecurityContextImpl.class, c.getSecurityContext().getClass());
    assertSame(ProvidersImpl.class, c.getBodyWorkers().getClass());
}
Also used : Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) HttpServletResponse(javax.servlet.http.HttpServletResponse) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) List(java.util.List) ArrayList(java.util.ArrayList) PerRequestResourceProvider(org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider) Test(org.junit.Test)

Example 8 with Customer

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

the class JAXRSUtilsTest method testDefaultValueOnField.

@Test
public void testDefaultValueOnField() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    Customer c = new Customer();
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
    Message m = createMessage();
    m.put(Message.QUERY_STRING, "");
    JAXRSUtils.injectParameters(ori, c, m);
    assertEquals("bQuery", c.getB());
}
Also used : Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Test(org.junit.Test)

Example 9 with Customer

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

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

the class JAXRSUtilsTest method testParamAnnotationOnField.

@Test
public void testParamAnnotationOnField() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    Customer c = new Customer();
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
    Message m = createMessage();
    MultivaluedMap<String, String> headers = new MetadataMap<>();
    headers.add("AHeader", "theAHeader");
    m.put(Message.PROTOCOL_HEADERS, headers);
    m.put(Message.QUERY_STRING, "b=bValue");
    JAXRSUtils.injectParameters(ori, c, m);
    assertEquals("bValue", c.getB());
    assertEquals("theAHeader", c.getAHeader());
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Test(org.junit.Test)

Aggregations

Customer (org.apache.cxf.jaxrs.Customer)18 Test (org.junit.Test)17 Message (org.apache.cxf.message.Message)13 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)11 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 ThreadLocalProxy (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy)5 CustomerParameterHandler (org.apache.cxf.jaxrs.CustomerParameterHandler)4 MessageImpl (org.apache.cxf.message.MessageImpl)4 ServletContext (javax.servlet.ServletContext)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ParamConverterProvider (javax.ws.rs.ext.ParamConverterProvider)3 Server (org.apache.cxf.endpoint.Server)3 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)3 PriorityCustomerParameterHandler (org.apache.cxf.jaxrs.PriorityCustomerParameterHandler)3 HttpServletResponseFilter (org.apache.cxf.jaxrs.impl.HttpServletResponseFilter)3 ThreadLocalHttpServletRequest (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest)3 PerRequestResourceProvider (org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider)3 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)3 ArrayList (java.util.ArrayList)2