Search in sources :

Example 6 with Dispatcher

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

the class JavaScriptModule method setupModuleDispatchers.

@Contribute(Dispatcher.class)
@Primary
public static void setupModuleDispatchers(OrderedConfiguration<Dispatcher> configuration, ModuleManager moduleManager, OperationTracker tracker, ResourceStreamer resourceStreamer, PathConstructor pathConstructor, JavaScriptStackSource javaScriptStackSource, JavaScriptStackPathConstructor javaScriptStackPathConstructor, LocalizationSetter localizationSetter, @Symbol(SymbolConstants.MODULE_PATH_PREFIX) String modulePathPrefix, @Symbol(SymbolConstants.ASSET_PATH_PREFIX) String assetPathPrefix) {
    configuration.add("Modules", new ModuleDispatcher(moduleManager, resourceStreamer, tracker, pathConstructor, javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, modulePathPrefix, assetPathPrefix, false), "after:Asset", "before:ComponentEvent");
    configuration.add("ComnpressedModules", new ModuleDispatcher(moduleManager, resourceStreamer, tracker, pathConstructor, javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, modulePathPrefix, assetPathPrefix, true), "after:Modules", "before:ComponentEvent");
}
Also used : ModuleDispatcher(org.apache.tapestry5.internal.services.javascript.ModuleDispatcher) Primary(org.apache.tapestry5.ioc.annotations.Primary) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 7 with Dispatcher

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

the class ComponentEventDispatcherTest method request_for_whitelist_only_page_from_valid_client.

@Test
public void request_for_whitelist_only_page_from_valid_client() throws IOException {
    String containerPageName = "foo/MyPage";
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter localizationSetter = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = newMock(MetaDataLocator.class);
    ClientWhitelist whitelist = newMock(ClientWhitelist.class);
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters(containerPageName, containerPageName, "", "anevent", new EmptyEventContext(), new EmptyEventContext());
    train_getPath(request, "/foo/MyPage:anevent");
    expect(localizationSetter.isSupportedLocaleName("foo")).andReturn(false);
    train_isPageName(resolver, containerPageName, true);
    train_canonicalizePageName(resolver, containerPageName, containerPageName);
    expect(metaDataLocator.findMeta(MetaDataConstants.WHITELIST_ONLY_PAGE, containerPageName, boolean.class)).andReturn(true);
    expect(whitelist.isClientRequestOnWhitelist()).andReturn(true);
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    train_for_request_locale(request, localizationSetter);
    handler.handleComponentEvent(expectedParameters);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, localizationSetter, response, null, null, null, true, null, "", metaDataLocator, whitelist));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : ClientWhitelist(org.apache.tapestry5.services.security.ClientWhitelist) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) Response(org.apache.tapestry5.http.services.Response) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 8 with Dispatcher

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

the class ComponentEventDispatcherTest method page_activation_context_in_request.

@Test
public void page_activation_context_in_request() throws Exception {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters("mypage", "mypage", "", "eventname", new URLEventContext(contextValueEncoder, new String[] { "alpha", "beta" }), new EmptyEventContext());
    train_getPath(request, "/mypage:eventname");
    expect(ls.isSupportedLocaleName("mypage:eventname")).andReturn(false);
    train_isPageName(resolver, "mypage", true);
    train_canonicalizePageName(resolver, "mypage", "mypage");
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, "alpha/beta");
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    train_for_request_locale(request, ls);
    handler.handleComponentEvent(expectedParameters);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) Response(org.apache.tapestry5.http.services.Response) URLEventContext(org.apache.tapestry5.internal.URLEventContext) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Aggregations

Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7 Request (org.apache.tapestry5.http.services.Request)7 Response (org.apache.tapestry5.http.services.Response)7 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)7 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)6 Test (org.testng.annotations.Test)6 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)5 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)5 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)4 URLEventContext (org.apache.tapestry5.internal.URLEventContext)2 ClientWhitelist (org.apache.tapestry5.services.security.ClientWhitelist)2 ModuleDispatcher (org.apache.tapestry5.internal.services.javascript.ModuleDispatcher)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 Primary (org.apache.tapestry5.ioc.annotations.Primary)1