You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/07/28 05:23:07 UTC
svn commit: r798382 - in /myfaces/orchestra/trunk/core: ./
src/main/java/org/apache/myfaces/orchestra/lib/jsf/
src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/
Author: lu4242
Date: Tue Jul 28 03:23:02 2009
New Revision: 798382
URL: http://svn.apache.org/viewvc?rev=798382&view=rev
Log:
ORCHESTRA-15 Orchestra in Portal Environment, ORCHESTRA-22 portlet: Error creating bean with name 'org.apache.myfaces.orchestra.conversation.AccessScopeManager', ORCHESTRA-25 Orchestra does not work within BEA WebLogic JSF portlet - FacesContextFactory related problem
Added:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ExternalContextUtils.java (with props)
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletExternalContextWrapper.java (with props)
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletOrchestraFacesContextFactory.java (with props)
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/RequestType.java (with props)
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/_PortletFacesContextWrapper.java (with props)
Modified:
myfaces/orchestra/trunk/core/pom.xml
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/requestParameterProvider/jsf/RequestParameterFacesContextFactory.java
Modified: myfaces/orchestra/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/pom.xml?rev=798382&r1=798381&r2=798382&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/pom.xml (original)
+++ myfaces/orchestra/trunk/core/pom.xml Tue Jul 28 03:23:02 2009
@@ -53,6 +53,13 @@
<version>2.3</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>portlet-api</groupId>
+ <artifactId>portlet-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<!-- Needed for JSF1.1/JSF1.2 compatibility -->
Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ExternalContextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ExternalContextUtils.java?rev=798382&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ExternalContextUtils.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ExternalContextUtils.java Tue Jul 28 03:23:02 2009
@@ -0,0 +1,261 @@
+/*
+ * 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.jsf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+
+import javax.faces.context.ExternalContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * TODO: This class is a copy of
+ * org.apache.myfaces.commons.util.ExternalContextUtils
+ *
+ * Since orchestra should be compatible with 1.1, this is placed
+ * here and there is not a dependency for myfaces-commons-utils, because
+ * this stuff only works for 1.2
+ *
+ * This provides some functionality for determining some things about the
+ * native request object that is not provided by JSF. This class is useful
+ * for use in places where Portlet API's may or may not be present and can
+ * also provide access to some request-specific items which are not available on
+ * the JSF ExternalContext. If portlet API's are not present, this class simply
+ * handles the Servlet Request type.
+ *
+ * @since 1.4
+ */
+public final class ExternalContextUtils
+{
+ // prevent this from being instantiated
+ private ExternalContextUtils()
+ {
+ }
+
+ /**
+ * Returns the content length or -1 if the unknown.
+ *
+ * @param externalContext
+ * the ExternalContext
+ * @return the length or -1
+ */
+ public static final int getContentLength(ExternalContext externalContext)
+ {
+ RequestType type = getRequestType(externalContext);
+
+ if(type.isRequestFromClient())
+ {
+ try
+ {
+ Object request = externalContext.getRequest();
+ Method contentLenMethod = request.getClass().getMethod("getContentLength",new Class[]{});
+ return ((Integer) contentLenMethod.invoke(request,new Object[]{})).intValue(); //this will autobox
+ }
+ catch(Exception e)
+ {
+ _LOG.error("Unsupported request type.", e);
+ }
+ }
+
+ return -1;
+ }
+
+ /**
+ * Returns the request input stream if one is available
+ *
+ * @param externalContext
+ * @return
+ * @throws IOException
+ */
+ public static final InputStream getRequestInputStream(ExternalContext externalContext)
+ throws IOException
+ {
+ RequestType type = getRequestType(externalContext);
+
+ if(type.isRequestFromClient())
+ {
+ try
+ {
+ Object request = externalContext.getRequest();
+
+ Method method = request.getClass().getMethod(
+ type.isPortlet()?"getPortletInputStream":"getInputStream",new Class[]{});
+ return (InputStream) method.invoke(request,new Object[]{});
+ }
+ catch (Exception e)
+ {
+ _LOG.error("Unable to get the request input stream because of an error", e);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the requestType of this ExternalContext.
+ *
+ * @param externalContext the current external context
+ * @return the appropriate RequestType for this external context
+ * @see RequestType
+ */
+ public static final RequestType getRequestType(ExternalContext externalContext)
+ {
+ //Stuff is laid out strangely in this class in order to optimize
+ //performance. We want to do as few instanceof's as possible so
+ //things are laid out according to the expected frequency of the
+ //various requests occurring.
+ if(_PORTLET_CONTEXT_CLASS != null)
+ {
+ if (_PORTLET_CONTEXT_CLASS.isInstance(externalContext.getContext()))
+ {
+ //We are inside of a portlet container
+ Object request = externalContext.getRequest();
+
+ if(_PORTLET_RENDER_REQUEST_CLASS.isInstance(request))
+ {
+ return RequestType.RENDER;
+ }
+
+ if(_PORTLET_RESOURCE_REQUEST_CLASS != null)
+ {
+ if(_PORTLET_ACTION_REQUEST_CLASS.isInstance(request))
+ {
+ return RequestType.ACTION;
+ }
+
+ //We are in a JSR-286 container
+ if(_PORTLET_RESOURCE_REQUEST_CLASS.isInstance(request))
+ {
+ return RequestType.RESOURCE;
+ }
+
+ return RequestType.EVENT;
+ }
+
+ return RequestType.ACTION;
+ }
+ }
+
+ return RequestType.SERVLET;
+ }
+
+ /**
+ * This method is used when a ExternalContext object is not available,
+ * like in TomahawkFacesContextFactory.
+ *
+ * According to TOMAHAWK-1331, the object context could receive an
+ * instance of javax.portlet.PortletContext or javax.portlet.PortletConfig,
+ * so we check both cases.
+ *
+ * @param context
+ * @param request
+ * @return
+ */
+ public static final RequestType getRequestType(Object context, Object request)
+ {
+ //Stuff is laid out strangely in this class in order to optimize
+ //performance. We want to do as few instanceof's as possible so
+ //things are laid out according to the expected frequency of the
+ //various requests occurring.
+
+ if(_PORTLET_CONTEXT_CLASS != null)
+ {
+ if (_PORTLET_CONFIG_CLASS.isInstance(context) ||
+ _PORTLET_CONTEXT_CLASS.isInstance(context))
+ {
+ //We are inside of a portlet container
+
+ if(_PORTLET_RENDER_REQUEST_CLASS.isInstance(request))
+ {
+ return RequestType.RENDER;
+ }
+
+ if(_PORTLET_RESOURCE_REQUEST_CLASS != null)
+ {
+ if(_PORTLET_ACTION_REQUEST_CLASS.isInstance(request))
+ {
+ return RequestType.ACTION;
+ }
+
+ //We are in a JSR-286 container
+ if(_PORTLET_RESOURCE_REQUEST_CLASS.isInstance(request))
+ {
+ return RequestType.RESOURCE;
+ }
+
+ return RequestType.EVENT;
+ }
+
+ return RequestType.ACTION;
+ }
+ }
+
+ return RequestType.SERVLET;
+ }
+
+ private static final Log _LOG = LogFactory.getLog(ExternalContextUtils.class);
+
+ private static final Class _PORTLET_ACTION_REQUEST_CLASS;
+ private static final Class _PORTLET_RENDER_REQUEST_CLASS;
+ private static final Class _PORTLET_RESOURCE_REQUEST_CLASS; //Will be present in JSR-286 containers only
+ private static final Class _PORTLET_CONTEXT_CLASS;
+ private static final Class _PORTLET_CONFIG_CLASS;
+
+ static
+ {
+ Class context;
+ Class config;
+ Class actionRequest;
+ Class renderRequest;
+ Class resourceRequest;
+ try
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ context = loader.loadClass("javax.portlet.PortletContext");
+ config = loader.loadClass("javax.portlet.PortletConfig");
+ actionRequest = loader.loadClass("javax.portlet.ActionRequest");
+ renderRequest = loader.loadClass("javax.portlet.RenderRequest");
+
+ try
+ {
+ resourceRequest = loader.loadClass("javax.portlet.ResourceRequest");
+ }
+ catch (ClassNotFoundException e)
+ {
+ resourceRequest = null;
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ context = null;
+ config = null;
+ actionRequest = null;
+ renderRequest = null;
+ resourceRequest = null;
+ }
+
+ _PORTLET_CONTEXT_CLASS = context;
+ _PORTLET_CONFIG_CLASS = config;
+ _PORTLET_ACTION_REQUEST_CLASS = actionRequest;
+ _PORTLET_RENDER_REQUEST_CLASS = renderRequest;
+ _PORTLET_RESOURCE_REQUEST_CLASS = resourceRequest;
+ }
+}
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ExternalContextUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ExternalContextUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java?rev=798382&r1=798381&r2=798382&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java Tue Jul 28 03:23:02 2009
@@ -53,6 +53,7 @@
{
private final Log log = LogFactory.getLog(OrchestraFacesContextFactory.class);
private final FacesContextFactory original;
+ private PortletOrchestraFacesContextFactory portletOrchestraFacesContextFactory;
public OrchestraFacesContextFactory(FacesContextFactory original)
{
@@ -73,116 +74,128 @@
return null;
}
- // The handlers need to be reset on every request, as each request has a different
- // url which could potentially affect the list of handlers for that request.
- final LinkedList handlers = new LinkedList();
- handlers.add(new FrameworkAdapterRequestHandler());
- handlers.add(new ContextLockRequestHandler());
- handlers.add(new ConversationManagerRequestHandler());
- handlers.add(new DataSourceLeakRequestHandler());
-
- // Add any other handlers registered by filters or similar
- Map reqScope = facesContext.getExternalContext().getRequestMap();
- handlers.addAll(ConfigUtils.getRequestHandlers(reqScope));
-
- // Create and return the custom instance. Note that install=false
- // is specified for the FacesContextWrapper constructor, meaning
- // that the wrapper does not bind itself to the current thread:
- // the original object will still be the one that is returned
- // by FacesContext.getCurrentInstance(), not this wrapper. What
- // is important here is that the FacesServlet calls the release
- // method on this particular object, and that will happen because
- // FacesServlet uses the return value from this method as the object
- // to call release on, even though it is not the "current instance".
- // Not making the wrapper the current instance saves a little bit
- // of performance..
- log.debug("getFacesContext: creating custom instance");
- return new _FacesContextWrapper(facesContext, false)
+ if (!ExternalContextUtils.getRequestType(context, request).isPortlet())
{
- // Constructor. Note that the parent constructor runs first,
- // which means that FacesContext.currentInstance is valid
- // at the time that the RequestHandler objects run.
+ // The handlers need to be reset on every request, as each request has a different
+ // url which could potentially affect the list of handlers for that request.
+ final LinkedList handlers = new LinkedList();
+ handlers.add(new FrameworkAdapterRequestHandler());
+ handlers.add(new ContextLockRequestHandler());
+ handlers.add(new ConversationManagerRequestHandler());
+ handlers.add(new DataSourceLeakRequestHandler());
+
+ // Add any other handlers registered by filters or similar
+ Map reqScope = facesContext.getExternalContext().getRequestMap();
+ handlers.addAll(ConfigUtils.getRequestHandlers(reqScope));
+
+ // Create and return the custom instance. Note that install=false
+ // is specified for the FacesContextWrapper constructor, meaning
+ // that the wrapper does not bind itself to the current thread:
+ // the original object will still be the one that is returned
+ // by FacesContext.getCurrentInstance(), not this wrapper. What
+ // is important here is that the FacesServlet calls the release
+ // method on this particular object, and that will happen because
+ // FacesServlet uses the return value from this method as the object
+ // to call release on, even though it is not the "current instance".
+ // Not making the wrapper the current instance saves a little bit
+ // of performance..
+ log.debug("getFacesContext: creating custom instance");
+ return new _FacesContextWrapper(facesContext, false)
{
- log.debug("getFacesContext: running inner constructor");
- ListIterator i = handlers.listIterator();
- try
+ // Constructor. Note that the parent constructor runs first,
+ // which means that FacesContext.currentInstance is valid
+ // at the time that the RequestHandler objects run.
{
- while(i.hasNext())
+ log.debug("getFacesContext: running inner constructor");
+ ListIterator i = handlers.listIterator();
+ try
{
- RequestHandler h = (RequestHandler) i.next();
-
- if (log.isDebugEnabled())
+ while(i.hasNext())
{
- log.debug("Running inithandler of type " + h.getClass().getName());
+ RequestHandler h = (RequestHandler) i.next();
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("Running inithandler of type " + h.getClass().getName());
+ }
+
+ h.init(facesContext);
}
-
- h.init(facesContext);
+ }
+ catch(RuntimeException e)
+ {
+ // Oops, something went wrong. Undo any processing done by the
+ // RequestHandlers that have successfully run so far.
+ //
+ // Warning:: this tries to run deinit on the object that just
+ // failed to initialise. RequestHandler classes should be written
+ // to correctly handle this.
+ log.error("Problem initialising RequestHandler", e);
+ _release(i);
+ throw e;
}
}
- catch(RuntimeException e)
+
+ public void release()
{
- // Oops, something went wrong. Undo any processing done by the
- // RequestHandlers that have successfully run so far.
- //
- // Warning:: this tries to run deinit on the object that just
- // failed to initialise. RequestHandler classes should be written
- // to correctly handle this.
- log.error("Problem initialising RequestHandler", e);
+ // As the "setup" code for this inner class runs after the
+ // parent class constructor, the release code for this
+ // class should run before the parent release. This also
+ // ensures that FacesContext.currentInstance() is still
+ // valid when the RequestHandler objects run.
+ log.debug("Running release");
+
+ // Here, run the registered RequestHandlers in reverse order.
+ // Unfortunately, there is no ReverseListIterator class, so
+ // instead here we wind an iterator forward to the end of the
+ // list before passing it to _release, which then walks
+ // backwards through the list. Ecch.
+ ListIterator i = handlers.listIterator();
+ while (i.hasNext())
+ {
+ i.next();
+ }
_release(i);
- throw e;
+
+ // And invoke the parent release (which will invoke release
+ // on the target instance that this object decorates).
+ log.debug("Release completed");
+ super.release();
}
- }
-
- public void release()
- {
- // As the "setup" code for this inner class runs after the
- // parent class constructor, the release code for this
- // class should run before the parent release. This also
- // ensures that FacesContext.currentInstance() is still
- // valid when the RequestHandler objects run.
- log.debug("Running release");
- // Here, run the registered RequestHandlers in reverse order.
- // Unfortunately, there is no ReverseListIterator class, so
- // instead here we wind an iterator forward to the end of the
- // list before passing it to _release, which then walks
- // backwards through the list. Ecch.
- ListIterator i = handlers.listIterator();
- while (i.hasNext())
- {
- i.next();
- }
- _release(i);
-
- // And invoke the parent release (which will invoke release
- // on the target instance that this object decorates).
- log.debug("Release completed");
- super.release();
- }
-
- private void _release(ListIterator i)
- {
- while (i.hasPrevious())
+ private void _release(ListIterator i)
{
- try
+ while (i.hasPrevious())
{
- RequestHandler h = (RequestHandler) i.previous();
-
- if (log.isDebugEnabled())
+ try
{
- log.debug("Running deinithandler of type " + h.getClass().getName());
+ RequestHandler h = (RequestHandler) i.previous();
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("Running deinithandler of type " + h.getClass().getName());
+ }
+
+ h.deinit();
+ }
+ catch(Exception e)
+ {
+ // ignore errors, so we always deinitialise anything
+ // that we initialised.
+ log.error("Problem deinitialising RequestHandler", e);
}
-
- h.deinit();
- }
- catch(Exception e)
- {
- // ignore errors, so we always deinitialise anything
- // that we initialised.
- log.error("Problem deinitialising RequestHandler", e);
}
}
+ };
+ }
+ else
+ {
+ if (portletOrchestraFacesContextFactory == null)
+ {
+ portletOrchestraFacesContextFactory = new PortletOrchestraFacesContextFactory();
}
- };
+ return portletOrchestraFacesContextFactory.getFacesContext(
+ facesContext, context, request, response);
+ }
}
}
Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletExternalContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletExternalContextWrapper.java?rev=798382&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletExternalContextWrapper.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletExternalContextWrapper.java Tue Jul 28 03:23:02 2009
@@ -0,0 +1,373 @@
+/*
+ * 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.jsf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.context.ExternalContext;
+
+import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterProviderManager;
+
+/**
+ * Class used by _PortletFacesContextWrapper to allow orchestra work in portlets
+ *
+ * This class wraps encodeActionURL and encodeResourceURL to include
+ * conversationContext param like RequestParameterResponseWrapper does. In portlets
+ * we can't do the same than is servlets, because the params added here must be
+ * encoded by the portlet container and in portlets we don't have servlet redirect
+ * cases.
+ *
+ * @author Leonardo Uribe(latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class PortletExternalContextWrapper extends ExternalContext
+{
+ private ExternalContext _delegate;
+
+ public PortletExternalContextWrapper(ExternalContext context)
+ {
+ super();
+ this._delegate = context;
+ }
+
+ public void dispatch(String arg0) throws IOException
+ {
+ _delegate.dispatch(arg0);
+ }
+
+ public String encodeActionURL(String url)
+ {
+ if (url != null)
+ {
+ url = RequestParameterProviderManager.getInstance().encodeAndAttachParameters(url);
+ }
+ return _delegate.encodeActionURL(url);
+ }
+
+ public String encodeNamespace(String arg0)
+ {
+ return _delegate.encodeNamespace(arg0);
+ }
+
+ public String encodeResourceURL(String url)
+ {
+ if (url != null)
+ {
+ url = RequestParameterProviderManager.getInstance().encodeAndAttachParameters(url);
+ }
+ return _delegate.encodeResourceURL(url);
+ }
+
+ public Map getApplicationMap()
+ {
+ return _delegate.getApplicationMap();
+ }
+
+ public String getAuthType()
+ {
+ return _delegate.getAuthType();
+ }
+
+ public Object getContext()
+ {
+ return _delegate.getContext();
+ }
+
+ public String getInitParameter(String arg0)
+ {
+ return _delegate.getInitParameter(arg0);
+ }
+
+ public Map getInitParameterMap()
+ {
+ return _delegate.getInitParameterMap();
+ }
+
+ public String getRemoteUser()
+ {
+ return _delegate.getRemoteUser();
+ }
+
+ public Object getRequest()
+ {
+ return _delegate.getRequest();
+ }
+
+ public String getRequestContextPath()
+ {
+ return _delegate.getRequestContextPath();
+ }
+
+ public Map getRequestCookieMap()
+ {
+ return _delegate.getRequestCookieMap();
+ }
+
+ public Map getRequestHeaderMap()
+ {
+ return _delegate.getRequestHeaderMap();
+ }
+
+ public Map getRequestHeaderValuesMap()
+ {
+ return _delegate.getRequestHeaderValuesMap();
+ }
+
+ public Locale getRequestLocale()
+ {
+ return _delegate.getRequestLocale();
+ }
+
+ public Iterator getRequestLocales()
+ {
+ return _delegate.getRequestLocales();
+ }
+
+ public Map getRequestMap()
+ {
+ return _delegate.getRequestMap();
+ }
+
+ public Map getRequestParameterMap()
+ {
+ return _delegate.getRequestParameterMap();
+ }
+
+ public Iterator getRequestParameterNames()
+ {
+ return _delegate.getRequestParameterNames();
+ }
+
+ public Map getRequestParameterValuesMap()
+ {
+ return _delegate.getRequestParameterValuesMap();
+ }
+
+ public String getRequestPathInfo()
+ {
+ return _delegate.getRequestPathInfo();
+ }
+
+ public String getRequestServletPath()
+ {
+ return _delegate.getRequestServletPath();
+ }
+
+ public URL getResource(String arg0) throws MalformedURLException
+ {
+ return _delegate.getResource(arg0);
+ }
+
+ public InputStream getResourceAsStream(String arg0)
+ {
+ return _delegate.getResourceAsStream(arg0);
+ }
+
+ public Set getResourcePaths(String arg0)
+ {
+ return _delegate.getResourcePaths(arg0);
+ }
+
+ public Object getResponse()
+ {
+ return _delegate.getResponse();
+ }
+
+ public Object getSession(boolean arg0)
+ {
+ return _delegate.getSession(arg0);
+ }
+
+ public Map getSessionMap()
+ {
+ return _delegate.getSessionMap();
+ }
+
+ public Principal getUserPrincipal()
+ {
+ return _delegate.getUserPrincipal();
+ }
+
+ public boolean isUserInRole(String arg0)
+ {
+ return _delegate.isUserInRole(arg0);
+ }
+
+ public void redirect(String arg0) throws IOException
+ {
+ _delegate.redirect(arg0);
+ }
+
+ public void log(String s, Throwable throwable)
+ {
+ _delegate.log(s, throwable);
+ }
+
+ public void log(String s)
+ {
+ _delegate.log(s);
+ }
+
+ //Methods since 1.2
+
+ //Methods since 1.2
+
+ public String getResponseContentType()
+ {
+ try
+ {
+ Method method = _delegate.getClass().getMethod(
+ "getResponseContentType",
+ null);
+ return (String) method.invoke(_delegate, null);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("JSF 1.2 method not implemented: "+e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error calling JSF 1.2 method: "+e.getMessage());
+ }
+ }
+
+ public void setRequest(java.lang.Object request)
+ {
+ try
+ {
+ Method method = _delegate.getClass().getMethod(
+ "setRequest",
+ new Class[]{java.lang.Object.class});
+ method.invoke(_delegate, new Object[]{request});
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("JSF 1.2 method not implemented: "+e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error calling JSF 1.2 method: "+e.getMessage());
+ }
+ }
+
+ public void setRequestCharacterEncoding(java.lang.String encoding)
+ throws java.io.UnsupportedEncodingException
+ {
+ try
+ {
+ Method method = _delegate.getClass().getMethod(
+ "setRequestCharacterEncoding",
+ new Class[]{java.lang.String.class});
+ method.invoke(_delegate, new Object[]{encoding});
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("JSF 1.2 method not implemented: "+e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error calling JSF 1.2 method: "+e.getMessage());
+ }
+ }
+
+ public void setResponse(java.lang.Object response)
+ {
+ try
+ {
+ Method method = _delegate.getClass().getMethod(
+ "setResponse",
+ new Class[]{java.lang.Object.class});
+ method.invoke(_delegate, new Object[]{response});
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("JSF 1.2 method not implemented: "+e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error calling JSF 1.2 method: "+e.getMessage());
+ }
+ }
+
+ public void setResponseCharacterEncoding(java.lang.String encoding)
+ {
+ try
+ {
+ Method method = _delegate.getClass().getMethod(
+ "setResponseCharacterEncoding",
+ new Class[]{java.lang.String.class});
+ method.invoke(_delegate, new Object[]{encoding});
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("JSF 1.2 method not implemented: "+e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error calling JSF 1.2 method: "+e.getMessage());
+ }
+ }
+
+ public String getResponseCharacterEncoding()
+ {
+ try
+ {
+ Method method = _delegate.getClass().getMethod(
+ "getResponseCharacterEncoding",
+ null);
+ return (String) method.invoke(_delegate, null);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("JSF 1.2 method not implemented: "+e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error calling JSF 1.2 method: "+e.getMessage());
+ }
+ }
+
+ public String getRequestCharacterEncoding()
+ {
+ try
+ {
+ Method method = _delegate.getClass().getMethod(
+ "getRequestCharacterEncoding",
+ null);
+ return (String) method.invoke(_delegate, null);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("JSF 1.2 method not implemented: "+e.getMessage());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error calling JSF 1.2 method: "+e.getMessage());
+ }
+ }
+}
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletExternalContextWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletExternalContextWrapper.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletOrchestraFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletOrchestraFacesContextFactory.java?rev=798382&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletOrchestraFacesContextFactory.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletOrchestraFacesContextFactory.java Tue Jul 28 03:23:02 2009
@@ -0,0 +1,165 @@
+/*
+ * 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.jsf;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterServletFilter;
+
+/**
+ * Class used by OrchestraFacesContextFactory to allow orchestra work in portlets
+ *
+ * @author Leonardo Uribe(latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class PortletOrchestraFacesContextFactory
+{
+ private final Log log = LogFactory.getLog(PortletOrchestraFacesContextFactory.class);
+
+ private final AtomicLong _count;
+
+ private final static String REQUEST_CONTEXT_PARAM = "requestContext";
+
+ private final static String CONVERSATION_CONTEXT_PARAM = "conversationContext";
+
+ public final static String REQUEST_HANDLERS = "org.apache.myfaces.orchestra.REQUEST_HANDLERS";
+
+
+ public PortletOrchestraFacesContextFactory()
+ {
+ this._count = new AtomicLong(1);
+ }
+
+ /**
+ * Return the next token to identify in a unique way the current request. This is
+ * used when there is no conversationContext param available. In that remote case,
+ * a dummy param is added just to allow pass installed handlers between action
+ * and request scope.
+ *
+ * @return
+ */
+ protected String _getNextToken()
+ {
+ long nextToken = _count.incrementAndGet();
+ return Integer.toString(hashCode())+nextToken;
+ }
+
+ public FacesContext getFacesContext(final FacesContext facesContext, Object context,
+ Object request, Object response) throws FacesException
+ {
+ ExternalContext externalContext = facesContext.getExternalContext();
+ List handlers = null;
+ boolean init = false;
+ String nextToken = null;
+ if (RequestType.RENDER.equals(ExternalContextUtils.getRequestType(context, request)))
+ {
+ PortletRequest portletRequest = (PortletRequest) request;
+ nextToken = portletRequest.getParameter(CONVERSATION_CONTEXT_PARAM);
+ if (nextToken == null)
+ {
+ nextToken = portletRequest.getParameter(REQUEST_CONTEXT_PARAM);
+ }
+ if (nextToken != null)
+ {
+ //Restore it from application map and remove it from application map,
+ //since it will not be used anymore
+ handlers = (List) externalContext.getApplicationMap().remove(REQUEST_HANDLERS+nextToken);
+ }
+ }
+ if (handlers == null)
+ {
+ //Init
+ handlers = new LinkedList();
+ handlers.add(new FrameworkAdapterRequestHandler());
+ //TODO: put this one causes context never released because
+ //in portlets different threads could handle same request (one
+ //thread action and the other one render)
+ //handlers.add(new ContextLockRequestHandler());
+ handlers.add(new ConversationManagerRequestHandler());
+ handlers.add(new DataSourceLeakRequestHandler());
+ // Add any other handlers registered by filters or similar
+ Map reqScope = facesContext.getExternalContext().getRequestMap();
+ handlers.addAll(ConfigUtils.getRequestHandlers(reqScope));
+
+ if (RequestType.ACTION.equals(ExternalContextUtils.getRequestType(context, request)))
+ {
+ ActionResponse actionResponse = (ActionResponse) response;
+
+ PortletRequest portletRequest = (PortletRequest) request;
+ nextToken = portletRequest.getParameter(CONVERSATION_CONTEXT_PARAM);
+ if (nextToken == null)
+ {
+ nextToken = _getNextToken();
+ actionResponse.setRenderParameter(REQUEST_CONTEXT_PARAM, nextToken);
+ }
+ if (nextToken != null)
+ {
+ //Put it on application map, to make it available on render response phase
+ externalContext.getApplicationMap().put(REQUEST_HANDLERS+nextToken, handlers);
+ }
+ }
+ init = true;
+ }
+
+ // Do the stuff that suppose to be done by RequestParameterFacesContextFactory
+ // We need to do it here, because the code requires handlers are already set.
+ setRequestParameterResponseWrappedMode(context, request);
+
+ final RequestHandler contextLockHandler = new ContextLockRequestHandler();
+
+ //Since we override ExternalContext, install = true for this wrapper.
+ return new _PortletFacesContextWrapper(facesContext, true,
+ init, nextToken, handlers, contextLockHandler);
+ }
+
+ private void setRequestParameterResponseWrappedMode(Object context, Object request)
+ {
+ if (!getBooleanRequestValue(request,
+ RequestParameterServletFilter.REQUEST_PARAM_FILTER_CALLED))
+ {
+ setBooleanRequestValue(request,
+ RequestParameterServletFilter.REQUEST_PARAM_RESPONSE_WRAPPED, Boolean.TRUE);
+ }
+ }
+
+ private boolean getBooleanRequestValue(Object request, String key)
+ {
+ PortletRequest portletRequest = (PortletRequest) request;
+
+ return Boolean.TRUE.equals(portletRequest.getAttribute(key));
+ }
+
+ private void setBooleanRequestValue(Object request, String key, Boolean value)
+ {
+ PortletRequest portletRequest = (PortletRequest) request;
+
+ portletRequest.setAttribute(key,value);
+ }
+}
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletOrchestraFacesContextFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/PortletOrchestraFacesContextFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/RequestType.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/RequestType.java?rev=798382&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/RequestType.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/RequestType.java Tue Jul 28 03:23:02 2009
@@ -0,0 +1,136 @@
+/*
+ * 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.jsf;
+
+/**
+ * TODO: This class is a copy of
+ * org.apache.myfaces.commons.util.RequestType
+ *
+ * Since orchestra should be compatible with 1.1, this is placed
+ * here and there is not a dependency for myfaces-commons-utils, because
+ * this stuff only works for 1.2 (this class is also compatible
+ * with jdk 1.4)
+ *
+ * Represents the type of request currently in the ExternalContext.
+ * All servlet requests will be of the SERVLET requestType whereas
+ * all of the other RequestTypes will be portlet type requests. There
+ * are a number of convenience methods on the RequestType enumeration
+ * which can be used to determine the capabilities of the current request.
+ *
+ * @since 1.4
+ */
+public class RequestType
+{
+ /**
+ * The type for all servlet requests. SERVLET request types are
+ * both client requests and response writable.
+ */
+ final public static RequestType SERVLET = new RequestType(true, true, false);
+
+ /**
+ * The type for a portlet RenderRequest. RENDER request types are
+ * for portlets and are response writable but are NOT client
+ * requests.
+ */
+ final public static RequestType RENDER = new RequestType(false, true, true);
+
+ /**
+ * The type for a portlet ActionRequest. ACTION request types are
+ * for portlets and are client requests but are NOT response
+ * writable.
+ */
+ final public static RequestType ACTION = new RequestType(true, false, true);
+
+ /**
+ * The type for a portlet ResourceRequest. RESOURCE request types
+ * are for portlets and are both client requests and response
+ * writable. RESOURCE request types will only be returned in a
+ * Portlet 2.0 portlet container.
+ */
+ final public static RequestType RESOURCE = new RequestType(true, true, true);
+
+ /**
+ * The type for a portlet EventRequest. EVENT request types
+ * are for portlets and are neither client requests nor response
+ * writable. EVENT request types will only be returned in a
+ * Portlet 2.0 portlet container.
+ */
+ final public static RequestType EVENT = new RequestType(false, false, true);
+
+ private boolean _client;
+ private boolean _writable;
+ private boolean _portlet;
+
+ RequestType(boolean client, boolean writable, boolean portlet)
+ {
+ _client = client;
+ _writable = writable;
+ _portlet = portlet;
+ }
+
+ /**
+ * Returns <code>true</code> if this request was a direct
+ * result of a call from the client. This implies that
+ * the current application is the "owner" of the current
+ * request and that it has access to the inputStream, can
+ * get and set character encodings, etc. Currently all
+ * SERVLET, ACTION, and RESOURCE RequestTypes are client
+ * requests.
+ *
+ * @return <code>true</code> if the current request is a
+ * client data type request and <code>false</code>
+ * if it is not.
+ */
+ public boolean isRequestFromClient()
+ {
+ return _client;
+ }
+
+ /**
+ * Returns <code>true</code> if the response for this
+ * RequestType is intended to produce output to the client.
+ * Currently the SERVLET, RENDER, and RESOURCE request are
+ * response writable.
+ *
+ * @return <code>true</code> if the current request is
+ * intended to produce output and <code>false</code>
+ * if it is not.
+ */
+ public boolean isResponseWritable()
+ {
+ return _writable;
+ }
+
+ /**
+ * Returns <code>true</code> if the response for this
+ * RequestType originated from a JSR-168 or JSR-286
+ * portlet container. Currently RENDER, ACTION,
+ * RESOURCE, and EVENT RequestTypes are all portlet
+ * requests.
+ *
+ * @return <code>true</code> if the current request
+ * originated inside of a JSR-168 or JSR-286
+ * Portlet Container or <code>false</code> if
+ * it did not.
+ */
+ public boolean isPortlet()
+ {
+ return _portlet;
+ }
+}
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/RequestType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/RequestType.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/_PortletFacesContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/_PortletFacesContextWrapper.java?rev=798382&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/_PortletFacesContextWrapper.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/_PortletFacesContextWrapper.java Tue Jul 28 03:23:02 2009
@@ -0,0 +1,374 @@
+/*
+ * 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.jsf;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import javax.el.ELContext;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
+
+/**
+ * Convenient class to wrap the current FacesContext in portlet environment.
+ *
+ * @since 1.4
+ *
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class _PortletFacesContextWrapper extends FacesContext
+{
+ private final static String REQUEST_ADAPTER = "org.apache.myfaces.orchestra.REQUEST_ADAPTER";
+
+ //~ Instance fields -------------------------------------------------------
+
+ private final FacesContext _facesContext;
+ private Method methodGetELContext = null;
+ private final ExternalContext externalContextDelegate;
+ private final RequestHandler contextLockHandler;
+ private final List _handlers;
+ private final String _nextToken;
+
+ private final Log log = LogFactory
+ .getLog(_PortletFacesContextWrapper.class);
+
+ //~ Constructors ----------------------------------------------------------
+
+ /**
+ * The install parameter controls whether this object will be configured as
+ * the object returned from calls to FacesContext.getCurrentInstance() or not.
+ * <p>
+ * When only overriding the release() method, then install=false is ok as that
+ * is called directly by the FacesServlet on the instance returned by the
+ * FacesContextFactory. However all other methods are invoked on the object
+ * that is returned from FacesContext.getCurrentInstance, so install=true is
+ * needed in order for any other method overrides to have any effect.
+ * <p>
+ * <b>IMPORTANT</b>: install=true should not be used until MYFACES-1820 is fixed.
+ */
+ public _PortletFacesContextWrapper(final FacesContext facesContext,
+ final boolean install, boolean finit, String fnextToken, List fhandlers,
+ final RequestHandler fcontextLockHandler )
+ {
+ log.debug("getFacesContext: running inner constructor");
+
+ _facesContext = facesContext;
+
+ if (install)
+ {
+ FacesContext.setCurrentInstance(this);
+ }
+
+ externalContextDelegate = new PortletExternalContextWrapper(
+ _facesContext.getExternalContext());
+
+ _handlers = fhandlers;
+ _nextToken = fnextToken;
+ contextLockHandler = fcontextLockHandler;
+ if (finit)
+ {
+ ListIterator i = fhandlers.listIterator();
+ try
+ {
+ contextLockHandler.init(facesContext);
+ while (i.hasNext())
+ {
+ RequestHandler h = (RequestHandler) i.next();
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("Running inithandler of type "
+ + h.getClass().getName());
+ }
+
+ h.init(facesContext);
+ }
+ }
+ catch (RuntimeException e)
+ {
+ log.error("Problem initialising RequestHandler", e);
+ _release(i);
+ contextLockHandler.deinit();
+ throw e;
+ }
+ }
+ else
+ {
+ try
+ {
+ contextLockHandler.init(facesContext);
+ }
+ catch (RuntimeException e)
+ {
+ contextLockHandler.deinit();
+ }
+
+ RequestType type = ExternalContextUtils.getRequestType(facesContext
+ .getExternalContext());
+
+ if (RequestType.RENDER.equals(type))
+ {
+ String handlersKey = (String) fnextToken;
+ FrameworkAdapter adapter = (FrameworkAdapter) getExternalContext()
+ .getApplicationMap().remove(
+ REQUEST_ADAPTER + handlersKey);
+ if (FrameworkAdapter.getCurrentInstance() == null)
+ {
+ FrameworkAdapter.setCurrentInstance(adapter);
+ }
+ }
+ }
+ }
+
+ //~ Non-Final Methods -----------------------------------------------------
+
+ public void release()
+ {
+ log.debug("Running release");
+ RequestType type = ExternalContextUtils
+ .getRequestType(getExternalContext());
+ if (RequestType.RENDER.equals(type) ||
+ RequestType.EVENT.equals(type) ||
+ RequestType.RESOURCE.equals(type) ||
+ this.getResponseComplete())
+ {
+ ListIterator i = _handlers.listIterator();
+ while (i.hasNext())
+ {
+ i.next();
+ }
+ _release(i);
+ }
+ if (RequestType.ACTION.equals(type))
+ {
+ if (this.getResponseComplete())
+ {
+ // If response is complete by some reason, we need to
+ // clean request handlers from application map. This is set
+ // before an instance of this class is created.
+ getExternalContext().getApplicationMap().remove(
+ PortletOrchestraFacesContextFactory.REQUEST_HANDLERS+_nextToken);
+ }
+ else
+ {
+ //Pass the current FrameworkAdapter through application map,
+ //to remove it later when rendering
+ FrameworkAdapter adapter = FrameworkAdapter.getCurrentInstance();
+ getExternalContext().getApplicationMap().put(
+ REQUEST_ADAPTER + _nextToken, adapter);
+
+ //Orchestra suppose the same thread handles the current request, but
+ //in portlets this is not necessary true. One thread could handle action
+ //requests and other render request. To keep code working we set it to
+ //null here, so other request don't mix it.
+ FrameworkAdapter.setCurrentInstance(null);
+ }
+ }
+
+ try
+ {
+ //Since in portlets the same thread does not handler both action and
+ //render phase for the same request contextLockHandler needs to
+ //be cleared and lock again
+ contextLockHandler.deinit();
+ }
+ catch (Exception e)
+ {
+ log.error("Problem deinitialising RequestHandler", e);
+ }
+ log.debug("Release completed");
+ _facesContext.release();
+ }
+
+ private void _release(ListIterator i)
+ {
+ while (i.hasPrevious())
+ {
+ try
+ {
+ RequestHandler h = (RequestHandler) i.previous();
+ if (log.isDebugEnabled())
+ {
+ log.debug("Running deinithandler of type "
+ + h.getClass().getName());
+ }
+ h.deinit();
+ }
+ catch (Exception e)
+ {
+ log.error("Problem deinitialising RequestHandler", e);
+ }
+ }
+ }
+
+ //~ Final Methods ---------------------------------------------------------
+
+ public final Application getApplication()
+ {
+ return _facesContext.getApplication();
+ }
+
+ public final Iterator getClientIdsWithMessages()
+ {
+ return _facesContext.getClientIdsWithMessages();
+ }
+
+ public ExternalContext getExternalContext()
+ {
+ return externalContextDelegate == null ? _facesContext
+ .getExternalContext() : externalContextDelegate;
+ }
+
+ public final FacesMessage.Severity getMaximumSeverity()
+ {
+ return _facesContext.getMaximumSeverity();
+ }
+
+ public final Iterator getMessages()
+ {
+ return _facesContext.getMessages();
+ }
+
+ public final Iterator getMessages(String clientId)
+ {
+ return _facesContext.getMessages(clientId);
+ }
+
+ public final RenderKit getRenderKit()
+ {
+ return _facesContext.getRenderKit();
+ }
+
+ public final boolean getRenderResponse()
+ {
+ return _facesContext.getRenderResponse();
+ }
+
+ public final boolean getResponseComplete()
+ {
+ return _facesContext.getResponseComplete();
+ }
+
+ public final void setResponseStream(ResponseStream responsestream)
+ {
+ _facesContext.setResponseStream(responsestream);
+ }
+
+ public final ResponseStream getResponseStream()
+ {
+ return _facesContext.getResponseStream();
+ }
+
+ public final void setResponseWriter(ResponseWriter responsewriter)
+ {
+ _facesContext.setResponseWriter(responsewriter);
+ }
+
+ public final ResponseWriter getResponseWriter()
+ {
+ return _facesContext.getResponseWriter();
+ }
+
+ public final void setViewRoot(UIViewRoot viewRoot)
+ {
+ _facesContext.setViewRoot(viewRoot);
+ }
+
+ public final UIViewRoot getViewRoot()
+ {
+ return _facesContext.getViewRoot();
+ }
+
+ public final void addMessage(String clientId, FacesMessage message)
+ {
+ _facesContext.addMessage(clientId, message);
+ }
+
+ public final void renderResponse()
+ {
+ _facesContext.renderResponse();
+ }
+
+ public final void responseComplete()
+ {
+ _facesContext.responseComplete();
+ }
+
+ public final ELContext getELContext()
+ {
+ // Here, we cannot call getELContext on FacesContext as it does not
+ // exist for JSF1.1; the solution is to use reflection instead. This
+ // method will never be called unless we are in a JSF1.2 environment
+ // so the target method will always exist when this is called.
+ try
+ {
+ if (methodGetELContext == null)
+ {
+ // Performance optimisation: find method, and cache it for later.
+ methodGetELContext = FacesContext.class.getDeclaredMethod(
+ "getELContext", (Class[]) null);
+ }
+ return (ELContext) methodGetELContext.invoke(_facesContext,
+ (Object[]) null);
+ }
+ catch (NoSuchMethodException e)
+ {
+ // should never happen
+ Log log = LogFactory.getLog(this.getClass());
+ log.error("JSF1.2 method invoked in non-JSF-1.2 environment", e);
+ throw new IllegalStateException(
+ "JSF1.2 method invoked in non-JSF-1.2 environment");
+ }
+ catch (InvocationTargetException e)
+ {
+ // should never happen
+ Log log = LogFactory.getLog(this.getClass());
+ log.error(
+ "Method getELContext on wrapped instance threw exception",
+ e);
+ throw new IllegalStateException(
+ "Method getELContext on wrapped instance threw exception");
+ }
+ catch (IllegalAccessException e)
+ {
+ // should never happen
+ Log log = LogFactory.getLog(this.getClass());
+ log
+ .error(
+ "Method getElContext on wrapped instance is not accessable",
+ e);
+ throw new IllegalStateException(
+ "Method getElContext on wrapped instance is not accessable");
+ }
+ }
+}
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/_PortletFacesContextWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/_PortletFacesContextWrapper.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
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=798382&r1=798381&r2=798382&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 Tue Jul 28 03:23:02 2009
@@ -18,9 +18,6 @@
*/
package org.apache.myfaces.orchestra.requestParameterProvider.jsf;
-import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterResponseWrapper;
-import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterServletFilter;
-
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
@@ -28,6 +25,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.myfaces.orchestra.lib.jsf.ExternalContextUtils;
+import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterResponseWrapper;
+import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterServletFilter;
+
/**
* Ensure that a custom wrapper is put around the HttpServletResponse so that encodeURL can be
* intercepted and modified.
@@ -58,7 +59,7 @@
public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle)
throws FacesException
{
- if (response instanceof HttpServletResponse)
+ if (!ExternalContextUtils.getRequestType(context, request).isPortlet())
{
HttpServletRequest httpServletRequest = (HttpServletRequest) request;