Search in sources :

Example 1 with BookmarkablePageRequestHandler

use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.

the class WicketTesterTest method setQueryParameterWhenRequestHasAnQueryUrl.

/**
 * Asserting that parameters set in request get processed, even if the request URL already has
 * query parameters
 */
@Test
public void setQueryParameterWhenRequestHasAnQueryUrl() {
    PageParameters parameters = new PageParameters();
    parameters.set("q_1", "q_1_value");
    IPageProvider testPageProvider = new PageProvider(MockPageParametersAware.class, parameters);
    IRequestHandler pageRequestHandler = new BookmarkablePageRequestHandler(testPageProvider);
    Url url = tester.getApplication().getRootRequestMapper().mapHandler(pageRequestHandler);
    tester.getRequest().setParameter("q_2", "q_2_value");
    tester.getRequest().setUrl(url);
    tester.processRequest();
    MockPageParametersAware page = (MockPageParametersAware) tester.getLastRenderedPage();
    assertEquals("q_1_value", page.getLastQueryParameters().getParameterValue("q_1").toString());
    assertEquals("q_2_value", page.getLastQueryParameters().getParameterValue("q_2").toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) MockPageParametersAware(org.apache.wicket.MockPageParametersAware) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 2 with BookmarkablePageRequestHandler

use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.

the class ISecuritySettingsTest method enforceMountsWithCryptoMapper.

/**
 * https://issues.apache.org/jira/browse/WICKET-5560
 */
@Test
public void enforceMountsWithCryptoMapper() {
    WebApplication app = tester.getApplication();
    IRequestHandler handler = new BookmarkablePageRequestHandler(new PageProvider(UnknownPage.class));
    String plainTextNonMountedUrl = tester.urlFor(handler).toString();
    assertTrue("Plain text non mounted url should start with wicket/bookmarkable/: " + plainTextNonMountedUrl, plainTextNonMountedUrl.startsWith("wicket/bookmarkable/"));
    tester.executeUrl(plainTextNonMountedUrl);
    tester.assertRenderedPage(UnknownPage.class);
    app.setRootRequestMapper(new CryptoMapper(app.getRootRequestMapper(), app));
    /*
		 * Execute dummy request to get WicketTester to re-initialise with CryptoMapper in place.
		 */
    tester.executeUrl("");
    String encryptedNonMountedUrl = tester.urlFor(handler).toString();
    assertFalse("Encrypted URL should not start with wicket/bookmarkable/" + encryptedNonMountedUrl, encryptedNonMountedUrl.startsWith("wicket/bookmarkable/"));
    tester.executeUrl(plainTextNonMountedUrl);
    assertNull(tester.getLastRenderedPage());
    tester.executeUrl(encryptedNonMountedUrl);
    tester.assertRenderedPage(UnknownPage.class);
    app.mountPackage("unknown", UnknownPage.class);
    tester.executeUrl(plainTextNonMountedUrl);
    assertNull(tester.getLastRenderedPage());
    tester.executeUrl(encryptedNonMountedUrl);
    tester.assertRenderedPage(UnknownPage.class);
    app.getSecuritySettings().setEnforceMounts(true);
    tester.executeUrl(plainTextNonMountedUrl);
    assertNull(tester.getLastRenderedPage());
    tester.executeUrl(encryptedNonMountedUrl);
    assertNull(tester.getLastRenderedPage());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) CryptoMapper(org.apache.wicket.core.request.mapper.CryptoMapper) WebApplication(org.apache.wicket.protocol.http.WebApplication) Test(org.junit.Test)

Example 3 with BookmarkablePageRequestHandler

use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.

the class BaseWicketTester method startPage.

/**
 * Renders a <code>Page</code> from its default constructor.
 *
 * @param <C>
 * @param pageClass
 *            a test <code>Page</code> class with default constructor
 * @param parameters
 *            the parameters to use for the class.
 * @return the rendered <code>Page</code>
 */
@SuppressWarnings("unchecked")
public final <C extends Page> C startPage(final Class<C> pageClass, final PageParameters parameters) {
    Args.notNull(pageClass, "pageClass");
    // must be null for Pages
    componentInPage = null;
    // prepare the request
    request.setUrl(application.getRootRequestMapper().mapHandler(new BookmarkablePageRequestHandler(new PageProvider(pageClass, parameters))));
    // process the request
    processRequest();
    // The last rendered page
    return (C) getLastRenderedPage();
}
Also used : BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) PageProvider(org.apache.wicket.core.request.handler.PageProvider)

Example 4 with BookmarkablePageRequestHandler

use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler 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 5 with BookmarkablePageRequestHandler

use of org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler in project wicket by apache.

the class BookmarkableMapperTest method encode1.

/**
 */
@Test
public void encode1() {
    PageProvider provider = new PageProvider(MockPage.class, new PageParameters());
    provider.setPageSource(context);
    IRequestHandler handler = new BookmarkablePageRequestHandler(provider);
    Url url = encoder.mapHandler(handler);
    assertEquals("wicket/bookmarkable/" + PAGE_CLASS_NAME, url.toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)18 PageProvider (org.apache.wicket.core.request.handler.PageProvider)17 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)16 IRequestHandler (org.apache.wicket.request.IRequestHandler)16 Test (org.junit.Test)16 Url (org.apache.wicket.request.Url)15 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)15 MockPageParametersAware (org.apache.wicket.MockPageParametersAware)2 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)1 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)1 CryptoMapper (org.apache.wicket.core.request.mapper.CryptoMapper)1 InnerPage (org.apache.wicket.core.request.mapper.PackageMapperTest.OuterPage.InnerPage)1 WebApplication (org.apache.wicket.protocol.http.WebApplication)1 IRequestHandlerDelegate (org.apache.wicket.request.IRequestHandlerDelegate)1 IRequestParameters (org.apache.wicket.request.IRequestParameters)1 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)1 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)1 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)1 PageInfo (org.apache.wicket.request.mapper.info.PageInfo)1 StringValue (org.apache.wicket.util.string.StringValue)1