use of org.apache.cxf.jaxrs.model.URITemplate in project cxf by apache.
the class UriInfoImplTest method testGetTemplateParameters.
@Test
public void testGetTemplateParameters() {
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
new URITemplate("/bar").match("/baz", values);
UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), values);
assertEquals("unexpected templates", 0, u.getPathParameters().size());
values.clear();
new URITemplate("/{id}").match("/bar%201", values);
u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar%201"), values);
MultivaluedMap<String, String> tps = u.getPathParameters(false);
assertEquals("Number of templates is wrong", 1, tps.size());
assertEquals("Wrong template value", tps.getFirst("id"), "bar%201");
values.clear();
new URITemplate("/{id}/{baz}").match("/1%202/bar", values);
u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/1%202/bar"), values);
tps = u.getPathParameters();
assertEquals("Number of templates is wrong", 2, tps.size());
assertEquals("Wrong template value", tps.getFirst("id"), "1 2");
assertEquals("Wrong template value", tps.getFirst("baz"), "bar");
// with suffix
values.clear();
new URITemplate("/bar").match("/bar", values);
u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"), values);
assertEquals("unexpected templates", 0, u.getPathParameters().size());
}
use of org.apache.cxf.jaxrs.model.URITemplate in project cxf by apache.
the class OAuthUtils method checkRequestURI.
public static boolean checkRequestURI(String servletPath, String uri) {
boolean wildcard = uri.endsWith("*");
String theURI = wildcard ? uri.substring(0, uri.length() - 1) : uri;
try {
URITemplate template = new URITemplate(theURI);
MultivaluedMap<String, String> map = new MetadataMap<String, String>();
if (template.match(servletPath, map)) {
String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP);
if (wildcard || StringUtils.isEmpty(finalGroup) || "/".equals(finalGroup)) {
return true;
}
}
} catch (Exception ex) {
// ignore
}
return false;
}
Aggregations