You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2007/10/05 15:32:12 UTC
svn commit: r582255 -
/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterFacesContextFactory.java
Author: skitching
Date: Fri Oct 5 06:32:11 2007
New Revision: 582255
URL: http://svn.apache.org/viewvc?rev=582255&view=rev
Log:
Set a second (different) request flag when the response has been internally wrapped; the RequestParameterProviderManager
does need to be reassured that the response wrapping has occurred when no servletfilter is present. Also update
comments/docs.
Modified:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterFacesContextFactory.java
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterFacesContextFactory.java?rev=582255&r1=582254&r2=582255&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterFacesContextFactory.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterFacesContextFactory.java Fri Oct 5 06:32:11 2007
@@ -29,14 +29,16 @@
import javax.servlet.http.HttpServletResponse;
/**
- * <p/>
- * This factory wraps each {@link javax.servlet.http.HttpServletResponse} in a {@link org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterResponseWrapper},
- * meaning that every call to response.encodeURL() gets forwarded to the RequestParameterProviderManager.
- * </p>
- * <p/>
+ * Ensure that a custom wrapper is put aroung the HttpServletResponse so that encodeURL can be
+ * intercepted and modified.
+ * <p>
+ * There is a servlet filter (RequestParameterServletFilter) that does this in the obvious way, but
+ * it is a nuisance to have to set up filters in the web.xml. This class implements a sneaky hack
+ * to get this to happen automatically for JSF applications, ie no servlet filter is needed when
+ * this is specified in the faces-config.xml file as the FacesContextFactory.
+ * <p>
* If you have to deal with a mixed environment e.g. JSP/JSF it would be better to use the
- * {@link org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterServletFilter}
- * </p>
+ * {@link org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterServletFilter}.
*/
public class RequestParameterFacesContextFactory extends FacesContextFactory
{
@@ -52,18 +54,27 @@
if (response instanceof HttpServletResponse)
{
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+
+ // Wrap this request only if something else (eg a RequestParameterServletFilter) has not already wrapped it.
if (!Boolean.TRUE.equals(httpServletRequest.getAttribute(RequestParameterServletFilter.REQUEST_PARAM_FILTER_CALLED)))
{
- // We do not set the filter_called flag anymore. This is intentional.
- // Reason: If you create your own FacesContext outside of JSF this method might be called more than once.
- // First for your own FacesContext and second for the FacesContext created by JSF.
- // On the second call this flag was set and we didn't wrapped the response stream as required.
- // So, this flag should just be used to see if the RequestParameterServletFilter has been configured.
- // If so, do not wrap, else, wrap every time a new FacesContext is going to be created.
- // The response object passed in will always be an unwrapped (in the meaning of RPRW) one.
- // httpServletRequest.setAttribute(RequestParameterServletFilter.REQUEST_PARAM_FILTER_CALLED, Boolean.TRUE);
-
+ // No servlet filter has wrapped the response, so do it now for the response referenced by this FacesContext.
+ // Note that this wrapper will therefore apply to all output generated via the FacesContext, but not to
+ // anything that might be written by filters etc.
response = new RequestParameterResponseWrapper((HttpServletResponse) response);
+
+ // We now need to reassure the RequestParameterProviderManager that the response has indeed been
+ // wrapped; it checks and reports an error if not as it is easy to stuff up this configuration.
+ //
+ // However we can not just set the REQUEST_PARAMETER_FILTER_CALLED flag here. If code creates its own
+ // FacesContext instance for any reason while a request is running, then this method is called again.
+ // On the second call this flag would already be set and the response would not be wrapped as required.
+ //
+ // Therefore we have two separate flags; RequestParameterProviderManager checks whether either
+ // REQUEST_PARAM_FILTER_CALLED or REQUEST_PARAM_RESPONSE_WRAPPED has been set.
+
+ httpServletRequest.setAttribute(RequestParameterServletFilter.REQUEST_PARAM_RESPONSE_WRAPPED, Boolean.TRUE);
+
}
}