Search in sources :

Example 6 with PageAndComponentProvider

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

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

the class PageInstanceMapper method mapRequest.

/**
 * @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
 */
@Override
public IRequestHandler mapRequest(Request request) {
    if (matches(request)) {
        Url url = request.getUrl();
        PageComponentInfo info = getPageComponentInfo(url);
        if (info != null && info.getPageInfo().getPageId() != null) {
            Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null;
            if (info.getComponentInfo() == null) {
                PageProvider provider = new PageProvider(info.getPageInfo().getPageId(), renderCount);
                provider.setPageSource(getContext());
                // render page
                return new RenderPageRequestHandler(provider);
            } else {
                ComponentInfo componentInfo = info.getComponentInfo();
                PageAndComponentProvider provider = new PageAndComponentProvider(info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath());
                provider.setPageSource(getContext());
                return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
            }
        }
    }
    return null;
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) 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) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 8 with PageAndComponentProvider

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

the class BaseWicketTester method executeListener.

/**
 * Simulates processing URL that invokes an {@link IRequestListener} on	a component.
 *
 * After the listener is invoked the page containing the component will be rendered
 * (with an optional redirect - depending on {@link RenderStrategy}).
 *
 * @param component
 * @param listener
 */
public void executeListener(final Component component) {
    Args.notNull(component, "component");
    // there are two ways to do this. RequestCycle could be forced to call the handler
    // directly but constructing and parsing the URL increases the chance of triggering bugs
    Page page = component.getPage();
    PageAndComponentProvider pageAndComponentProvider = new PageAndComponentProvider(page, component);
    IRequestHandler handler = null;
    if (page.isPageStateless() || (page.isBookmarkable() && page.wasCreatedBookmarkable())) {
        handler = new BookmarkableListenerRequestHandler(pageAndComponentProvider);
    } else {
        handler = new ListenerRequestHandler(pageAndComponentProvider);
    }
    Url url = urlFor(handler);
    request.setUrl(url);
    // Process the request
    processRequest(request, null);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) Url(org.apache.wicket.request.Url)

Example 9 with PageAndComponentProvider

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

the class BaseWicketTester method invokeListener.

/**
 * Simulates invoking an {@link IRequestListener} on a component. As opposed to the
 * {@link #executeListener(Component)} method, current request/response objects will be used
 *
 * After the listener is invoked the page containing the component will be rendered
 * (with an optional redirect - depending on {@link RenderStrategy}).
 *
 * @param component
 * @param listener
 */
public void invokeListener(final Component component) {
    Args.notNull(component, "component");
    // there are two ways to do this. RequestCycle could be forced to call the handler
    // directly but constructing and parsing the URL increases the chance of triggering bugs
    IRequestHandler handler = new ListenerRequestHandler(new PageAndComponentProvider(component.getPage(), component));
    processRequest(handler);
}
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)

Example 10 with PageAndComponentProvider

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

the class BaseWicketTester method invokeListener.

/**
 * Simulates invoking an {@link IRequestListener} on a component. As opposed to the
 * {@link #executeListener(Component)} method, current request/response objects will be used
 *
 * After the listener is invoked the page containing the component will be rendered
 * (with an optional redirect - depending on {@link RenderStrategy}).
 *
 * @param component
 * @param listener
 */
public void invokeListener(Component component, final Behavior behavior) {
    Args.notNull(component, "component");
    Args.notNull(behavior, "behavior");
    // there are two ways to do this. RequestCycle could be forced to call the handler
    // directly but constructing and parsing the URL increases the chance of triggering bugs
    IRequestHandler handler = new ListenerRequestHandler(new PageAndComponentProvider(component.getPage(), component), component.getBehaviorId(behavior));
    processRequest(handler);
}
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)

Aggregations

PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)20 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)17 IRequestHandler (org.apache.wicket.request.IRequestHandler)17 Url (org.apache.wicket.request.Url)15 Test (org.junit.Test)13 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)12 MockPage (org.apache.wicket.MockPage)10 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)10 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)3 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)2 Page (org.apache.wicket.Page)1 IPageAndComponentProvider (org.apache.wicket.core.request.handler.IPageAndComponentProvider)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)1 RequestSettingRequestHandler (org.apache.wicket.core.request.handler.RequestSettingRequestHandler)1 WebPage (org.apache.wicket.markup.html.WebPage)1 Request (org.apache.wicket.request.Request)1 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)1 PageInfo (org.apache.wicket.request.mapper.info.PageInfo)1