You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2009/10/01 20:05:29 UTC
svn commit: r820738 - in /myfaces/trinidad/branches/1.2.12.1-branch:
trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/
Author: sobryan
Date: Thu Oct 1 18:05:29 2009
New Revision: 820738
URL: http://svn.apache.org/viewvc?rev=820738&view=rev
Log:
TRINIDAD-1581: add the ability to get a session id from ExternalContextUtils
* Added methods to ExternalContextUtils
* Changed implementation of ServletExternalContext to be more "correct" in dealing with sessions
Modified:
myfaces/trinidad/branches/1.2.12.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
myfaces/trinidad/branches/1.2.12.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java
Modified: myfaces/trinidad/branches/1.2.12.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java?rev=820738&r1=820737&r2=820738&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java (original)
+++ myfaces/trinidad/branches/1.2.12.1-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ExternalContextUtils.java Thu Oct 1 18:05:29 2009
@@ -155,7 +155,33 @@
return RequestType.SERVLET;
}
+
+ /**
+ * Returns the current active session id or <code>null</code> if there is
+ * none. If a session is not already created, this method will create one
+ * for you.
+ *
+ * @param ec the current external context
+ * @return a string containing the requestedSessionId
+ */
+ public static String getSessionId(ExternalContext ec)
+ {
+ return getSessionId(ec, true);
+ }
+ /**
+ * Returns the current active session id or <code>null</code> if there is
+ * none.
+ *
+ * @param ec the current external context
+ * @param create create a new session if one is not created
+ * @return a string containing the requestedSessionId
+ */
+ public static String getSessionId(ExternalContext ec, boolean create)
+ {
+ Object session = ec.getSession(create);
+ return (null!=session)?(String)_runMethod(session, "getId"):null;
+ }
/**
* Returns the session ID for the client, or <code>null</code> if there is none.
@@ -179,7 +205,7 @@
{
return (Boolean) _runMethod(ec.getRequest(), "isRequestedSessionIdValid");
}
-
+
/**
* Returns the contextPath of the ServletContext or <code>null</code> for portlets
*
@@ -448,7 +474,7 @@
{
try
{
- Method sessionIdMethod = sessionIdMethod = obj.getClass().getMethod(methodName);
+ Method sessionIdMethod = obj.getClass().getMethod(methodName);
return sessionIdMethod.invoke(obj);
}
catch (Exception e)
Modified: myfaces/trinidad/branches/1.2.12.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java?rev=820738&r1=820737&r2=820738&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java (original)
+++ myfaces/trinidad/branches/1.2.12.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/external/ServletExternalContext.java Thu Oct 1 18:05:29 2009
@@ -393,11 +393,10 @@
@Override
public Object getSession(final boolean create)
{
- _checkRequest();
+ //If we don't have a request object, just return null
if (_httpServletRequest == null)
{
- throw new IllegalArgumentException(_LOG.getMessage(
- "ONLY_HTTPSERVLETREQUEST_SUPPORTED"));
+ return null;
}
return _httpServletRequest.getSession(create);
}