Search in sources :

Example 1 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.

the class AbstractBookmarkableMapper method processListener.

/**
 * Creates a {@code IRequestHandler} that notifies an {@link IRequestListener}.
 *
 * @param pageComponentInfo
 * @param pageClass
 * @param pageParameters
 * @return a {@code IRequestHandler} that notifies an {@link IRequestListener}.
 */
protected IRequestHandler processListener(PageComponentInfo pageComponentInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters) {
    PageInfo pageInfo = pageComponentInfo.getPageInfo();
    ComponentInfo componentInfo = pageComponentInfo.getComponentInfo();
    Integer renderCount = null;
    if (componentInfo != null) {
        renderCount = componentInfo.getRenderCount();
    }
    PageAndComponentProvider provider = new PageAndComponentProvider(pageInfo.getPageId(), pageClass, pageParameters, renderCount, componentInfo.getComponentPath());
    provider.setPageSource(getContext());
    checkExpiration(provider, pageInfo);
    return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)

Example 2 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.

the class AbstractBookmarkableMapper method mapHandler.

@Override
public Url mapHandler(IRequestHandler requestHandler) {
    // eliminate the need for IRequestHandlerDelegate
    while (requestHandler instanceof IRequestHandlerDelegate) {
        requestHandler = ((IRequestHandlerDelegate) requestHandler).getDelegateHandler();
    }
    if (requestHandler instanceof BookmarkablePageRequestHandler) {
        // simple bookmarkable URL with no page instance information
        BookmarkablePageRequestHandler handler = (BookmarkablePageRequestHandler) requestHandler;
        if (!checkPageClass(handler.getPageClass())) {
            return null;
        }
        PageInfo info = new PageInfo();
        UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
        return buildUrl(urlInfo);
    } else if (requestHandler instanceof RenderPageRequestHandler) {
        // possibly hybrid URL - bookmarkable URL with page instance information
        // but only allowed if the page was created by bookmarkable URL
        RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
        if (!checkPageClass(handler.getPageClass())) {
            return null;
        }
        if (handler.getPageProvider().isNewPageInstance()) {
            // no existing page instance available, don't bother creating new page instance
            PageInfo info = new PageInfo();
            UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
            return buildUrl(urlInfo);
        }
        IRequestablePage page = handler.getPage();
        if (checkPageInstance(page) && (!pageMustHaveBeenCreatedBookmarkable() || page.wasCreatedBookmarkable())) {
            PageInfo info = getPageInfo(handler);
            PageComponentInfo pageComponentInfo = new PageComponentInfo(info, null);
            UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), handler.getPageParameters());
            return buildUrl(urlInfo);
        } else {
            return null;
        }
    } else if (requestHandler instanceof BookmarkableListenerRequestHandler) {
        // request listener URL with page class information
        BookmarkableListenerRequestHandler handler = (BookmarkableListenerRequestHandler) requestHandler;
        Class<? extends IRequestablePage> pageClass = handler.getPageClass();
        if (!checkPageClass(pageClass)) {
            return null;
        }
        Integer renderCount = null;
        if (handler.includeRenderCount()) {
            renderCount = handler.getRenderCount();
        }
        PageInfo pageInfo = getPageInfo(handler);
        ComponentInfo componentInfo = new ComponentInfo(renderCount, handler.getComponentPath(), handler.getBehaviorIndex());
        PageParameters parameters = getRecreateMountedPagesAfterExpiry() ? new PageParameters(handler.getPage().getPageParameters()).mergeWith(handler.getPageParameters()) : handler.getPageParameters();
        UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(pageInfo, componentInfo), pageClass, parameters);
        return buildUrl(urlInfo);
    }
    return null;
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IRequestHandlerDelegate(org.apache.wicket.request.IRequestHandlerDelegate) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 3 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.

the class CryptoMapperTest method mountedPageRequestListenerParameter.

/**
 * Tests that PageComponentInfo parameters are encrypted on Mounted pages
 */
@Test
public void mountedPageRequestListenerParameter() {
    final String componentPath = "link";
    PageAndComponentProvider provider = new PageAndComponentProvider(Page1.class, componentPath);
    IRequestHandler requestHandler = new ListenerRequestHandler(provider);
    Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler);
    assertTrue(plainUrl.toString().startsWith(MOUNTED_URL));
    /*
		 * Do not allow unencrypted request listener urls to mounted pages.
		 */
    assertNull(mapper.mapRequest(getRequest(plainUrl)));
    /*
		 * Test encryption of request listener parameter.
		 */
    Url encryptedUrl = mapper.mapHandler(requestHandler);
    assertEquals(Url.parse(MOUNTED_URL).getSegments(), encryptedUrl.getSegments());
    assertTrue(encryptedUrl.getQueryParameters().size() > 0);
    for (Url.QueryParameter qp : encryptedUrl.getQueryParameters()) {
        if (Strings.isEmpty(qp.getValue())) {
            PageComponentInfo pci = PageComponentInfo.parse(qp.getName());
            assertNull("PageComponentInfo query parameter not encrypted", pci);
        }
    }
    requestHandler = mapper.mapRequest(getRequest(encryptedUrl));
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(ListenerRequestHandler.class));
    ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
    assertEquals(componentPath, handler.getComponentPath());
    assertEquals(Page1.class, handler.getPageClass());
    /*
		 * We anticipate that sometimes multiple cryptomappers will be used. It should still work in these situations.
		 */
    requestHandler = new CryptoMapper(mapper, tester.getApplication()).mapRequest(getRequest(encryptedUrl));
    assertNotNull(requestHandler);
    requestHandler = unwrapRequestHandlerDelegate(requestHandler);
    assertThat(requestHandler, instanceOf(ListenerRequestHandler.class));
    handler = (ListenerRequestHandler) requestHandler;
    assertEquals(componentPath, handler.getComponentPath());
    assertEquals(Page1.class, handler.getPageClass());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) Test(org.junit.Test)

Example 4 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.

the class BookmarkableMapper method parseRequest.

@Override
protected UrlInfo parseRequest(Request request) {
    if (Application.exists()) {
        if (Application.get().getSecuritySettings().getEnforceMounts()) {
            return null;
        }
    }
    if (matches(request)) {
        Url url = request.getUrl();
        // try to extract page and component information from URL
        PageComponentInfo info = getPageComponentInfo(url);
        List<String> segments = url.getSegments();
        // load the page class
        String className;
        if (segments.size() >= 3) {
            className = segments.get(2);
        } else {
            className = segments.get(1);
        }
        if (Strings.isEmpty(className)) {
            return null;
        }
        Class<? extends IRequestablePage> pageClass = getPageClass(className);
        if (pageClass != null && IRequestablePage.class.isAssignableFrom(pageClass)) {
            // extract the PageParameters from URL if there are any
            PageParameters pageParameters = extractPageParameters(request, 3, pageParametersEncoder);
            if (pageParameters != null) {
                pageParameters.setLocale(resolveLocale());
            }
            return new UrlInfo(info, pageClass, pageParameters);
        }
    }
    return null;
}
Also used : IRequestablePage(org.apache.wicket.request.component.IRequestablePage) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 5 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.

the class MountedMapper method mapHandler.

@Override
public Url mapHandler(IRequestHandler requestHandler) {
    Url url = super.mapHandler(requestHandler);
    if (url == null && requestHandler instanceof ListenerRequestHandler && getRecreateMountedPagesAfterExpiry()) {
        ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
        IRequestablePage page = handler.getPage();
        if (checkPageInstance(page)) {
            Integer renderCount = null;
            if (handler.includeRenderCount()) {
                renderCount = page.getRenderCount();
            }
            String componentPath = handler.getComponentPath();
            PageInfo pageInfo = getPageInfo(handler);
            ComponentInfo componentInfo = new ComponentInfo(renderCount, componentPath, handler.getBehaviorIndex());
            PageComponentInfo pageComponentInfo = new PageComponentInfo(pageInfo, componentInfo);
            PageParameters parameters = newPageParameters();
            parameters.mergeWith(page.getPageParameters());
            UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), parameters.mergeWith(handler.getPageParameters()));
            url = buildUrl(urlInfo);
        }
    }
    return url;
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Aggregations

PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)9 Url (org.apache.wicket.request.Url)6 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)5 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)5 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)5 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)5 PageInfo (org.apache.wicket.request.mapper.info.PageInfo)4 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)3 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)3 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)3 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1 IRequestHandler (org.apache.wicket.request.IRequestHandler)1 IRequestHandlerDelegate (org.apache.wicket.request.IRequestHandlerDelegate)1 Request (org.apache.wicket.request.Request)1 Test (org.junit.Test)1