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 2005/03/08 17:30:10 UTC
cvs commit: jakarta-tapestry/framework/src/java/org/apache/tapestry/engine AbstractEngine.java
hlship 2005/03/08 08:30:10
Modified: framework/src/java/org/apache/tapestry/services/impl
ImplStrings.properties InfrastructureImpl.java
ImplMessages.java
framework/src/descriptor/META-INF tapestry.request.xml
framework/src/java/org/apache/tapestry/services
WebRequestServicerFilter.java Infrastructure.java
framework/src/java/org/apache/tapestry/engine
AbstractEngine.java
Added: framework/src/java/org/apache/tapestry/services/impl
DisableCachingFilter.java
framework/src/test/org/apache/tapestry/services/impl
TestDisableCachingFilter.java
Log:
Move disable caching logic out of AbstractEngine and into a WebRequestServicerPipeline filter (that is conditionally contributed).
Revision Changes Path
1.11 +1 -0 jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ImplStrings.properties
Index: ImplStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ImplStrings.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ImplStrings.properties 8 Mar 2005 15:36:35 -0000 1.10
+++ ImplStrings.properties 8 Mar 2005 16:30:10 -0000 1.11
@@ -51,3 +51,4 @@
namespace-property-source-description=<PropertySource for namespace {0}>
invalid-encoding=Unable to set request character encoding to ''{0}'': {1}
+error-resetting=Error resetting cached data at end of request: {0}
\ No newline at end of file
1.23 +6 -0 jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java
Index: InfrastructureImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- InfrastructureImpl.java 28 Feb 2005 16:25:38 -0000 1.22
+++ InfrastructureImpl.java 8 Mar 2005 16:30:10 -0000 1.23
@@ -344,4 +344,10 @@
{
_threadLocale = threadLocale;
}
+
+ public String getOutputEncoding()
+ {
+ return _applicationPropertySource.getPropertyValue("org.apache.tapestry.output-encoding");
+ }
+
}
\ No newline at end of file
1.12 +5 -1 jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ImplMessages.java
Index: ImplMessages.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ImplMessages.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ImplMessages.java 8 Mar 2005 15:36:35 -0000 1.11
+++ ImplMessages.java 8 Mar 2005 16:30:10 -0000 1.12
@@ -14,7 +14,6 @@
package org.apache.tapestry.services.impl;
-import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
@@ -218,4 +217,9 @@
{
return _formatter.format("invalid-encoding", encoding, cause);
}
+
+ public static String errorResetting(Throwable cause)
+ {
+ return _formatter.format("error-resetting", cause);
+ }
}
\ No newline at end of file
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/DisableCachingFilter.java
Index: DisableCachingFilter.java
===================================================================
// Copyright 2005 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.
// 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.tapestry.services.impl;
import java.io.IOException;
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.HiveMind;
import org.apache.tapestry.services.ResetEventCoordinator;
import org.apache.tapestry.services.WebRequestServicer;
import org.apache.tapestry.services.WebRequestServicerFilter;
import org.apache.tapestry.web.WebRequest;
import org.apache.tapestry.web.WebResponse;
/**
* Filter whose job is to invoke
* {@link org.apache.tapestry.services.ResetEventCoordinator#fireResetEvent()}after the request has
* been processed. This filter is only contributed into the
* tapestry.request.WebRequestServicerPipeline configuration if the
* org.apache.tapestry.disable-caching system property is true.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class DisableCachingFilter implements WebRequestServicerFilter
{
private ErrorLog _errorLog;
private ResetEventCoordinator _resetEventCoordinator;
public void service(WebRequest request, WebResponse response, WebRequestServicer servicer)
throws IOException
{
try
{
servicer.service(request, response);
}
finally
{
fireResetEvent();
}
}
private void fireResetEvent()
{
try
{
_resetEventCoordinator.fireResetEvent();
}
catch (Exception ex)
{
_errorLog.error(ImplMessages.errorResetting(ex), HiveMind.getLocation(ex), ex);
}
}
public void setResetEventCoordinator(ResetEventCoordinator resetEventCoordinator)
{
_resetEventCoordinator = resetEventCoordinator;
}
public void setErrorLog(ErrorLog errorLog)
{
_errorLog = errorLog;
}
}
1.19 +17 -0 jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.request.xml
Index: tapestry.request.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.request.xml,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- tapestry.request.xml 8 Mar 2005 15:51:43 -0000 1.18
+++ tapestry.request.xml 8 Mar 2005 16:30:10 -0000 1.19
@@ -217,4 +217,21 @@
</construct>
</invoke-factory>
</service-point>
+
+ <service-point id="DisableCachingFilter" interface="WebRequestServicerFilter">
+
+ Uses the ResetEventCoordinator to reset any cached data at the end of the request.
+ Only used during development, not in production.
+
+ <invoke-factory>
+ <construct class="impl.DisableCachingFilter">
+ <set-object property="resetEventCoordinator" value="infrastructure:resetEventCoordinator"/>
+ </construct>
+ </invoke-factory>
+ </service-point>
+
+ <contribution configuration-id="WebRequestServicerPipeline" if="property org.apache.tapestry.disable-caching">
+ <filter name="DisableCachingFilter" object="service:DisableCachingFilter"/>
+ </contribution>
+
</module>
\ No newline at end of file
1.1 jakarta-tapestry/framework/src/test/org/apache/tapestry/services/impl/TestDisableCachingFilter.java
Index: TestDisableCachingFilter.java
===================================================================
// Copyright 2005 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.
// 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.tapestry.services.impl;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.Location;
import org.apache.hivemind.test.HiveMindTestCase;
import org.apache.tapestry.services.ResetEventCoordinator;
import org.apache.tapestry.services.WebRequestServicer;
import org.apache.tapestry.web.WebRequest;
import org.apache.tapestry.web.WebResponse;
import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.services.impl.DisableCachingFilter}.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class TestDisableCachingFilter extends HiveMindTestCase
{
private WebRequest newRequest()
{
return (WebRequest) newMock(WebRequest.class);
}
private WebResponse newResponse()
{
return (WebResponse) newMock(WebResponse.class);
}
private WebRequestServicer newServicer()
{
return (WebRequestServicer) newMock(WebRequestServicer.class);
}
private ResetEventCoordinator newREC()
{
return (ResetEventCoordinator) newMock(ResetEventCoordinator.class);
}
public void testNormal() throws Exception
{
WebRequest request = newRequest();
WebResponse response = newResponse();
WebRequestServicer servicer = newServicer();
ResetEventCoordinator rec = newREC();
servicer.service(request, response);
rec.fireResetEvent();
replayControls();
DisableCachingFilter f = new DisableCachingFilter();
f.setResetEventCoordinator(rec);
f.service(request, response, servicer);
verifyControls();
}
public void testResetFailure() throws Exception
{
WebRequest request = newRequest();
WebResponse response = newResponse();
WebRequestServicer servicer = newServicer();
MockControl control = newControl(ResetEventCoordinator.class);
ResetEventCoordinator rec = (ResetEventCoordinator) control.getMock();
ErrorLog log = (ErrorLog) newMock(ErrorLog.class);
Location l = fabricateLocation(99);
Throwable t = new ApplicationRuntimeException("Mock failure.", l, null);
servicer.service(request, response);
rec.fireResetEvent();
control.setThrowable(t);
log.error(ImplMessages.errorResetting(t), l, t);
replayControls();
DisableCachingFilter f = new DisableCachingFilter();
f.setResetEventCoordinator(rec);
f.setErrorLog(log);
f.service(request, response, servicer);
verifyControls();
}
}
1.2 +4 -1 jakarta-tapestry/framework/src/java/org/apache/tapestry/services/WebRequestServicerFilter.java
Index: WebRequestServicerFilter.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/WebRequestServicerFilter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebRequestServicerFilter.java 8 Mar 2005 15:36:34 -0000 1.1
+++ WebRequestServicerFilter.java 8 Mar 2005 16:30:10 -0000 1.2
@@ -14,6 +14,8 @@
package org.apache.tapestry.services;
+import java.io.IOException;
+
import org.apache.tapestry.web.WebRequest;
import org.apache.tapestry.web.WebResponse;
@@ -25,5 +27,6 @@
*/
public interface WebRequestServicerFilter
{
- public void service(WebRequest request, WebResponse response, WebRequestServicer service);
+ public void service(WebRequest request, WebResponse response, WebRequestServicer servicer)
+ throws IOException;
}
\ No newline at end of file
1.22 +2 -0 jakarta-tapestry/framework/src/java/org/apache/tapestry/services/Infrastructure.java
Index: Infrastructure.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/Infrastructure.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Infrastructure.java 28 Feb 2005 16:25:38 -0000 1.21
+++ Infrastructure.java 8 Mar 2005 16:30:10 -0000 1.22
@@ -204,4 +204,6 @@
*/
public void setLocale(Locale value);
+
+ public String getOutputEncoding();
}
\ No newline at end of file
1.23 +4 -81 jakarta-tapestry/framework/src/java/org/apache/tapestry/engine/AbstractEngine.java
Index: AbstractEngine.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/engine/AbstractEngine.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- AbstractEngine.java 8 Mar 2005 15:51:44 -0000 1.22
+++ AbstractEngine.java 8 Mar 2005 16:30:10 -0000 1.23
@@ -15,7 +15,6 @@
package org.apache.tapestry.engine;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -24,7 +23,6 @@
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
@@ -112,24 +110,6 @@
private ListenerMap _listeners;
/**
- * The name of the application property that will be used to determine the encoding to use when
- * generating the output
- *
- * @since 3.0
- */
-
- public static final String OUTPUT_ENCODING_PROPERTY_NAME = "org.apache.tapestry.output-encoding";
-
- /**
- * The default encoding that will be used when generating the output. It is used if no output
- * encoding property has been specified.
- *
- * @since 3.0
- */
-
- public static final String DEFAULT_OUTPUT_ENCODING = "UTF-8";
-
- /**
* The curent locale for the engine, which may be changed at any time.
*/
@@ -143,22 +123,6 @@
public static final String VISIT_CLASS_PROPERTY_NAME = "org.apache.tapestry.visit-class";
/**
- * If true (set from the JVM system parameter <code>org.apache.tapestry.disable-caching</code>)
- * then the cache of pages, specifications and template will be cleared after each request.
- */
-
- private static final boolean _disableCaching = Boolean
- .getBoolean("org.apache.tapestry.disable-caching");
-
- /**
- * The instance of {@link IMonitorFactory}used to create a monitor.
- *
- * @since 3.0
- */
-
- private IMonitorFactory _monitorFactory;
-
- /**
* Sets the Exception page's exception property, then renders the Exception page.
* <p>
* If the render throws an exception, then copious output is sent to <code>System.err</code>
@@ -385,26 +349,11 @@
if (output != null)
output.forceFlush();
- cleanupAfterRequest(cycle);
}
catch (Exception ex)
{
reportException(Tapestry.getMessage("AbstractEngine.exception-during-cleanup"), ex);
}
-
- if (_disableCaching)
- {
- try
- {
- _infrastructure.getResetEventCoordinator().fireResetEvent();
- }
- catch (Exception ex)
- {
- reportException(Tapestry
- .getMessage("AbstractEngine.exception-during-cache-clear"), ex);
- }
- }
-
}
}
@@ -696,40 +645,14 @@
return TapestryConstants.STALE_SESSION_PAGE;
}
- /**
- * The encoding to be used if none has been defined using the output encoding property. Override
- * this method to change the default.
- *
- * @return the default output encoding
- * @since 3.0
- */
- protected String getDefaultOutputEncoding()
+ /** @since 3.1 */
+ public Infrastructure getInfrastructure()
{
- return DEFAULT_OUTPUT_ENCODING;
+ return _infrastructure;
}
- /**
- * Returns the encoding to be used to generate the servlet responses and accept the servlet
- * requests. The encoding is defined using the org.apache.tapestry.output-encoding and is UTF-8
- * by default
- *
- * @since 3.0
- * @see org.apache.tapestry.IEngine#getOutputEncoding()
- */
public String getOutputEncoding()
{
- IPropertySource source = getPropertySource();
-
- String encoding = source.getPropertyValue(OUTPUT_ENCODING_PROPERTY_NAME);
- if (encoding == null)
- encoding = getDefaultOutputEncoding();
-
- return encoding;
- }
-
- /** @since 3.1 */
- public Infrastructure getInfrastructure()
- {
- return _infrastructure;
+ return _infrastructure.getOutputEncoding();
}
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org