Search in sources :

Example 1 with CustomerParameterHandler

use of org.apache.cxf.jaxrs.CustomerParameterHandler 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) CustomerParameterHandler(org.apache.cxf.jaxrs.CustomerParameterHandler) Test(org.junit.Test)

Example 2 with CustomerParameterHandler

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

the class JAXRSUtilsTest method testCustomerParameter.

@Test
public void testCustomerParameter() throws Exception {
    Message messageImpl = createMessage();
    ServerProviderFactory.getInstance(messageImpl).registerUserProvider(new CustomerParameterHandler());
    Class<?>[] argType = { Customer.class, Customer[].class, Customer2.class };
    Method m = Customer.class.getMethod("testCustomerParam", argType);
    messageImpl.put(Message.QUERY_STRING, "p1=Fred&p2=Barry&p3=Jack&p4=John");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
    assertEquals(3, params.size());
    Customer c = (Customer) params.get(0);
    assertEquals("Fred", c.getName());
    Customer c2 = ((Customer[]) params.get(1))[0];
    assertEquals("Barry", c2.getName());
    Customer2 c3 = (Customer2) params.get(2);
    assertEquals("Jack", c3.getName());
    try {
        messageImpl.put(Message.QUERY_STRING, "p3=noName");
        JAXRSUtils.processParameters(new OperationResourceInfo(m, null), null, messageImpl);
        fail("Customer2 constructor does not accept names starting with lower-case chars");
    } catch (Exception ex) {
    // expected
    }
}
Also used : Message(org.apache.cxf.message.Message) Customer2(org.apache.cxf.jaxrs.Customer2) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) WebApplicationException(javax.ws.rs.WebApplicationException) CustomerParameterHandler(org.apache.cxf.jaxrs.CustomerParameterHandler) Test(org.junit.Test)

Aggregations

Customer (org.apache.cxf.jaxrs.Customer)2 CustomerParameterHandler (org.apache.cxf.jaxrs.CustomerParameterHandler)2 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ParamConverterProvider (javax.ws.rs.ext.ParamConverterProvider)1 Customer2 (org.apache.cxf.jaxrs.Customer2)1 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)1 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)1 Message (org.apache.cxf.message.Message)1 MessageImpl (org.apache.cxf.message.MessageImpl)1