Search in sources :

Example 31 with RequestPathInfo

use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.

the class MockSlingHttpServletRequest method getPathInfo.

@Override
public String getPathInfo() {
    RequestPathInfo requestPathInfo = this.getRequestPathInfo();
    if (StringUtils.isEmpty(requestPathInfo.getResourcePath())) {
        return null;
    }
    StringBuilder pathInfo = new StringBuilder();
    pathInfo.append(requestPathInfo.getResourcePath());
    if (StringUtils.isNotEmpty(requestPathInfo.getSelectorString())) {
        pathInfo.append('.');
        pathInfo.append(requestPathInfo.getSelectorString());
    }
    if (StringUtils.isNotEmpty(requestPathInfo.getExtension())) {
        pathInfo.append('.');
        pathInfo.append(requestPathInfo.getExtension());
    }
    if (StringUtils.isNotEmpty(requestPathInfo.getSuffix())) {
        pathInfo.append(requestPathInfo.getSuffix());
    }
    return pathInfo.toString();
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 32 with RequestPathInfo

use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.

the class UrlFilterTest method non_null_selector.

@Test
public void non_null_selector() {
    UrlFilter filter = new UrlFilter();
    final RequestPathInfo testInfo = context.mock(RequestPathInfo.class);
    this.context.checking(new Expectations() {

        {
            allowing(testInfo).getSelectorString();
            will(returnValue("sample"));
        }
    });
    // null allowedSelectors = ok
    assertTrue(filter.checkSelector(testInfo, properties));
    // empty array allowedSelectors = fail
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[0]);
    assertFalse(filter.checkSelector(testInfo, properties));
    // selector string in array = ok
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] { "sample", "sample2" });
    assertTrue(filter.checkSelector(testInfo, properties));
    // selector string not in array = fail
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] { "other" });
    assertFalse(filter.checkSelector(testInfo, properties));
    properties.clear();
    // matches regex
    properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m.*$");
    assertTrue(filter.checkSelector(testInfo, properties));
    // doesn't match regex
    properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[1-2]m$");
    assertFalse(filter.checkSelector(testInfo, properties));
    properties.clear();
    // matches array or regex = ok
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] { "other" });
    properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m.*$");
    assertTrue(filter.checkSelector(testInfo, properties));
    properties.put(UrlFilter.PN_ALLOWED_SELECTORS, (Object) new String[] { "sample" });
    properties.put(UrlFilter.PN_ALLOWED_SELECTOR_PATTERN, "^s[a-z]m$");
    assertTrue(filter.checkSelector(testInfo, properties));
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Example 33 with RequestPathInfo

use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.

the class RequestData method initServlet.

public void initServlet(final Resource resource, final ServletResolver sr) {
    // the resource and the request path info, will never be null
    RequestPathInfo requestPathInfo = new SlingRequestPathInfo(resource);
    ContentData contentData = setContent(resource, requestPathInfo);
    requestProgressTracker.log("Resource Path Info: {0}", requestPathInfo);
    // finally resolve the servlet for the resource
    requestProgressTracker.startTimer("ServletResolution");
    Servlet servlet = sr.resolveServlet(slingRequest);
    requestProgressTracker.logTimer("ServletResolution", "URI={0} handled by Servlet={1}", getServletRequest().getRequestURI(), (servlet == null ? "-none-" : RequestUtil.getServletName(servlet)));
    contentData.setServlet(servlet);
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) SlingMainServlet(org.apache.sling.engine.impl.SlingMainServlet) Servlet(javax.servlet.Servlet)

Aggregations

RequestPathInfo (org.apache.sling.api.request.RequestPathInfo)33 Resource (org.apache.sling.api.resource.Resource)4 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Servlet (javax.servlet.Servlet)1 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 SlingMainServlet (org.apache.sling.engine.impl.SlingMainServlet)1 VersioningConfiguration (org.apache.sling.servlets.post.VersioningConfiguration)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1