use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method invokeCustomerMethod.
private void invokeCustomerMethod(ClassResourceInfo cri, Customer customer, Server server) throws Exception {
OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(Customer.class.getMethod("test", new Class[] {}));
JAXRSInvoker invoker = new JAXRSInvoker();
Exchange exc = new ExchangeImpl();
exc.put(Endpoint.class, server.getEndpoint());
Message inMessage = new MessageImpl();
exc.setInMessage(inMessage);
exc.put(OperationResourceInfo.class, ori);
invoker.invoke(exc, Collections.emptyList(), customer);
}
use of org.apache.cxf.jaxrs.Customer 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
}
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class ProviderFactoryTest method testParameterHandlerProviderWithPriority.
@Test
public void testParameterHandlerProviderWithPriority() throws Exception {
ProviderFactory pf = ServerProviderFactory.getInstance();
ParamConverterProvider h = new CustomerParameterHandler();
ParamConverterProvider hp = new PriorityCustomerParameterHandler();
pf.registerUserProvider(h);
pf.registerUserProvider(hp);
ParamConverter<Customer> h2 = pf.createParameterHandler(Customer.class, Customer.class, null, new MessageImpl());
assertSame(h2, hp);
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testSingletonContextFields.
@SuppressWarnings("unchecked")
@Test
public void testSingletonContextFields() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
cri.setResourceProvider(new SingletonResourceProvider(c));
Message m = createMessage();
m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
ServletContext servletContextMock = EasyMock.createNiceMock(ServletContext.class);
m.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
HttpServletRequest httpRequest = EasyMock.createNiceMock(HttpServletRequest.class);
m.put(AbstractHTTPDestination.HTTP_REQUEST, httpRequest);
HttpServletResponse httpResponse = EasyMock.createMock(HttpServletResponse.class);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, httpResponse);
InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
InjectionUtils.injectContextFields(c, cri, m);
InjectionUtils.injectContextMethods(c, cri, m);
assertSame(ThreadLocalUriInfo.class, c.getUriInfo2().getClass());
assertSame(UriInfoImpl.class, ((ThreadLocalProxy<UriInfo>) c.getUriInfo2()).get().getClass());
assertSame(HttpHeadersImpl.class, ((ThreadLocalProxy<HttpHeaders>) c.getHeaders()).get().getClass());
assertSame(RequestImpl.class, ((ThreadLocalProxy<Request>) c.getRequest()).get().getClass());
assertSame(ResourceInfoImpl.class, ((ThreadLocalProxy<ResourceInfo>) c.getResourceInfo()).get().getClass());
assertSame(SecurityContextImpl.class, ((ThreadLocalProxy<SecurityContext>) c.getSecurityContext()).get().getClass());
assertSame(ProvidersImpl.class, ((ThreadLocalProxy<Providers>) c.getBodyWorkers()).get().getClass());
assertSame(servletContextMock, ((ThreadLocalProxy<ServletContext>) c.getThreadLocalServletContext()).get());
assertSame(servletContextMock, ((ThreadLocalProxy<ServletContext>) c.getServletContext()).get());
assertSame(servletContextMock, ((ThreadLocalProxy<ServletContext>) c.getSuperServletContext()).get());
HttpServletRequest currentReq = ((ThreadLocalProxy<HttpServletRequest>) c.getServletRequest()).get();
assertSame(httpRequest, ((HttpServletRequestFilter) currentReq).getRequest());
HttpServletResponseFilter filter = (HttpServletResponseFilter) ((ThreadLocalProxy<HttpServletResponse>) c.getServletResponse()).get();
assertSame(httpResponse, filter.getResponse());
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testParamAnnotationOnMethod.
@Test
public void testParamAnnotationOnMethod() 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("AHeader2", "theAHeader2");
m.put(Message.PROTOCOL_HEADERS, headers);
m.put(Message.QUERY_STRING, "a_value=aValue&query2=b");
JAXRSUtils.injectParameters(ori, c, m);
assertEquals("aValue", c.getQueryParam());
assertEquals("theAHeader2", c.getAHeader2());
}
Aggregations