Search in sources :

Example 21 with PageRenderRequestParameters

use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method context_passed_in_path.

private void context_passed_in_path(boolean finalSlash) throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest(true);
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    String path = "/foo/Bar/zip/zoom" + (finalSlash ? "/" : "");
    train_getPath(request, path);
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/Bar/zip/zoom", false);
    train_isPageName(resolver, "foo/Bar/zip", false);
    train_isPageName(resolver, "foo/Bar", true);
    train_canonicalizePageName(resolver, "foo/Bar", "foo/bar");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertEquals(parameters.getLogicalPageName(), "foo/bar");
    assertArraysEqual(parameters.getActivationContext().toStrings(), "zip", "zoom");
    assertTrue(parameters.isLoopback());
    verify();
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator)

Example 22 with PageRenderRequestParameters

use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method locale_not_encoded.

@Test
public void locale_not_encoded() {
    RequestSecurityManager manager = mockRequestSecurityManager();
    Response response = mockResponse();
    ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
    expect(manager.checkPageSecurity("MyPage")).andReturn(LinkSecurity.INSECURE);
    train_encodeURL(response, "/myapp/mypage", "MAGIC");
    replay();
    ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "/myapp", "", null, null);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("MyPage", new EmptyEventContext());
    Link link = encoder.createPageRenderLink(parameters);
    assertEquals(link.toURI(), "MAGIC");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ContextPathEncoder(org.apache.tapestry5.services.ContextPathEncoder) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 23 with PageRenderRequestParameters

use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.

the class LinkSourceImplTest method testPageLinkCreation2.

private void testPageLinkCreation2(String pageName, boolean overrideContext, Object... context) {
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    LinkCreationListener2 listener = mockLinkCreationListener2();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    ComponentClassResolver resolver = mockComponentClassResolver();
    String canonical = "CanonicalPageName";
    RequestGlobals globals = mockRequestGlobals();
    // Ensure that the loopback logic is off; loopback logic is fully tested via an
    // integration test.
    expect(globals.getActivePageName()).andReturn("someOtherPage");
    train_canonicalizePageName(resolver, pageName, canonical);
    if (!overrideContext)
        train_collectPageActivationContext(collector, canonical, context);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters(canonical, new ArrayEventContext(typeCoercer, context), false);
    expect(linkEncoder.createPageRenderLink(parameters)).andReturn(link);
    listener.createdPageRenderLink(link, parameters);
    replay();
    LinkSource source = new LinkSourceImpl(null, collector, typeCoercer, resolver, linkEncoder, globals, null, emptyConfiguration);
    source.getLinkCreationHub().addListener(listener);
    Object[] passedContext = overrideContext ? context : new Object[0];
    Link returnedLink = source.createPageRenderLink(pageName, overrideContext, passedContext);
    assertSame(returnedLink, link);
    verify();
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Link(org.apache.tapestry5.http.Link)

Example 24 with PageRenderRequestParameters

use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.

the class LinkSourceImplTest method create_page_render_link_by_name.

@Test
public void create_page_render_link_by_name() {
    String pageName = "order/Edit";
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    ComponentClassResolver resolver = mockComponentClassResolver();
    RequestGlobals globals = mockRequestGlobals();
    expect(globals.getActivePageName()).andReturn("someOtherPage");
    train_canonicalizePageName(resolver, pageName, pageName);
    train_collectPageActivationContext(collector, pageName, 3);
    EventContext pageActivationContext = new ArrayEventContext(typeCoercer, 3);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters(pageName, pageActivationContext, false);
    expect(linkEncoder.createPageRenderLink(parameters)).andReturn(link);
    replay();
    LinkSource source = new LinkSourceImpl(null, collector, typeCoercer, resolver, linkEncoder, globals, null, emptyConfiguration);
    Link actual = source.createPageRenderLink(pageName, false);
    // Make sure the same link is returned.
    assertEquals(actual, link);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 25 with PageRenderRequestParameters

use of org.apache.tapestry5.services.PageRenderRequestParameters in project tapestry-5 by apache.

the class PageRenderDispatcher method dispatch.

public boolean dispatch(Request request, final Response response) throws IOException {
    if (request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND) != null) {
        // This needs to be cleared out because the container may submit a request back into the filter
        // for the 404 page and some containers reuse the existing HttpServletRequest. See TAP5-2388.
        request.setAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND, null);
        return false;
    }
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    if (parameters == null)
        return false;
    componentRequestHandler.handlePageRender(parameters);
    return true;
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters)

Aggregations

PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)24 Test (org.testng.annotations.Test)14 Request (org.apache.tapestry5.http.services.Request)12 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)11 Link (org.apache.tapestry5.http.Link)10 Response (org.apache.tapestry5.http.services.Response)10 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)9 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)8 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)8 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)6 EventContext (org.apache.tapestry5.EventContext)3 RequestGlobals (org.apache.tapestry5.http.services.RequestGlobals)3 ContextPathEncoder (org.apache.tapestry5.services.ContextPathEncoder)3 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)3 Page (org.apache.tapestry5.internal.structure.Page)2 PageRenderRequestHandler (org.apache.tapestry5.services.PageRenderRequestHandler)2 IOException (java.io.IOException)1 Locale (java.util.Locale)1 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 ArrayEventContext (org.apache.tapestry5.internal.services.ArrayEventContext)1