myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r581845 - in /myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra: conversation/jsf/filter/ filter/ frameworkAdapter/ frameworkAdapter/jsf/ lib/
Date Thu, 04 Oct 2007 10:55:19 GMT
Author: skitching
Date: Thu Oct  4 03:55:18 2007
New Revision: 581845

URL: http://svn.apache.org/viewvc?rev=581845&view=rev
Log:
Alter implementations of orchestra-provided servlet filters. This makes the following incompatible
changes:

1. Class frameworkAdapter/FrameworkAdapterServletFilter no longer exists. It is replaced by
frameworkAdapter/jsf/JsfFrameworkAdapterFilter.

2. Class conversation.jsf.OrchestraServletFilter no longer has a servlet config param to choose
the framework; it
always chooses jsf (as the package name indicates).

There are some other API changes, but nothing that is likely to affect users. 

Added:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/filter/
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/filter/OrchestraServletFilter.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapterFilter.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/CompoundFilter.java
Removed:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapterServletFilter.java
Modified:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapter.java

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java?rev=581845&r1=581844&r2=581845&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java
(original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java
Thu Oct  4 03:55:18 2007
@@ -19,163 +19,21 @@
 
 package org.apache.myfaces.orchestra.conversation.jsf.filter;
 
-import org.apache.myfaces.orchestra.connectionManager.ConnectionManagerDataSource;
-import org.apache.myfaces.orchestra.conversation.ConversationContext;
-import org.apache.myfaces.orchestra.conversation.ConversationManager;
-import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapterServletFilter;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import java.io.IOException;
+import org.apache.myfaces.orchestra.lib.CompoundFilter;
 
 /**
- * Perform a number of useful per-request tasks.
- * <p>
- * <h2>Configures the orchestra FrameworkAdapter</h2>
- * Orchestra accesses information about the request, response, session, etc via a
- * FrameworkAdapter so that it can be used with multiple web tier frameworks. This
- * class selects the correct adapter to use; the default is the JsfFrameworkAdapter
- * but setting the appropriate servlet context parameter in web.xml allows other
- * adapter classes to be selected.
- * <p>
- * <h2>Make request/response objects accessible</h2>
- * The request and response objects for the current request are stored in thread-local
- * variables for the duration of this request. This makes it possible for any code to
- * retrieve them via static methods on this class. This is required by at least
- * the JsfFrameworkAdapter class, ie required when using Orchestra with JSF.
- * <p>
- * <h2>Request Synchronization</h2>
- * It is possible for multiple requests associated with the same http session to be
- * received concurrently. In particular, ajax pages can cause this.
- * <p> 
- * By default, the servlet engine simply processes all requests concurrently
- * in different threads. However that can cause all sorts of unexpected problems with 
- * session-scoped objects.
- * <p>
- * The usual solution is to apply a filter to all requests which uses standard java
- * synchronisation on a session-scoped object, taking the lock on request entry and
- * releasing it on request exit. This ensures that only one request for that session
- * runs at a time, with the others waiting until they can obtain a lock on the
- * appropriate object.
+ * Provides the functionality of two useful orchestra filters together as one, reducing the
+ * amount of web.xml configuration required.
  * <p>
- * When using an Orchestra conversationContext, session-scoped data should be avoided and
- * conversation-scoped beans used instead. If there is no session-scoped data in use by
- * an application then it is possible to allow concurrent requests to the same http session,
- * but NOT concurrent access to the same orchestra conversationContext. This filter 
- * implements that, by holding a lock on a mutex object held by the appropriate
- * conversationContext.
- * <p>
- * The serialize-requests functionality can be enabled or disabled via a filter init
- * parameter; setting "serializeRequests" to "false" disables this filter. Default
- * value: true (enabled).
- * <p>
- * <h2>JDBC Connection Management</h2>
- * Orchestra provides a special DataSource wrapper that can be configured for any
- * datasource used by the application. The datasource simply wraps all real Connection
- * objects it returns in a proxy, and keeps track of them. Here in this servlet it
- * checks whether all connections borrowed by this thread have been returned, and if
- * not returns the real connection nulls out the connection held by the proxy. See
- * ConnectionManagerDataSource for more details.
+ * @see org.apache.myfaces.orchestra.frameworkAdapter.jsf.JsfFrameworkAdapterFilter
+ * @see org.apache.myfaces.orchestra.filter.OrchestraServletFilter
  */
-public class OrchestraServletFilter implements Filter
+public class OrchestraServletFilter extends CompoundFilter
 {
-	/**
-	 * This filter init property can be set to "true" or "false". Default: "true".
-	 */
-	public final static String SERIALIZE_REQUESTS = "serializeRequests"; // NON-NLS
-
-	/**
-	 * A <i>servlet context</i> property that defines the name of a java class which
maps from
-	 * the orchestra FrameworkAdapterInterface to the actual web tier environment 
-	 * that orchestra is running in. Defaults to the standard orchestra JSF adapter.
-	 * This only needs to be set if Orchestra is being used in a non-JSF environment.
-	 */
-	public final static String FRAMEWORK_ADAPTER_KEY = "org.apache.myfaces.orchestra.FRAMEWORK_ADAPTER_CLASS";
// NON-NLS
-
-	/** The default value for FRAMEWORK_ADAPTER_KEY. */
-	public final static String FRAMEWORK_ADAPTER_DFLT = "org.apache.myfaces.orchestra.frameworkAdapter.jsf.JsfFrameworkAdapter";
// NON-NLS
-
-	/**
-	 * Key of an attribute within the ConversationContext that is used as a lock to serialize
-	 * multiple http requests for the same conversation context.
-	 */
-	private final static String CONTEXT_MUTEXT_OBJECT = OrchestraServletFilter.class.getName()
+ ".SER_MUTEX";
-
-	private boolean serializeRequests = true;
-
-	private final FrameworkAdapterServletFilter frameworkAdapterServletFilter = new FrameworkAdapterServletFilter();
-
-	public void init(FilterConfig filterConfig) throws ServletException
-	{
-		String value = filterConfig.getInitParameter(SERIALIZE_REQUESTS);
-		if ("false".equals(value)) // NON-NLS
-		{
-			serializeRequests = false;
-		}
-
-		frameworkAdapterServletFilter.init(filterConfig);
-	}
-
-	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, final
FilterChain filterChain) throws IOException, ServletException
-	{
-		frameworkAdapterServletFilter.doFilter(servletRequest, servletResponse, new FilterChain()
-		{
-			public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws
IOException, ServletException
-			{
-				try
-				{
-					Object mutex = null;
-					if (serializeRequests)
-					{
-						ConversationManager manager = ConversationManager.getInstance(false);
-						if (manager != null)
-						{
-							ConversationContext conversationContext = manager.getCurrentConversationContext();
-							if (conversationContext != null)
-							{
-								synchronized(conversationContext)
-								{
-									mutex = conversationContext.getAttribute(CONTEXT_MUTEXT_OBJECT);
-									if (mutex == null)
-									{
-										mutex = new Object();
-										conversationContext.setAttribute(CONTEXT_MUTEXT_OBJECT, mutex);
-									}
-								}
-							}
-						}
-					}
-					if (serializeRequests && mutex != null)
-					{
-						synchronized(mutex)
-						{
-							filterChain.doFilter(servletRequest, servletResponse);
-						}
-					}
-					else
-					{
-						filterChain.doFilter(servletRequest, servletResponse);
-					}
-				}
-				finally
-				{
-					cleanupPersistence();
-				}
-			}
-		});
-	}
-
-	protected void cleanupPersistence()
-	{
-		ConnectionManagerDataSource.releaseAllBorrowedConnections();
-	}
-
-	public void destroy()
+	public OrchestraServletFilter()
 	{
-		frameworkAdapterServletFilter.destroy();
+		super(
+			new org.apache.myfaces.orchestra.frameworkAdapter.jsf.JsfFrameworkAdapterFilter(),
+			new org.apache.myfaces.orchestra.filter.OrchestraServletFilter());
 	}
 }

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/filter/OrchestraServletFilter.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/filter/OrchestraServletFilter.java?rev=581845&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/filter/OrchestraServletFilter.java
(added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/filter/OrchestraServletFilter.java
Thu Oct  4 03:55:18 2007
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.myfaces.orchestra.filter;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.myfaces.orchestra.connectionManager.ConnectionManagerDataSource;
+import org.apache.myfaces.orchestra.conversation.ConversationContext;
+import org.apache.myfaces.orchestra.conversation.ConversationManager;
+
+/**
+ * Perform a number of useful per-request tasks.
+ * <p>
+ * This filter is entirely optional; it can be omitted if you do not need any of the
+ * functionality provided here. 
+ * <p>
+ * Note that it is necessary to define a filter that initialises the Orchestra
+ * framework; this can be done either via a standalone filter such as
+ * JsfFrameworkAdapterFilter, or via a filter that combines framework initialisation
+ * with the functionality of this class, such as JsfOrchestraServletFilter.
+ * <p>
+ * <h2>Request Serialization</h2>
+ * It is possible for multiple requests associated with the same http session to be
+ * received concurrently. In particular, ajax pages can cause this.
+ * <p> 
+ * By default, the servlet engine simply processes all requests concurrently
+ * in different threads. However that can cause all sorts of unexpected problems with 
+ * session-scoped objects.
+ * <p>
+ * The usual solution is to apply a filter to all requests which uses standard java
+ * synchronisation on a session-scoped object, taking the lock on request entry and
+ * releasing it on request exit. This ensures that only one request for that session
+ * runs at a time, with the others waiting until they can obtain a lock on the
+ * appropriate object. This is referred to as "request serialization" because it causes
+ * requests to be processed serially, ie one after the other, rather than concurrently.
+ * This has nothing to do with java.io.Serializable.
+ * <p>
+ * When using an Orchestra conversationContext, session-scoped data should be avoided and
+ * conversation-scoped beans used instead. If there is no session-scoped data in use by
+ * an application then it is possible to allow concurrent requests to the same http session,
+ * but NOT concurrent access to the same orchestra conversationContext. This filter 
+ * implements that, by holding a lock on a mutex object held by the appropriate
+ * conversationContext.
+ * <p>
+ * The request serialization functionality can be enabled or disabled via a filter init
+ * parameter; setting "serializeRequests" to "false" disables this feature. Default
+ * value: true (enabled).
+ * <p>
+ * <h2>JDBC Connection Management</h2>
+ * Orchestra provides a special DataSource wrapper that can be configured for any
+ * datasource used by the application. The datasource simply wraps all real Connection
+ * objects it returns in a proxy, and keeps track of them. Here in this servlet it
+ * checks whether all connections borrowed by this thread have been returned, and if
+ * not returns the real connection nulls out the connection held by the proxy. See
+ * ConnectionManagerDataSource for more details.
+ */
+public class OrchestraServletFilter implements Filter
+{
+	/**
+	 * This filter init property can be set to "true" or "false". Default: "true".
+	 */
+	public final static String SERIALIZE_REQUESTS = "serializeRequests"; // NON-NLS
+
+	/**
+	 * Key of an attribute within the ConversationContext that is used as a lock to serialize
+	 * multiple http requests for the same conversation context.
+	 */
+	private final static String CONTEXT_MUTEXT_OBJECT = OrchestraServletFilter.class.getName()
+ ".SER_MUTEX";
+
+	private boolean serializeRequests = true;
+
+	public void init(FilterConfig filterConfig) throws ServletException
+	{
+		String value = filterConfig.getInitParameter(SERIALIZE_REQUESTS);
+		if ("false".equals(value)) // NON-NLS
+		{
+			serializeRequests = false;
+		}
+	}
+
+	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, final
FilterChain filterChain) throws IOException, ServletException
+	{
+		try
+		{
+			Object mutex = null;
+			if (serializeRequests)
+			{
+				ConversationManager manager = ConversationManager.getInstance(false);
+				if (manager != null)
+				{
+					ConversationContext conversationContext = manager.getCurrentConversationContext();
+					if (conversationContext != null)
+					{
+						synchronized(conversationContext)
+						{
+							mutex = conversationContext.getAttribute(CONTEXT_MUTEXT_OBJECT);
+							if (mutex == null)
+							{
+								mutex = new Object();
+								conversationContext.setAttribute(CONTEXT_MUTEXT_OBJECT, mutex);
+							}
+						}
+					}
+				}
+			}
+			if (serializeRequests && mutex != null)
+			{
+				synchronized(mutex)
+				{
+					filterChain.doFilter(servletRequest, servletResponse);
+				}
+			}
+			else
+			{
+				filterChain.doFilter(servletRequest, servletResponse);
+			}
+		}
+		finally
+		{
+			cleanupPersistence();
+		}
+	}
+
+	protected void cleanupPersistence()
+	{
+		ConnectionManagerDataSource.releaseAllBorrowedConnections();
+	}
+
+	public void destroy()
+	{
+	}
+}
\ No newline at end of file

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapter.java?rev=581845&r1=581844&r2=581845&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapter.java
(original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapter.java
Thu Oct  4 03:55:18 2007
@@ -18,15 +18,22 @@
  */
 package org.apache.myfaces.orchestra.frameworkAdapter.jsf;
 
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapterInterface;
-import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapterServletFilter;
+import java.io.IOException;
 
 import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.conversation.ConversationWiperThread;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapterInterface;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
 
 /**
  * A JSF Implementation for the FrameworkAdapter.
@@ -37,12 +44,44 @@
 public class JsfFrameworkAdapter implements FrameworkAdapterInterface
 {
 	private final static String ISE_MESSAGE="can't find a way to access jsf data structures";
// NON-NLS
+	private final static ThreadLocal httpServletRequest = new ThreadLocal();
+	private final static ThreadLocal httpServletResponse = new ThreadLocal();
+
+	private final Log log = LogFactory.getLog(JsfFrameworkAdapter.class);
 
 	protected FacesContext getFacesContext()
 	{
 		return FacesContext.getCurrentInstance();
 	}
 
+	private HttpServletRequest getRequest()
+	{
+		return (HttpServletRequest) httpServletRequest.get();
+	}
+
+	public void beginRequest(ServletRequest req, ServletResponse rsp)
+	{
+		log.debug("Beginning request");
+		if (req instanceof HttpServletRequest)
+		{
+			httpServletRequest.set(req);
+		}
+		if (rsp instanceof HttpServletResponse)
+		{
+			httpServletResponse.set(rsp);
+		}
+
+		FrameworkAdapter.setInstance(this);
+	}
+	
+	public void endRequest()
+	{
+		log.debug("Ending request");
+		FrameworkAdapter.setInstance(null);
+		httpServletRequest.set(null);
+		httpServletResponse.set(null);
+	}
+	
 	public String getInitParameter(String key)
 	{
 		FacesContext context = getFacesContext();
@@ -58,7 +97,7 @@
 			return context.getExternalContext().getRequestParameterMap().get(key);
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null)
 		{
 			return request.getParameter(key);
@@ -75,7 +114,7 @@
 			return context.getExternalContext().getRequestParameterMap().containsKey(key);
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null)
 		{
 			return request.getParameter(key) != null;
@@ -92,7 +131,7 @@
 			return context.getExternalContext().getRequestMap().get(key);
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null)
 		{
 			return request.getAttribute(key);
@@ -110,7 +149,7 @@
 			return;
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null)
 		{
 			request.setAttribute(key, value);
@@ -128,7 +167,7 @@
 			return context.getExternalContext().getRequestMap().containsKey(key);
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null)
 		{
 			return request.getAttribute(key) != null;
@@ -145,7 +184,7 @@
 			return context.getExternalContext().getSessionMap().get(key);
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null && request.getSession(true) != null)
 		{
 			return request.getSession(true).getAttribute(key);
@@ -163,7 +202,7 @@
 			return;
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null && request.getSession(true) != null)
 		{
 			request.getSession(true).setAttribute(key, value);
@@ -180,7 +219,7 @@
 			return context.getExternalContext().getSessionMap().containsKey(key);
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null && request.getSession(true) != null)
 		{
 			return request.getSession(true).getAttribute(key) != null;
@@ -197,7 +236,7 @@
 			return context.getExternalContext().getRequestContextPath();
 		}
 
-		HttpServletRequest request = FrameworkAdapterServletFilter.getHttpServletRequest();
+		HttpServletRequest request = getRequest();
 		if (request != null)
 		{
 			return request.getContextPath();

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapterFilter.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapterFilter.java?rev=581845&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapterFilter.java
(added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/jsf/JsfFrameworkAdapterFilter.java
Thu Oct  4 03:55:18 2007
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.myfaces.orchestra.frameworkAdapter.jsf;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Configures the JsfFrameworkAdapter.
+ * <p> 
+ * Orchestra accesses information about the request, response, session, etc via a
+ * FrameworkAdapter so that it can be used with multiple web tier frameworks. This
+ * class selects and configures the JSF version of this adapter.
+ * <p>
+ * Note that the JsfOrchestraServletFilter class combines the functionality of this
+ * class and the OrchestraServletFilter class together for convenience (allows just
+ * one filter to be defined rather than two). Of course this is only useful if you
+ * actually want the functionality of the OrchestraServletFilter.
+ */
+public class JsfFrameworkAdapterFilter implements Filter
+{
+	private final Log log = LogFactory.getLog(JsfFrameworkAdapterFilter.class);
+	private final JsfFrameworkAdapter adapter = new JsfFrameworkAdapter();
+
+	public void init(FilterConfig filterConfig) throws ServletException
+	{
+	}
+
+	public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain filterChain) throws
IOException, ServletException
+	{
+		log.debug("doFilter");
+		try
+		{
+			adapter.beginRequest(req, rsp);
+			filterChain.doFilter(req, rsp);
+		}
+		finally
+		{
+			adapter.endRequest();
+		}
+	}
+
+	public void destroy()
+	{
+	}
+}
\ No newline at end of file

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/CompoundFilter.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/CompoundFilter.java?rev=581845&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/CompoundFilter.java
(added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/CompoundFilter.java
Thu Oct  4 03:55:18 2007
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.myfaces.orchestra.lib;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * Compose two filter objects together, as if filter2 is nested within filter1.
+ */
+public abstract class CompoundFilter implements Filter
+{
+	private final Filter filter1;
+	private final Filter filter2;
+
+	public CompoundFilter(Filter filter1, Filter filter2)
+	{
+		this.filter1 = filter1;
+		this.filter2 = filter2;
+	}
+
+	public void init(FilterConfig filterConfig) throws ServletException
+	{
+		filter1.init(filterConfig);
+		filter2.init(filterConfig);
+	}
+
+	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, final
FilterChain filterChain) throws IOException, ServletException
+	{
+		FilterChain chain = new FilterChain()
+		{
+			public void doFilter(ServletRequest req, ServletResponse rsp) throws IOException, ServletException
+			{
+				filter2.doFilter(req, rsp, filterChain);
+			}
+			
+		};
+		
+		filter1.doFilter(servletRequest, servletResponse, chain);
+	}
+
+	public void destroy()
+	{
+		filter2.destroy();
+		filter1.destroy();
+	}
+}
\ No newline at end of file



Mime
View raw message