You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2009/01/27 20:21:32 UTC
svn commit: r738194 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/internal/services/
main/java/org/apache/tapestry5/services/ main/java/org/apache/tapestry5/test/
test/java/org/apache/tapestry5/internal/services/
Author: hlship
Date: Tue Jan 27 19:21:32 2009
New Revision: 738194
URL: http://svn.apache.org/viewvc?rev=738194&view=rev
Log:
TAP5-476: Have a common handler/filter pipeline for both component event and page render requests, to make it easier to add filters that apply to both types of requests
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentRequestHandlerTerminator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupRendererTerminator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupRendererTerminator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestFilter.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestHandler.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventDispatcher.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderDispatcher.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventDispatcherTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageRenderDispatcherTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventDispatcher.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventDispatcher.java?rev=738194&r1=738193&r2=738194&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventDispatcher.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventDispatcher.java Tue Jan 27 19:21:32 2009
@@ -45,24 +45,22 @@
{
private final ComponentClassResolver componentClassResolver;
- private final ComponentEventRequestHandler componentEventRequestHandler;
-
private final ContextPathEncoder contextPathEncoder;
private final LocalizationSetter localizationSetter;
- public ComponentEventDispatcher(
- @Traditional
- ComponentEventRequestHandler componentEventRequestHandler,
+ private final ComponentRequestHandler componentRequestHandler;
+ public ComponentEventDispatcher(
ComponentClassResolver componentClassResolver,
-
- ContextPathEncoder contextPathEncoder, LocalizationSetter localizationSetter)
+ ContextPathEncoder contextPathEncoder,
+ LocalizationSetter localizationSetter,
+ ComponentRequestHandler componentRequestHandler)
{
- this.componentEventRequestHandler = componentEventRequestHandler;
this.componentClassResolver = componentClassResolver;
this.contextPathEncoder = contextPathEncoder;
this.localizationSetter = localizationSetter;
+ this.componentRequestHandler = componentRequestHandler;
}
// A beast that recognizes all the elements of a path in a single go.
@@ -137,7 +135,7 @@
activationContext,
eventContext);
- componentEventRequestHandler.handle(parameters);
+ componentRequestHandler.handleComponentEvent(parameters);
return true;
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentRequestHandlerTerminator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentRequestHandlerTerminator.java?rev=738194&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentRequestHandlerTerminator.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentRequestHandlerTerminator.java Tue Jan 27 19:21:32 2009
@@ -0,0 +1,50 @@
+// Copyright 2009 Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services;
+
+import org.apache.tapestry5.services.*;
+
+import java.io.IOException;
+
+/**
+ * Terminator for the {@link org.apache.tapestry5.services.ComponentRequestHandler} pipeline, that feeds out into the
+ * {@link org.apache.tapestry5.services.ComponentEventRequestHandler} and {@link org.apache.tapestry5.services.PageRenderRequestHandler}
+ * pipelines.
+ *
+ * @sicne 5.1.0.0
+ */
+public class ComponentRequestHandlerTerminator implements ComponentRequestHandler
+{
+ private final ComponentEventRequestHandler componentEventRequestHandler;
+
+ private final PageRenderRequestHandler pageRenderRequestHandler;
+
+ public ComponentRequestHandlerTerminator(@Traditional ComponentEventRequestHandler componentEventRequestHandler,
+ PageRenderRequestHandler pageRenderRequestHandler)
+ {
+ this.componentEventRequestHandler = componentEventRequestHandler;
+ this.pageRenderRequestHandler = pageRenderRequestHandler;
+ }
+
+ public void handleComponentEvent(ComponentEventRequestParameters parameters) throws IOException
+ {
+ componentEventRequestHandler.handle(parameters);
+ }
+
+ public void handlePageRender(PageRenderRequestParameters parameters) throws IOException
+ {
+ pageRenderRequestHandler.handle(parameters);
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupRendererTerminator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupRendererTerminator.java?rev=738194&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupRendererTerminator.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupRendererTerminator.java Tue Jan 27 19:21:32 2009
@@ -0,0 +1,39 @@
+// Copyright 2009 Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services;
+
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.services.MarkupRenderer;
+
+/**
+ * Terminator for the [@link MarkupRenderer} pipeline, which exists to invoke {@link
+ * org.apache.tapestry5.internal.services.PageRenderQueue#render(org.apache.tapestry5.MarkupWriter)}.
+ *
+ * @since 5.1.0.0
+ */
+public class MarkupRendererTerminator implements MarkupRenderer
+{
+ private final PageRenderQueue pageRenderQueue;
+
+ public MarkupRendererTerminator(PageRenderQueue pageRenderQueue)
+ {
+ this.pageRenderQueue = pageRenderQueue;
+ }
+
+ public void renderMarkup(MarkupWriter writer)
+ {
+ pageRenderQueue.render(writer);
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderDispatcher.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderDispatcher.java?rev=738194&r1=738193&r2=738194&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderDispatcher.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderDispatcher.java Tue Jan 27 19:21:32 2009
@@ -28,19 +28,21 @@
{
private final ComponentClassResolver componentClassResolver;
- private final PageRenderRequestHandler handler;
-
private final ContextPathEncoder contextPathEncoder;
private final LocalizationSetter localizationSetter;
- public PageRenderDispatcher(ComponentClassResolver componentClassResolver, PageRenderRequestHandler handler,
- ContextPathEncoder contextPathEncoder, LocalizationSetter localizationSetter)
+ private final ComponentRequestHandler componentRequestHandler;
+
+ public PageRenderDispatcher(ComponentClassResolver componentClassResolver,
+ ContextPathEncoder contextPathEncoder,
+ LocalizationSetter localizationSetter,
+ ComponentRequestHandler componentRequestHandler)
{
this.componentClassResolver = componentClassResolver;
- this.handler = handler;
this.contextPathEncoder = contextPathEncoder;
this.localizationSetter = localizationSetter;
+ this.componentRequestHandler = componentRequestHandler;
}
public boolean dispatch(Request request, final Response response) throws IOException
@@ -112,7 +114,7 @@
PageRenderRequestParameters parameters = new PageRenderRequestParameters(pageName, activationContext);
- handler.handle(parameters);
+ componentRequestHandler.handlePageRender(parameters);
return true;
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupRendererTerminator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupRendererTerminator.java?rev=738194&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupRendererTerminator.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupRendererTerminator.java Tue Jan 27 19:21:32 2009
@@ -0,0 +1,41 @@
+// Copyright 2009 Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services;
+
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.json.JSONObject;
+import org.apache.tapestry5.services.PartialMarkupRenderer;
+
+/**
+ * Terminator for the {@link org.apache.tapestry5.services.PartialMarkupRenderer} pipeline, which ultimately invokes
+ * {@link org.apache.tapestry5.internal.services.PageRenderQueue#renderPartial(org.apache.tapestry5.MarkupWriter,
+ * org.apache.tapestry5.json.JSONObject)}.
+ *
+ * @since 5.1.0.0
+ */
+public class PartialMarkupRendererTerminator implements PartialMarkupRenderer
+{
+ private final PageRenderQueue renderQueue;
+
+ public PartialMarkupRendererTerminator(PageRenderQueue renderQueue)
+ {
+ this.renderQueue = renderQueue;
+ }
+
+ public void renderMarkup(MarkupWriter writer, JSONObject reply)
+ {
+ renderQueue.renderPartial(writer, reply);
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestFilter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestFilter.java?rev=738194&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestFilter.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestFilter.java Tue Jan 27 19:21:32 2009
@@ -0,0 +1,43 @@
+// Copyright 2009 Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.services;
+
+import java.io.IOException;
+
+/**
+ * Filter interface for {@link org.apache.tapestry5.services.ComponentRequestHandler}.
+ */
+public interface ComponentRequestFilter
+{
+ /**
+ * Handler for a component action request which will trigger an event on a component and use the return value to
+ * send a response to the client (typically, a redirect to a page render URL).
+ *
+ * @param parameters defining the requst
+ * @param handler next handler in the pipeline
+ */
+ void handleComponentEvent(ComponentEventRequestParameters parameters, ComponentRequestHandler handler)
+ throws IOException;
+
+ /**
+ * Invoked to activate and render a page. In certain cases, based on values returned when activating the page, a
+ * {@link org.apache.tapestry5.services.ComponentEventResultProcessor} may be used to send an alternate response
+ * (typically, a redirect).
+ *
+ * @param parameters defines the page name and activation context
+ * @param handler next handler in the pipeline
+ */
+ void handlePageRender(PageRenderRequestParameters parameters, ComponentRequestHandler handler) throws IOException;
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestHandler.java?rev=738194&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestHandler.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ComponentRequestHandler.java Tue Jan 27 19:21:32 2009
@@ -0,0 +1,47 @@
+// Copyright 2009 Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.services;
+
+import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
+
+import java.io.IOException;
+
+/**
+ * A facade around {@link org.apache.tapestry5.services.ComponentEventRequestHandler} and {@link
+ * org.apache.tapestry5.services.PageRenderRequestHandler} that allows for simplified filters that cover both types of
+ * requests.
+ *
+ * @since 5.1.0.0
+ */
+@UsesOrderedConfiguration(ComponentRequestFilter.class)
+public interface ComponentRequestHandler
+{
+ /**
+ * Handler for a component action request which will trigger an event on a component and use the return value to
+ * send a response to the client (typically, a redirect to a page render URL).
+ *
+ * @param parameters defining the requst
+ */
+ void handleComponentEvent(ComponentEventRequestParameters parameters) throws IOException;
+
+ /**
+ * Invoked to activate and render a page. In certain cases, based on values returned when activating the page, a
+ * {@link org.apache.tapestry5.services.ComponentEventResultProcessor} may be used to send an alternate response
+ * (typically, a redirect).
+ *
+ * @param parameters defines the page name and activation context
+ */
+ void handlePageRender(PageRenderRequestParameters parameters) throws IOException;
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=738194&r1=738193&r2=738194&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Tue Jan 27 19:21:32 2009
@@ -143,6 +143,105 @@
this.endOfRequestEventHub = endOfRequestEventHub;
}
+ // A bunch of classes "promoted" from inline inner class to nested classes,
+ // just so that the stack trace would be more readable. Most of these
+ // are teminators for pipeline services.
+
+ /**
+ * @since 5.1.0.0
+ */
+ private class ApplicationInitializerTerminator implements ApplicationInitializer
+ {
+ public void initializeApplication(Context context)
+ {
+ applicationGlobals.storeContext(context);
+ }
+ }
+
+ /**
+ * @since 5.1.0.0
+ */
+ private class HttpServletRequestHandlerTerminator implements HttpServletRequestHandler
+ {
+ private final RequestHandler handler;
+ private final String applicationCharset;
+ private final SessionPersistedObjectAnalyzer analyzer;
+
+ public HttpServletRequestHandlerTerminator(RequestHandler handler, String applicationCharset,
+ SessionPersistedObjectAnalyzer analyzer)
+ {
+ this.handler = handler;
+ this.applicationCharset = applicationCharset;
+ this.analyzer = analyzer;
+ }
+
+ public boolean service(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
+ throws IOException
+ {
+ requestGlobals.storeServletRequestResponse(servletRequest, servletResponse);
+
+ Request request = new RequestImpl(servletRequest, applicationCharset, analyzer);
+ Response response = new ResponseImpl(servletResponse);
+
+ // TAP5-257: Make sure that the "initial guess" for request/response is available, even if
+ // some filter in the RequestHandler pipeline replaces them.
+
+ requestGlobals.storeRequestResponse(request, response);
+
+ // Transition from the Servlet API-based pipeline, to the Tapestry-based pipeline.
+
+ return handler.service(request, response);
+ }
+ }
+
+ /**
+ * @since 5.1.0.0
+ */
+ private class ServletApplicationInitializerTerminator implements ServletApplicationInitializer
+ {
+ private final ApplicationInitializer initializer;
+
+ public ServletApplicationInitializerTerminator(ApplicationInitializer initializer)
+ {
+ this.initializer = initializer;
+ }
+
+ public void initializeApplication(ServletContext servletContext)
+ {
+ applicationGlobals.storeServletContext(servletContext);
+
+ // And now, down the (Web) ApplicationInitializer pipeline ...
+
+ ContextImpl context = new ContextImpl(servletContext);
+
+ applicationGlobals.storeContext(context);
+
+ initializer.initializeApplication(context);
+ }
+ }
+
+ /**
+ * @since 5.1.0.0
+ */
+ private class RequestHandlerTerminator implements RequestHandler
+ {
+ private final Dispatcher masterDispatcher;
+
+ public RequestHandlerTerminator(Dispatcher masterDispatcher)
+ {
+ this.masterDispatcher = masterDispatcher;
+ }
+
+ public boolean service(Request request, Response response) throws IOException
+ {
+ // Update RequestGlobals with the current request/response (in case some filter replaced the
+ // normal set).
+ requestGlobals.storeRequestResponse(request, response);
+
+ return masterDispatcher.dispatch(request, response);
+ }
+ }
+
public static void bind(ServiceBinder binder)
{
binder.bind(ClasspathAssetAliasManager.class, ClasspathAssetAliasManagerImpl.class);
@@ -1004,13 +1103,7 @@
public ApplicationInitializer buildApplicationInitializer(Logger logger,
List<ApplicationInitializerFilter> configuration)
{
- ApplicationInitializer terminator = new ApplicationInitializer()
- {
- public void initializeApplication(Context context)
- {
- applicationGlobals.storeContext(context);
- }
- };
+ ApplicationInitializer terminator = new ApplicationInitializerTerminator();
return pipelineBuilder.build(logger, ApplicationInitializer.class, ApplicationInitializerFilter.class,
configuration, terminator);
@@ -1021,34 +1114,16 @@
List<HttpServletRequestFilter> configuration,
@Primary
- final RequestHandler handler,
+ RequestHandler handler,
@Inject @Symbol(SymbolConstants.CHARSET)
- final String applicationCharset,
+ String applicationCharset,
@Primary
- final SessionPersistedObjectAnalyzer analyzer)
+ SessionPersistedObjectAnalyzer analyzer)
{
- HttpServletRequestHandler terminator = new HttpServletRequestHandler()
- {
- public boolean service(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
- throws IOException
- {
- requestGlobals.storeServletRequestResponse(servletRequest, servletResponse);
-
- Request request = new RequestImpl(servletRequest, applicationCharset, analyzer);
- Response response = new ResponseImpl(servletResponse);
-
- // TAP5-257: Make sure that the "initial guess" for request/response is available, even if
- // some filter in the RequestHandler pipeline replaces them.
-
- requestGlobals.storeRequestResponse(request, response);
-
- // Transition from the Servlet API-based pipeline, to the Tapestry-based pipeline.
-
- return handler.service(request, response);
- }
- };
+ HttpServletRequestHandler terminator = new HttpServletRequestHandlerTerminator(handler, applicationCharset,
+ analyzer);
return pipelineBuilder.build(logger, HttpServletRequestHandler.class, HttpServletRequestFilter.class,
configuration, terminator);
@@ -1058,19 +1133,9 @@
public RequestHandler buildRequestHandler(Logger logger, List<RequestFilter> configuration,
@Primary
- final Dispatcher masterDispatcher)
+ Dispatcher masterDispatcher)
{
- RequestHandler terminator = new RequestHandler()
- {
- public boolean service(Request request, Response response) throws IOException
- {
- // Update RequestGlobals with the current request/response (in case some filter replaced the
- // normal set).
- requestGlobals.storeRequestResponse(request, response);
-
- return masterDispatcher.dispatch(request, response);
- }
- };
+ RequestHandler terminator = new RequestHandlerTerminator(masterDispatcher);
return pipelineBuilder.build(logger, RequestHandler.class, RequestFilter.class, configuration, terminator);
}
@@ -1079,23 +1144,9 @@
List<ServletApplicationInitializerFilter> configuration,
@Primary
- final ApplicationInitializer initializer)
+ ApplicationInitializer initializer)
{
- ServletApplicationInitializer terminator = new ServletApplicationInitializer()
- {
- public void initializeApplication(ServletContext servletContext)
- {
- applicationGlobals.storeServletContext(servletContext);
-
- // And now, down the (Web) ApplicationInitializer pipeline ...
-
- ContextImpl context = new ContextImpl(servletContext);
-
- applicationGlobals.storeContext(context);
-
- initializer.initializeApplication(context);
- }
- };
+ ServletApplicationInitializer terminator = new ServletApplicationInitializerTerminator(initializer);
return pipelineBuilder.build(logger, ServletApplicationInitializer.class,
ServletApplicationInitializerFilter.class, configuration, terminator);
@@ -1233,23 +1284,11 @@
/**
* The MarkupRenderer service is used to render a full page as markup. Supports an ordered configuration of {@link
* org.apache.tapestry5.services.MarkupRendererFilter}s.
- *
- * @param pageRenderQueue handles the bulk of the work
- * @param logger used to log errors building the pipeline
- * @param configuration filters on this service
- * @return the service
*/
- public MarkupRenderer buildMarkupRenderer(final PageRenderQueue pageRenderQueue, Logger logger,
+ public MarkupRenderer buildMarkupRenderer(Logger logger,
+ @Autobuild MarkupRendererTerminator terminator,
List<MarkupRendererFilter> configuration)
{
- MarkupRenderer terminator = new MarkupRenderer()
- {
- public void renderMarkup(MarkupWriter writer)
- {
- pageRenderQueue.render(writer);
- }
- };
-
return pipelineBuilder.build(logger, MarkupRenderer.class, MarkupRendererFilter.class, configuration,
terminator);
}
@@ -1258,26 +1297,14 @@
* A wrapper around {@link org.apache.tapestry5.internal.services.PageRenderQueue} used for partial page renders.
* Supports an ordered configuration of {@link org.apache.tapestry5.services.PartialMarkupRendererFilter}s.
*
- * @param logger used to log warnings creating the pipeline
- * @param configuration filters for the service
- * @param renderQueue does most of the work
- * @return the service
* @see #contributePartialMarkupRenderer(org.apache.tapestry5.ioc.OrderedConfiguration, org.apache.tapestry5.Asset,
* org.apache.tapestry5.ioc.services.SymbolSource, AssetSource, ValidationMessagesSource)
*/
public PartialMarkupRenderer buildPartialMarkupRenderer(Logger logger,
List<PartialMarkupRendererFilter> configuration,
- final PageRenderQueue renderQueue)
+ @Autobuild PartialMarkupRendererTerminator terminator)
{
- PartialMarkupRenderer terminator = new PartialMarkupRenderer()
- {
- public void renderMarkup(MarkupWriter writer, JSONObject reply)
- {
- renderQueue.renderPartial(writer, reply);
- }
- };
-
return pipelineBuilder.build(logger, PartialMarkupRenderer.class, PartialMarkupRendererFilter.class,
configuration, terminator);
}
@@ -2197,6 +2224,8 @@
/**
* Advises the {@link org.apache.tapestry5.internal.services.ComponentMessagesSource} service so that the creation
* of {@link org.apache.tapestry5.ioc.Messages} instances can be deferred.
+ *
+ * @since 5.1.0.0
*/
@Match("ComponentMessagesSource")
public static void adviseLazy(LazyAdvisor advisor, MethodAdviceReceiver receiver)
@@ -2204,4 +2233,19 @@
advisor.addLazyMethodInvocationAdvice(receiver);
}
+ /**
+ * @since 5.1.0.0
+ */
+ public ComponentRequestHandler buildComponentRequestHandler(
+ List<ComponentRequestFilter> configuration,
+
+ @Autobuild ComponentRequestHandlerTerminator terminator,
+
+ Logger logger)
+ {
+ return pipelineBuilder.build(logger, ComponentRequestHandler.class, ComponentRequestFilter.class,
+ configuration, terminator);
+ }
+
+
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java?rev=738194&r1=738193&r2=738194&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java Tue Jan 27 19:21:32 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -1190,4 +1190,14 @@
{
expect(session.isInvalidated()).andReturn(invalidated);
}
+
+ protected final ComponentEventRequestHandler mockComponentEventRequestHandler()
+ {
+ return newMock(ComponentEventRequestHandler.class);
+ }
+
+ protected final ComponentRequestHandler mockComponentRequestHandler()
+ {
+ return newMock(ComponentRequestHandler.class);
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventDispatcherTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventDispatcherTest.java?rev=738194&r1=738193&r2=738194&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventDispatcherTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventDispatcherTest.java Tue Jan 27 19:21:32 2009
@@ -41,7 +41,6 @@
@Test
public void no_dot_or_colon_in_path() throws Exception
{
- ComponentEventRequestHandler handler = newComponentEventRequestHandler();
Request request = mockRequest();
Response response = mockResponse();
@@ -49,18 +48,13 @@
replay();
- Dispatcher dispatcher = new ComponentEventDispatcher(handler, null, null, null);
+ Dispatcher dispatcher = new ComponentEventDispatcher(null, null, null, null);
assertFalse(dispatcher.dispatch(request, response));
verify();
}
- protected final ComponentEventRequestHandler newComponentEventRequestHandler()
- {
- return newMock(ComponentEventRequestHandler.class);
- }
-
@Test
public void event_on_page() throws Exception
{
@@ -131,7 +125,7 @@
@Test
public void page_activation_context_in_request() throws Exception
{
- ComponentEventRequestHandler handler = newComponentEventRequestHandler();
+ ComponentRequestHandler handler = mockComponentRequestHandler();
Request request = mockRequest();
Response response = mockResponse();
ComponentClassResolver resolver = mockComponentClassResolver();
@@ -143,7 +137,7 @@
contextValueEncoder,
new String[] {
"alpha",
- "beta"}),
+ "beta" }),
new EmptyEventContext());
train_getPath(request, "/mypage:eventname");
@@ -156,11 +150,11 @@
train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
- handler.handle(expectedParameters);
+ handler.handleComponentEvent(expectedParameters);
replay();
- Dispatcher dispatcher = new ComponentEventDispatcher(handler, resolver, contextPathEncoder, ls);
+ Dispatcher dispatcher = new ComponentEventDispatcher(resolver, contextPathEncoder, ls, handler);
assertTrue(dispatcher.dispatch(request, response));
@@ -170,7 +164,7 @@
@Test
public void different_active_and_containing_pages() throws Exception
{
- ComponentEventRequestHandler handler = newComponentEventRequestHandler();
+ ComponentRequestHandler handler = mockComponentRequestHandler();
Request request = mockRequest();
Response response = mockResponse();
ComponentClassResolver resolver = mockComponentClassResolver();
@@ -191,11 +185,11 @@
train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, "mypage");
- handler.handle(expectedParameters);
+ handler.handleComponentEvent(expectedParameters);
replay();
- Dispatcher dispatcher = new ComponentEventDispatcher(handler, resolver, contextPathEncoder, ls);
+ Dispatcher dispatcher = new ComponentEventDispatcher(resolver, contextPathEncoder, ls, handler);
assertTrue(dispatcher.dispatch(request, response));
@@ -205,7 +199,6 @@
@Test
public void request_path_reference_non_existent_page() throws Exception
{
- ComponentEventRequestHandler handler = newComponentEventRequestHandler();
Request request = mockRequest();
Response response = mockResponse();
ComponentClassResolver resolver = mockComponentClassResolver();
@@ -218,7 +211,7 @@
replay();
- Dispatcher dispatcher = new ComponentEventDispatcher(handler, resolver, null, ls);
+ Dispatcher dispatcher = new ComponentEventDispatcher(resolver, null, ls, null);
assertFalse(dispatcher.dispatch(request, response));
@@ -229,7 +222,7 @@
String eventType,
String... eventContext) throws IOException
{
- ComponentEventRequestHandler handler = newComponentEventRequestHandler();
+ ComponentRequestHandler handler = mockComponentRequestHandler();
Request request = mockRequest();
Response response = mockResponse();
ComponentClassResolver resolver = mockComponentClassResolver();
@@ -254,11 +247,12 @@
train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
- handler.handle(expectedParameters);
+ handler.handleComponentEvent(expectedParameters);
replay();
- Dispatcher dispatcher = new ComponentEventDispatcher(handler, resolver, contextPathEncoder, localizationSetter);
+ Dispatcher dispatcher = new ComponentEventDispatcher(resolver, contextPathEncoder, localizationSetter,
+ handler);
assertTrue(dispatcher.dispatch(request, response));
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageRenderDispatcherTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageRenderDispatcherTest.java?rev=738194&r1=738193&r2=738194&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageRenderDispatcherTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PageRenderDispatcherTest.java Tue Jan 27 19:21:32 2009
@@ -42,8 +42,6 @@
public void not_a_page_request() throws Exception
{
ComponentClassResolver resolver = mockComponentClassResolver();
- RequestPageCache cache = mockRequestPageCache();
- PageRenderRequestHandler handler = new PageRenderRequestHandlerImpl(cache, null, null);
Request request = mockRequest();
Response response = mockResponse();
LocalizationSetter ls = mockLocalizationSetter();
@@ -55,7 +53,7 @@
replay();
- Dispatcher d = new PageRenderDispatcher(resolver, handler, contextPathEncoder, ls);
+ Dispatcher d = new PageRenderDispatcher(resolver, contextPathEncoder, ls, null);
assertFalse(d.dispatch(request, response));
@@ -67,7 +65,6 @@
public void empty_path() throws Exception
{
ComponentClassResolver resolver = mockComponentClassResolver();
- PageRenderRequestHandler handler = newMock(PageRenderRequestHandler.class);
Request request = mockRequest();
Response response = mockResponse();
LocalizationSetter ls = mockLocalizationSetter();
@@ -80,7 +77,7 @@
replay();
- Dispatcher d = new PageRenderDispatcher(resolver, handler, contextPathEncoder, ls);
+ Dispatcher d = new PageRenderDispatcher(resolver, contextPathEncoder, ls, null);
assertFalse(d.dispatch(request, response));
@@ -91,7 +88,6 @@
public void just_the_locale_name() throws Exception
{
ComponentClassResolver resolver = mockComponentClassResolver();
- PageRenderRequestHandler handler = newMock(PageRenderRequestHandler.class);
Request request = mockRequest();
Response response = mockResponse();
LocalizationSetter ls = mockLocalizationSetter();
@@ -104,7 +100,7 @@
replay();
- Dispatcher d = new PageRenderDispatcher(resolver, handler, contextPathEncoder, ls);
+ Dispatcher d = new PageRenderDispatcher(resolver, contextPathEncoder, ls, null);
assertFalse(d.dispatch(request, response));
@@ -139,15 +135,13 @@
train_getRootElement(page, rootElement);
- train_triggerContextEvent(rootElement, EventConstants.ACTIVATE, new Object[] {"foo", "bar"}, false);
+ train_triggerContextEvent(rootElement, EventConstants.ACTIVATE, new Object[] { "foo", "bar" }, false);
renderer.renderPageResponse(page);
replay();
- PageRenderRequestHandler handler = new PageRenderRequestHandlerImpl(cache, processor, renderer);
-
- Dispatcher d = new PageRenderDispatcher(resolver, handler, contextPathEncoder, ls);
+ Dispatcher d = new PageRenderDispatcher(resolver, contextPathEncoder, ls, wrap(cache, processor, renderer));
assertTrue(d.dispatch(request, response));
@@ -195,9 +189,7 @@
replay();
- PageRenderRequestHandler handler = new PageRenderRequestHandlerImpl(cache, processor, renderer);
-
- Dispatcher d = new PageRenderDispatcher(resolver, handler, contextPathEncoder, ls);
+ Dispatcher d = new PageRenderDispatcher(resolver, contextPathEncoder, ls, wrap(cache, processor, renderer));
assertTrue(d.dispatch(request, response));
@@ -242,21 +234,27 @@
train_get(cache, "foo/Bar", page);
train_getRootElement(page, rootElement);
- train_triggerContextEvent(rootElement, EventConstants.ACTIVATE, new Object[] {"zip", "zoom"}, false);
+ train_triggerContextEvent(rootElement, EventConstants.ACTIVATE, new Object[] { "zip", "zoom" }, false);
renderer.renderPageResponse(page);
replay();
- PageRenderRequestHandler handler = new PageRenderRequestHandlerImpl(cache, processor, renderer);
-
- Dispatcher d = new PageRenderDispatcher(resolver, handler, contextPathEncoder, ls);
+ Dispatcher d = new PageRenderDispatcher(resolver, contextPathEncoder, ls, wrap(cache, processor, renderer));
assertTrue(d.dispatch(request, response));
verify();
}
+ private ComponentRequestHandler wrap(RequestPageCache cache, ComponentEventResultProcessor processor,
+ PageResponseRenderer renderer)
+ {
+ PageRenderRequestHandler prh = new PageRenderRequestHandlerImpl(cache, processor, renderer);
+
+ return new ComponentRequestHandlerTerminator(null, prh);
+ }
+
protected ComponentEventResultProcessor newComponentEventResultProcessor()
{
return newMock(ComponentEventResultProcessor.class);