Java Code Examples for org.apache.cxf.jaxrs.model.OperationResourceInfo#setURITemplate()

The following examples show how to use org.apache.cxf.jaxrs.model.OperationResourceInfo#setURITemplate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testConversion() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    OperationResourceInfo ori =
        new OperationResourceInfo(
            Customer.class.getMethod("testConversion",
                                     new Class[]{PathSegmentImpl.class,
                                                 SimpleFactory.class}),
            cri);
    ori.setHttpMethod("GET");
    ori.setURITemplate(new URITemplate("{id1}/{id2}"));
    MultivaluedMap<String, String> values = new MetadataMap<>();
    values.putSingle("id1", "1");
    values.putSingle("id2", "2");

    Message m = createMessage();


    List<Object> params =
        JAXRSUtils.processParameters(ori, values, m);
    PathSegment ps = (PathSegment)params.get(0);
    assertEquals("1", ps.getPath());

    SimpleFactory sf = (SimpleFactory)params.get(1);
    assertEquals(2, sf.getId());
}
 
Example 2
Source File: ResourceUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static OperationResourceInfo createOperationInfo(Method m, Method annotatedMethod,
                                                  ClassResourceInfo cri, Path path, String httpMethod) {
    OperationResourceInfo ori = new OperationResourceInfo(m, annotatedMethod, cri);
    URITemplate t = URITemplate.createTemplate(path);
    ori.setURITemplate(t);
    ori.setHttpMethod(httpMethod);
    return ori;
}
 
Example 3
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSelectResourceMethod() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class);
    OperationResourceInfo ori1 = new OperationResourceInfo(
                                     Customer.class.getMethod("getItAsXML", new Class[]{}),
                                     cri);
    ori1.setHttpMethod("GET");
    ori1.setURITemplate(new URITemplate("/"));
    OperationResourceInfo ori2 = new OperationResourceInfo(
                                     Customer.class.getMethod("getItPlain", new Class[]{}),
                                     cri);
    ori2.setHttpMethod("GET");
    ori2.setURITemplate(new URITemplate("/"));
    MethodDispatcher md = new MethodDispatcher();
    md.bind(ori1, Customer.class.getMethod("getItAsXML", new Class[]{}));
    md.bind(ori2, Customer.class.getMethod("getItPlain", new Class[]{}));
    cri.setMethodDispatcher(md);

    OperationResourceInfo ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage(), "GET",
          new MetadataMap<String, String>(), "*/*", getTypes("text/plain"));

    assertSame(ori, ori2);

    ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage(), "GET", new MetadataMap<String, String>(),
                                          "*/*", getTypes("text/xml"));

    assertSame(ori, ori1);

    ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage(), "GET", new MetadataMap<String, String>(),
                                      "*/*",
                                      sortMediaTypes(getTypes("*/*;q=0.1,text/plain,text/xml;q=0.8")));

    assertSame(ori, ori2);
    ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage(), "GET", new MetadataMap<String, String>(),
                                      "*/*",
                                      sortMediaTypes(getTypes("*;q=0.1,text/plain,text/xml;q=0.9,x/y")));

    assertSame(ori, ori2);
}
 
Example 4
Source File: UriInfoImplTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static OperationResourceInfo getOri(ClassResourceInfo cri, String methodName) throws Exception {
    Method method = cri.getResourceClass().getMethod(methodName);
    OperationResourceInfo ori = new OperationResourceInfo(method, cri);
    ori.setURITemplate(URITemplate.createTemplate(AnnotationUtils.getMethodAnnotation(method, Path.class)));
    return ori;
}