use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSInvoker method getResourceProvider.
private ResourceProvider getResourceProvider(Exchange exchange) {
Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER);
if (provider == null) {
OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
ClassResourceInfo cri = ori.getClassResourceInfo();
return cri.getResourceProvider();
}
return (ResourceProvider) provider;
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo 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());
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testQueryParamAsListWithDefaultValue.
@SuppressWarnings("unchecked")
@Test
public void testQueryParamAsListWithDefaultValue() throws Exception {
Class<?>[] argType = { List.class, List.class, List.class, Integer[].class, List.class, List.class, List.class, List.class, List.class };
Method m = Customer.class.getMethod("testQueryAsList", argType);
Message messageImpl = createMessage();
ProviderFactory.getInstance(messageImpl).registerUserProvider(new MyTypeParamConverterProvider());
messageImpl.put(Message.QUERY_STRING, "query2=query2Value&query2=query2Value2&query3=1&query3=2&query4=");
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(9, params.size());
List<String> queryList = (List<String>) params.get(0);
assertNotNull(queryList);
assertEquals(1, queryList.size());
assertEquals("default", queryList.get(0));
List<String> queryList2 = (List<String>) params.get(1);
assertNotNull(queryList2);
assertEquals(2, queryList2.size());
assertEquals("query2Value", queryList2.get(0));
assertEquals("query2Value2", queryList2.get(1));
List<Integer> queryList3 = (List<Integer>) params.get(2);
assertNotNull(queryList3);
assertEquals(2, queryList3.size());
assertEquals(Integer.valueOf(1), queryList3.get(0));
assertEquals(Integer.valueOf(2), queryList3.get(1));
Integer[] queryList3Array = (Integer[]) params.get(3);
assertNotNull(queryList3Array);
assertEquals(2, queryList3Array.length);
assertEquals(Integer.valueOf(1), queryList3Array[0]);
assertEquals(Integer.valueOf(2), queryList3Array[1]);
List<String> queryList4 = (List<String>) params.get(4);
assertNotNull(queryList4);
assertEquals(1, queryList4.size());
assertEquals("", queryList4.get(0));
List<String> queryList5 = (List<String>) params.get(5);
assertNotNull(queryList5);
assertEquals(0, queryList5.size());
List<MyType<Integer>> queryList6 = (List<MyType<Integer>>) params.get(6);
assertNotNull(queryList6);
assertEquals(2, queryList6.size());
assertEquals(Integer.valueOf(1), queryList6.get(0).get());
assertEquals(Integer.valueOf(2), queryList6.get(1).get());
List<Long> queryList7 = (List<Long>) params.get(7);
assertNotNull(queryList7);
assertEquals(2, queryList7.size());
assertEquals(1L, queryList7.get(0).longValue());
assertEquals(2L, queryList7.get(1).longValue());
List<Double> queryList8 = (List<Double>) params.get(8);
assertNotNull(queryList8);
assertEquals(2, queryList8.size());
assertEquals(1., queryList8.get(0), 0.);
assertEquals(2., queryList8.get(1), 0.);
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.
the class JAXRSUtilsTest method testFindTargetResourceClassWithSubResource.
@Test
public void testFindTargetResourceClassWithSubResource() throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStore.class);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentTypes = "*/*";
OperationResourceInfo ori = findTargetResourceClass(resources, createMessage(), "/bookstore/books/sub/123", "GET", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("getBook", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, createMessage(), "/bookstore/books/123/true/chapter/1", "GET", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("getNewBook", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, createMessage(), "/bookstore/books", "POST", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("addBook", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, createMessage(), "/bookstore/books", "PUT", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("updateBook", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, createMessage(), "/bookstore/books/123", "DELETE", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("deleteBook", ori.getMethodToInvoke().getName());
}
use of org.apache.cxf.jaxrs.model.OperationResourceInfo 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());
}
Aggregations