Search in sources :

Example 1 with ListenerRequestHandler

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

the class BehaviorRequestTest method urlForBehavior.

private String urlForBehavior(Behavior behaviorUnderTest) {
    final int index = page.container.getBehaviorId(behaviorUnderTest);
    final IPageAndComponentProvider provider = new PageAndComponentProvider(page, page.container);
    final IRequestHandler handler = new ListenerRequestHandler(provider, index);
    return tester.urlFor(handler).toString();
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) IPageAndComponentProvider(org.apache.wicket.core.request.handler.IPageAndComponentProvider) IPageAndComponentProvider(org.apache.wicket.core.request.handler.IPageAndComponentProvider) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler)

Example 2 with ListenerRequestHandler

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

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

the class BookmarkableMapperTest method decode7.

/**
 */
@Test
public void decode7() {
    Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "?15-ILinkListener.4-foo-bar");
    IRequestHandler handler = encoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(ListenerRequestHandler.class));
    ListenerRequestHandler h = (ListenerRequestHandler) handler;
    IRequestablePage page = h.getPage();
    checkPage(page, 15);
    assertEquals("foo:bar", h.getComponent().getPageRelativePath());
    assertEquals((Object) 4, h.getBehaviorIndex());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 4 with ListenerRequestHandler

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

the class CryptoMapperTest method additionalParameters.

/**
 * Additional parameters, WICKET-4923
 */
@Test
public void additionalParameters() {
    MockPage page = new MockPage();
    IRequestableComponent c = page.get("foo:bar");
    PageAndComponentProvider provider = new PageAndComponentProvider(page, c);
    IRequestHandler handler = new ListenerRequestHandler(provider);
    Url url = mapper.mapHandler(handler);
    url.addQueryParameter("q", "foo");
    Request request = getRequest(url);
    IRequestHandler requestHandler = mapper.mapRequest(request);
    assertThat(requestHandler, instanceOf(RequestSettingRequestHandler.class));
    assertEquals("foo", ((RequestSettingRequestHandler) requestHandler).getRequest().getUrl().getQueryParameterValue("q").toString());
}
Also used : IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) RequestSettingRequestHandler(org.apache.wicket.core.request.handler.RequestSettingRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 5 with ListenerRequestHandler

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

Aggregations

ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)30 IRequestHandler (org.apache.wicket.request.IRequestHandler)25 Url (org.apache.wicket.request.Url)25 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)22 Test (org.junit.Test)21 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)16 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)12 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)5 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)5 MockPage (org.apache.wicket.MockPage)4 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)4 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)4 PageInfo (org.apache.wicket.request.mapper.info.PageInfo)3 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)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 RequestSettingRequestHandler (org.apache.wicket.core.request.handler.RequestSettingRequestHandler)1 WebPage (org.apache.wicket.markup.html.WebPage)1 Request (org.apache.wicket.request.Request)1