Search in sources :

Example 16 with URITemplate

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());
}
Also used : URITemplate(org.apache.cxf.jaxrs.model.URITemplate) Test(org.junit.Test)

Example 17 with URITemplate

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;
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) URITemplate(org.apache.cxf.jaxrs.model.URITemplate) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)

Aggregations

URITemplate (org.apache.cxf.jaxrs.model.URITemplate)17 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)8 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)7 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)7 Test (org.junit.Test)5 MethodDispatcher (org.apache.cxf.jaxrs.model.MethodDispatcher)4 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)2 Customer (org.apache.cxf.jaxrs.Customer)2 Message (org.apache.cxf.message.Message)2 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 Parameter (java.lang.reflect.Parameter)1 URI (java.net.URI)1 LinkedHashSet (java.util.LinkedHashSet)1