Search in sources :

Example 1 with MethodInvocationInfo

use of org.apache.cxf.jaxrs.model.MethodInvocationInfo in project cxf by apache.

the class UriInfoImpl method getMatchedURIs.

public List<String> getMatchedURIs(boolean decode) {
    if (stack != null) {
        List<String> objects = new ArrayList<>();
        List<String> uris = new LinkedList<String>();
        StringBuilder sumPath = new StringBuilder("");
        for (MethodInvocationInfo invocation : stack) {
            List<String> templateObjects = invocation.getTemplateValues();
            OperationResourceInfo ori = invocation.getMethodInfo();
            URITemplate[] paths = { ori.getClassResourceInfo().getURITemplate(), ori.getURITemplate() };
            if (paths[0] != null) {
                int count = paths[0].getVariables().size();
                List<String> rootObjects = new ArrayList<>(count);
                for (int i = 0; i < count && i < templateObjects.size(); i++) {
                    rootObjects.add(templateObjects.get(i));
                }
                uris.add(0, createMatchedPath(paths[0].getValue(), rootObjects, decode));
            }
            if (paths[1] != null && paths[1].getValue().length() > 1) {
                for (URITemplate t : paths) {
                    if (t != null) {
                        sumPath.append("/").append(t.getValue());
                    }
                }
                objects.addAll(templateObjects);
                uris.add(0, createMatchedPath(sumPath.toString(), objects, decode));
            }
        }
        return uris;
    }
    LOG.fine("No resource stack information, returning empty list");
    return Collections.emptyList();
}
Also used : ArrayList(java.util.ArrayList) URITemplate(org.apache.cxf.jaxrs.model.URITemplate) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo) LinkedList(java.util.LinkedList)

Example 2 with MethodInvocationInfo

use of org.apache.cxf.jaxrs.model.MethodInvocationInfo in project cxf by apache.

the class UriInfoImplTest method testGetMatchedURIsRootSub.

@Test
public void testGetMatchedURIsRootSub() throws Exception {
    System.out.println("testGetMatchedURIsRootSub");
    Message m = mockMessage("http://localhost:8080/app", "/foo/bar");
    OperationResourceInfoStack oriStack = new OperationResourceInfoStack();
    ClassResourceInfo cri = getCri(RootResource.class, true);
    OperationResourceInfo ori = getOri(cri, "getSubMethod");
    MethodInvocationInfo miInfo = new MethodInvocationInfo(ori, RootResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    m.put(OperationResourceInfoStack.class, oriStack);
    UriInfoImpl u = new UriInfoImpl(m);
    List<String> matchedUris = getMatchedURIs(u);
    assertEquals(2, matchedUris.size());
    assertEquals("foo/bar", matchedUris.get(0));
    assertEquals("foo", matchedUris.get(1));
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo) Test(org.junit.Test)

Example 3 with MethodInvocationInfo

use of org.apache.cxf.jaxrs.model.MethodInvocationInfo in project cxf by apache.

the class UriInfoImplTest method testGetMatchedURIsSubResourceLocator.

@Test
public void testGetMatchedURIsSubResourceLocator() throws Exception {
    System.out.println("testGetMatchedURIsSubResourceLocator");
    Message m = mockMessage("http://localhost:8080/app", "/foo/sub");
    OperationResourceInfoStack oriStack = new OperationResourceInfoStack();
    ClassResourceInfo rootCri = getCri(RootResource.class, true);
    OperationResourceInfo rootOri = getOri(rootCri, "getSubResourceLocator");
    MethodInvocationInfo miInfo = new MethodInvocationInfo(rootOri, RootResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    ClassResourceInfo subCri = getCri(SubResource.class, false);
    OperationResourceInfo subOri = getOri(subCri, "getFromSub");
    miInfo = new MethodInvocationInfo(subOri, SubResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    m.put(OperationResourceInfoStack.class, oriStack);
    UriInfoImpl u = new UriInfoImpl(m);
    List<String> matchedUris = getMatchedURIs(u);
    assertEquals(2, matchedUris.size());
    assertEquals("foo/sub", matchedUris.get(0));
    assertEquals("foo", matchedUris.get(1));
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ArrayList(java.util.ArrayList) OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo) Test(org.junit.Test)

Example 4 with MethodInvocationInfo

use of org.apache.cxf.jaxrs.model.MethodInvocationInfo in project cxf by apache.

the class JAXRSUtils method pushOntoStack.

public static void pushOntoStack(OperationResourceInfo ori, MultivaluedMap<String, String> params, Message msg) {
    OperationResourceInfoStack stack = msg.get(OperationResourceInfoStack.class);
    if (stack == null) {
        stack = new OperationResourceInfoStack();
        msg.put(OperationResourceInfoStack.class, stack);
    }
    List<String> values = null;
    if (params.size() <= 1) {
        values = Collections.emptyList();
    } else {
        values = new ArrayList<>(params.size() - 1);
        addTemplateVarValues(values, params, ori.getClassResourceInfo().getURITemplate());
        addTemplateVarValues(values, params, ori.getURITemplate());
    }
    Class<?> realClass = ori.getClassResourceInfo().getServiceClass();
    stack.push(new MethodInvocationInfo(ori, realClass, values));
}
Also used : OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo)

Example 5 with MethodInvocationInfo

use of org.apache.cxf.jaxrs.model.MethodInvocationInfo in project cxf by apache.

the class UriInfoImplTest method testGetMatchedURIsSubResourceLocatorSubPath.

@Test
public void testGetMatchedURIsSubResourceLocatorSubPath() throws Exception {
    System.out.println("testGetMatchedURIsSubResourceLocatorSubPath");
    Message m = mockMessage("http://localhost:8080/app", "/foo/sub/subSub");
    OperationResourceInfoStack oriStack = new OperationResourceInfoStack();
    ClassResourceInfo rootCri = getCri(RootResource.class, true);
    OperationResourceInfo rootOri = getOri(rootCri, "getSubResourceLocator");
    MethodInvocationInfo miInfo = new MethodInvocationInfo(rootOri, RootResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    ClassResourceInfo subCri = getCri(SubResource.class, false);
    OperationResourceInfo subOri = getOri(subCri, "getFromSubSub");
    miInfo = new MethodInvocationInfo(subOri, SubResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    m.put(OperationResourceInfoStack.class, oriStack);
    UriInfoImpl u = new UriInfoImpl(m);
    List<String> matchedUris = getMatchedURIs(u);
    assertEquals(3, matchedUris.size());
    assertEquals("foo/sub/subSub", matchedUris.get(0));
    assertEquals("foo/sub", matchedUris.get(1));
    assertEquals("foo", matchedUris.get(2));
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ArrayList(java.util.ArrayList) OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo) Test(org.junit.Test)

Aggregations

MethodInvocationInfo (org.apache.cxf.jaxrs.model.MethodInvocationInfo)6 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)5 OperationResourceInfoStack (org.apache.cxf.jaxrs.model.OperationResourceInfoStack)5 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)4 Message (org.apache.cxf.message.Message)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)1 URITemplate (org.apache.cxf.jaxrs.model.URITemplate)1