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();
}
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));
}
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));
}
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));
}
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));
}
Aggregations