On Sat, 2007-08-18 at 14:24 +0200, Mario Ivankovits wrote:
> Hi!
> >> The only advantage of the current way (servlet filter) is, that it works
> >> in an mixed webapp environment (JSF/JSP)
> >> However, we can provide your's as the default and provide mine as an
> >> alternative if we would like to.
> >>
> >
> > jo, that's why I think the "framework-adapter" might be fine in a filter ?!
> >
> I don't understand the question.
> You asked about the RequestParameterResponseWrapper.
>
> The Framework-Adapter is another story.
> I had the need to access the request/session map outside of an already
> setup facesContext.
> The JsfFrameworkAdapter already depends on the OrchestraServletFilter
> where we setup two thread-locals to get access to the request/response
> object outside of a ready setup Faces-Context, which is required right
> in the OrchestraServletFilter.
> So I am fine by adding some Framework-Adapter specified stuff to the
> OrchestraServletFilter - instead of creating a new filter.
Ok, I've created a patch for review.
My stupid email client wraps lines at 80 chars, so I've attached it
instead of providing it inline.
Regards,
Simon
Index: /home/simon/apache/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java
===================================================================
--- /home/simon/apache/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java (revision 567266)
+++ /home/simon/apache/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java (working copy)
@@ -19,9 +19,7 @@
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 java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -31,7 +29,12 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
+
+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.FrameworkAdapter;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapterInterface;
/**
* Perform a number of useful per-request tasks.
@@ -80,6 +83,20 @@
* This filter init property can be set to "true" or "false". Default: "true".
*/
public final static String SERIALIZE_REQUESTS = "serializeRequests"; // NON-NLS
+
+ /**
+ * A filter init 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 = "adapterClass"; // NON-NLS
+ public final static String FRAMEWORK_ADAPTER_DFLT = "org.apache.myfaces.orchestra.frameworkAdapter.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 static ThreadLocal httpServletRequest = new ThreadLocal();
@@ -86,6 +103,7 @@
private static ThreadLocal httpServletResponse = new ThreadLocal();
private boolean serializeRequests = true;
+ private FrameworkAdapterInterface frameworkAdapterObj;
public void init(FilterConfig filterConfig) throws ServletException
{
@@ -94,6 +112,21 @@
{
serializeRequests = false;
}
+
+ String adapterClassName = filterConfig.getInitParameter(FRAMEWORK_ADAPTER);
+ if (adapterClassName == null) {
+ adapterClassName = FRAMEWORK_ADAPTER_DFLT;
+ }
+ try {
+ Class adapterClass = this.getClass().getClassLoader().loadClass(adapterClassName);
+ frameworkAdapterObj = (FrameworkAdapterInterface) adapterClass.newInstance();
+ } catch(ClassNotFoundException e) {
+ throw new ServletException("Unable to load Orchestra FrameworkAdapter class " + adapterClassName, e);
+ } catch(InstantiationException e) {
+ throw new ServletException("Unable to load Orchestra FrameworkAdapter class " + adapterClassName, e);
+ } catch(IllegalAccessException e) {
+ throw new ServletException("Unable to load Orchestra FrameworkAdapter class " + adapterClassName, e);
+ }
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
@@ -109,6 +142,7 @@
httpServletResponse.set(servletResponse);
}
+ FrameworkAdapter.setInstance(frameworkAdapterObj);
Object mutex = null;
if (serializeRequests)
{
@@ -150,6 +184,7 @@
}
finally
{
+ FrameworkAdapter.setInstance(null);
httpServletRequest.set(null);
httpServletResponse.set(null);
}
Index: /home/simon/apache/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapter.java
===================================================================
--- /home/simon/apache/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapter.java (revision 567265)
+++ /home/simon/apache/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/frameworkAdapter/FrameworkAdapter.java (working copy)
@@ -26,6 +26,8 @@
* Provides a static method for returning the singleton FrameworkAdapterInterface, which allows Orchestra to
* support MVC frameworks other than JSF.
* <p>
+ * A request filter must be configured which calls setInstance at the start of each request, and
+ * setInstance(null) at the end of each request.
* This class can be configured to return any implementation of FrameworkAdapterInterface that is desired,
* simply by calling setFrameworkAdapter before any Orchestra code calls getInstance on this class. If no
* configuration is done then getInstance defaults to returning a FrameworkAdapterInterface which supports
@@ -33,8 +35,9 @@
*/
public final class FrameworkAdapter
{
- private static FrameworkAdapterInterface INSTANCE;
+ private final static ThreadLocal instance = new ThreadLocal();
+ /** No instances of this class should be created. */
private FrameworkAdapter()
{
}
@@ -39,9 +42,12 @@
{
}
- static void setFrameworkAdapter(FrameworkAdapterInterface frameworkAdapterInterface)
+ /**
+ * Expected to be called only by a servlet filter at the start and end of each request.
+ */
+ public static void setInstance(FrameworkAdapterInterface frameworkAdapterInterface)
{
- INSTANCE = frameworkAdapterInterface;
+ instance.set(frameworkAdapterInterface);
}
public static FrameworkAdapterInterface getInstance()
@@ -46,12 +52,6 @@
public static FrameworkAdapterInterface getInstance()
{
- if (INSTANCE == null)
- {
- INSTANCE = new JsfFrameworkAdapter();
- }
-
- return INSTANCE;
+ return (FrameworkAdapterInterface) instance.get();
}
-
}