Author: julien(a)jboss.com
Date: 2008-02-03 06:59:52 -0500 (Sun, 03 Feb 2008)
New Revision: 9720
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpSession.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchtedRequestDispatcher.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/HTTPSessionInvalidationInvalidesPortletSessionTestCase.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletUtils.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/ObtainNonNullSessionUsingCreateEqualsFalseTestCase.java
Log:
- rewrote portlet session obtention
- rewrote http portlet session wrapper obtention
- added test case for portlet session
- added http request/response unwrapping for dispatch
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java 2008-02-03
02:13:01 UTC (rev 9719)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -40,6 +40,7 @@
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.portlet.PortletSession;
+import javax.portlet.PortletRequest;
import java.security.Principal;
import java.util.Enumeration;
import java.util.Locale;
@@ -107,7 +108,7 @@
final DispatchType dispatchType;
/** . */
- private final PortletRequestImpl preq;
+ private final PortletRequest preq;
/** . */
private final HttpServletRequest dreq;
@@ -127,6 +128,9 @@
/** . */
private final ServletContext servletContext;
+ /** . */
+ private DispatchedHttpSession[] session;
+
public DispatchedHttpServletRequest(
Dispatch dispatch,
PortletRequestImpl preq,
@@ -274,12 +278,12 @@
}
//
- return preq.getAttributes().getAttribute(s, (HttpServletRequest)getRequest());
+ return ((PortletRequestImpl)preq).getAttributes().getAttribute(s,
(HttpServletRequest)getRequest());
}
public final Enumeration getAttributeNames()
{
- Set<String> names =
Tools.toSet(preq.getAttributes().getAttributeNames(null));
+ Set<String> names =
Tools.toSet(((PortletRequestImpl)preq).getAttributes().getAttributeNames(null));
// Add super stuff that is not reserved
for (Enumeration e = super.getAttributeNames();e.hasMoreElements();)
@@ -308,7 +312,7 @@
}
//
- preq.getAttributes().setAttribute(s, o);
+ ((PortletRequestImpl)preq).getAttributes().setAttribute(s, o);
}
public final void removeAttribute(String s)
@@ -461,7 +465,7 @@
public final RequestDispatcher getRequestDispatcher(String s)
{
- return new RequestDispatcherImpl(dreq.getRequestDispatcher(s), s);
+ return new DispatchtedRequestDispatcher(dreq.getRequestDispatcher(s), s);
}
public final boolean isUserInRole(String s)
@@ -471,12 +475,12 @@
public final HttpSession getSession(boolean b)
{
- return preq.getPortletSession(b).getHttpSession(PortletSession.APPLICATION_SCOPE);
+ return getSession(b, PortletSession.APPLICATION_SCOPE);
}
public final HttpSession getSession()
{
- return preq.getPortletSession().getHttpSession(PortletSession.APPLICATION_SCOPE);
+ return getSession(true);
}
public final boolean isRequestedSessionIdFromCookie()
@@ -803,4 +807,52 @@
return "GET";
}
}
+
+ /**
+ * Returns the an implementation of
<code>javax.servlet.http.HttpSession</code> that wraps this
+ * portlet session and use the specified scope for manipulating attributes. This
session is used
+ * during the request dispatch to a servlet.
+ *
+ * @param scope the scope
+ * @return the wrapped session
+ */
+ private HttpSession getSession(boolean create, int scope)
+ {
+ if (session == null)
+ {
+ session = new DispatchedHttpSession[2];
+ }
+
+ // Dereference an existing session if necessary
+ if (session[scope] != null && !session[scope].isValid())
+ {
+ session[scope] = null;
+ }
+
+ // If we have a session here we are sure it is valid and ok to return it
+ if (session[scope] != null)
+ {
+ // So we do nothing
+ }
+ else if (create)
+ {
+ // For sure we need a session we will obtain a valid one
+ PortletSession portletSession = preq.getPortletSession();
+ session[scope] = new DispatchedHttpSession(this, portletSession, scope);
+ }
+ else
+ {
+ // Here we can try an existing session but it may return null
+ PortletSession portletSession = preq.getPortletSession(false);
+
+ //
+ if (portletSession != null)
+ {
+ session[scope] = new DispatchedHttpSession(this, portletSession, scope);
+ }
+ }
+
+ //
+ return session[scope];
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java 2008-02-03
02:13:01 UTC (rev 9719)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -24,7 +24,6 @@
import org.jboss.portal.portlet.impl.jsr168.api.MimeResponseImpl;
import org.jboss.portal.portlet.impl.jsr168.api.StateAwareResponseImpl;
-import org.jboss.portal.common.NotYetImplemented;
import javax.portlet.PortletResponse;
import javax.servlet.ServletOutputStream;
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpSession.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpSession.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpSession.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -0,0 +1,149 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.impl.jsr168;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.ServletContext;
+import javax.portlet.PortletSession;
+import java.util.Enumeration;
+import java.util.ArrayList;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class DispatchedHttpSession implements HttpSession
+{
+
+ /** . */
+ private final DispatchedHttpServletRequest dispatchedRequest;
+
+ /** . */
+ private final PortletSession delegate;
+
+ /** . */
+ private final int scope;
+
+ public DispatchedHttpSession(DispatchedHttpServletRequest dispatchedRequest,
PortletSession delegate, int scope)
+ {
+ this.dispatchedRequest = dispatchedRequest;
+ this.delegate = delegate;
+ this.scope = scope;
+ }
+
+ public long getCreationTime()
+ {
+ return delegate.getCreationTime();
+ }
+
+ public String getId()
+ {
+ return delegate.getId();
+ }
+
+ public long getLastAccessedTime()
+ {
+ return delegate.getLastAccessedTime();
+ }
+
+ public ServletContext getServletContext()
+ {
+ return
((HttpServletRequest)dispatchedRequest.getRequest()).getSession().getServletContext();
+ }
+
+ public void setMaxInactiveInterval(int i)
+ {
+ delegate.setMaxInactiveInterval(i);
+ }
+
+ public int getMaxInactiveInterval()
+ {
+ return delegate.getMaxInactiveInterval();
+ }
+
+ public HttpSessionContext getSessionContext()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getAttribute(String s)
+ {
+ return delegate.getAttribute(s, scope);
+ }
+
+ public Object getValue(String s)
+ {
+ return getAttribute(s);
+ }
+
+ public Enumeration getAttributeNames()
+ {
+ return delegate.getAttributeNames(scope);
+ }
+
+ public String[] getValueNames()
+ {
+ ArrayList<String> names = Collections.list(delegate.getAttributeNames());
+
+ //
+ return names.toArray(new String[names.size()]);
+ }
+
+ public void setAttribute(String s, Object o)
+ {
+ delegate.setAttribute(s, o, scope);
+ }
+
+ public void putValue(String s, Object o)
+ {
+ setAttribute(s, o);
+ }
+
+ public void removeAttribute(String s)
+ {
+ delegate.removeAttribute(s, scope);
+ }
+
+ public void removeValue(String s)
+ {
+ removeAttribute(s);
+ }
+
+ public void invalidate()
+ {
+ delegate.invalidate();
+ }
+
+ public boolean isNew()
+ {
+ return delegate.isNew();
+ }
+
+ boolean isValid()
+ {
+ return true;
+ }
+}
Copied:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchtedRequestDispatcher.java
(from rev 9707,
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/RequestDispatcherImpl.java)
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchtedRequestDispatcher.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchtedRequestDispatcher.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -0,0 +1,125 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.impl.jsr168;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequestWrapper;
+import javax.servlet.ServletResponseWrapper;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class DispatchtedRequestDispatcher implements RequestDispatcher
+{
+
+ /** . */
+ private final RequestDispatcher realDispatcher;
+
+ /** . */
+ private final String path;
+
+ public DispatchtedRequestDispatcher(RequestDispatcher realDispatcher, String path)
+ {
+ this.realDispatcher = realDispatcher;
+ this.path = path;
+ }
+
+ public void include(ServletRequest req, ServletResponse resp) throws ServletException,
IOException
+ {
+ DispatchedHttpServletRequest dreq = unwrap(req);
+ unwrap(resp);
+
+ //
+ dreq.pushDispatch(new Dispatch(DispatchType.INCLUDE, path));
+ try
+ {
+ realDispatcher.include(req, resp);
+ }
+ finally
+ {
+ dreq.popDispatch();
+ }
+ }
+
+ public void forward(ServletRequest req, ServletResponse resp) throws ServletException,
IOException
+ {
+ DispatchedHttpServletRequest dreq = unwrap(req);
+ unwrap(resp);
+
+ //
+ dreq.pushDispatch(new Dispatch(DispatchType.FORWARD, path));
+ try
+ {
+ realDispatcher.forward(req, resp);
+ }
+ finally
+ {
+ dreq.popDispatch();
+ }
+ }
+
+ private static DispatchedHttpServletRequest unwrap(ServletRequest wrapped)
+ {
+ while (true)
+ {
+ if (wrapped instanceof DispatchedHttpServletRequest)
+ {
+ return (DispatchedHttpServletRequest)wrapped;
+ }
+ else if (wrapped instanceof ServletRequestWrapper)
+ {
+ ServletRequestWrapper wrapper = (ServletRequestWrapper)wrapped;
+ wrapped = wrapper.getRequest();
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+
+ private static DispatchedHttpServletResponse unwrap(ServletResponse wrapped)
+ {
+ while (true)
+ {
+ if (wrapped instanceof DispatchedHttpServletResponse)
+ {
+ return (DispatchedHttpServletResponse)wrapped;
+ }
+ else if (wrapped instanceof ServletResponseWrapper)
+ {
+ ServletResponseWrapper wrapper = (ServletResponseWrapper)wrapped;
+ wrapped = wrapper.getResponse();
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletUtils.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletUtils.java 2008-02-03
02:13:01 UTC (rev 9719)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletUtils.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -22,8 +22,15 @@
******************************************************************************/
package org.jboss.portal.portlet.impl.jsr168;
+import org.jboss.portal.portlet.impl.jsr168.api.PortletRequestImpl;
+
import javax.portlet.PortletMode;
import javax.portlet.WindowState;
+import javax.portlet.PortletRequest;
+import javax.portlet.RenderRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.filter.PortletRequestWrapper;
+import javax.portlet.filter.PortletResponseWrapper;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -116,4 +123,44 @@
tmp.append(SUFFIX);
return tmp.toString();
}
+
+ public static <U extends PortletRequest> U unwrap(PortletRequest wrapped,
Class<U> unwrapped)
+ {
+ while (true)
+ {
+ if (wrapped instanceof PortletRequestWrapper)
+ {
+ PortletRequestWrapper wrapper = (PortletRequestWrapper)wrapped;
+ wrapped = wrapper.getRequest();
+ }
+ else if (unwrapped.isInstance(wrapped))
+ {
+ return unwrapped.cast(wrapped);
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+
+ public static <U extends PortletResponse> U unwrap(PortletResponse wrapped,
Class<U> unwrapped)
+ {
+ while (true)
+ {
+ if (wrapped instanceof PortletResponseWrapper)
+ {
+ PortletResponseWrapper wrapper = (PortletResponseWrapper)wrapped;
+ wrapped = wrapper.getResponse();
+ }
+ else if (unwrapped.isInstance(wrapped))
+ {
+ return unwrapped.cast(wrapped);
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-02-03
02:13:01 UTC (rev 9719)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -378,39 +378,36 @@
public PortletSessionImpl getPortletSession(boolean create)
{
- //
- if (create)
+ // Dereference an existing session if it is not valid
+ if (psession != null && !psession.isValid())
{
- // Create the session with the dispatched request
- HttpSession hsession = dreq.getSession(true);
+ psession = null;
+ }
- // Create portlet session
+ // If we have a session here we are sure it is valid and ok to return it
+ if (psession != null)
+ {
+ // So we do nothing
+ }
+ else if (create)
+ {
+ // For sure we need a session we will obtain a valid one
+ HttpSession hsession = dreq.getSession();
PortletApplicationImpl portletApp =
(PortletApplicationImpl)container.getApplication();
- psession = new PortletSessionImpl(
- hsession,
- windowContext.getId(),
- portletApp.getPortletContext());
+ psession = new PortletSessionImpl(hsession, windowContext.getId(),
portletApp.getPortletContext());
}
- else if (psession == null)
+ else
{
+ // Here we can try an existing session but it may return null
HttpSession hsession = dreq.getSession(false);
//
if (hsession != null)
{
- // Create portlet session
PortletApplicationImpl portletApp =
(PortletApplicationImpl)container.getApplication();
- psession = new PortletSessionImpl(
- hsession,
- windowContext.getId(),
- portletApp.getPortletContext());
+ psession = new PortletSessionImpl(hsession, windowContext.getId(),
portletApp.getPortletContext());
}
}
- else if (!psession.isValid())
- {
- // If we don't create and the underlying http session is not valid we return
null
- psession = null;
- }
//
return psession;
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java 2008-02-03
02:13:01 UTC (rev 9719)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -50,19 +50,11 @@
/** . */
private PortletContext context;
- /** . */
- private HttpPortletSession applicationScopedHttpSession;
-
- /** . */
- private HttpPortletSession portletScopedHttpSession;
-
public PortletSessionImpl(HttpSession session, String id, PortletContext context)
{
this.session = session;
this.prefix = "javax.portlet.p." + id + "?";
this.context = context;
- this.applicationScopedHttpSession = null;
- this.portletScopedHttpSession = null;
}
public Object getAttribute(String s)
@@ -159,9 +151,6 @@
{
// Invalidate the underlying HTTP session
session.invalidate();
-
- // Mark the session as invalid
- // valid = false;
}
public boolean isNew()
@@ -226,35 +215,6 @@
}
/**
- * Returns the an implementation of
<code>javax.servlet.http.HttpSession</code> that wraps this
- * portlet session and use the specified scope for manipulating attributes. This
session is used
- * during the request dispatch to a servlet.
- *
- * @param scope the scope
- * @return the wrapped session
- */
- public HttpSession getHttpSession(int scope)
- {
- switch (scope)
- {
- case APPLICATION_SCOPE:
- if (applicationScopedHttpSession == null)
- {
- applicationScopedHttpSession = new HttpPortletSession(this,
APPLICATION_SCOPE);
- }
- return applicationScopedHttpSession;
- case PORTLET_SCOPE:
- if (portletScopedHttpSession == null)
- {
- portletScopedHttpSession = new HttpPortletSession(this, PORTLET_SCOPE);
- }
- return portletScopedHttpSession;
- default:
- throw new IllegalArgumentException("Unrecognzed session scope " +
scope);
- }
- }
-
- /**
* Detect validity of the session based on the underlying session.
*
* @return true if the session is valid
@@ -271,108 +231,4 @@
return false;
}
}
-
- private static class HttpPortletSession implements HttpSession
- {
-
- /** . */
- private final PortletSessionImpl delegate;
-
- /** . */
- private final int scope;
-
- private HttpPortletSession(PortletSessionImpl delegate, int scope)
- {
- this.delegate = delegate;
- this.scope = scope;
- }
-
- public long getCreationTime()
- {
- return delegate.getCreationTime();
- }
-
- public String getId()
- {
- return delegate.getId();
- }
-
- public long getLastAccessedTime()
- {
- return delegate.getLastAccessedTime();
- }
-
- public ServletContext getServletContext()
- {
- return delegate.session.getServletContext();
- }
-
- public void setMaxInactiveInterval(int i)
- {
- delegate.setMaxInactiveInterval(i);
- }
-
- public int getMaxInactiveInterval()
- {
- return delegate.getMaxInactiveInterval();
- }
-
- public HttpSessionContext getSessionContext()
- {
- throw new UnsupportedOperationException();
- }
-
- public Object getAttribute(String s)
- {
- return delegate.getAttribute(s, scope);
- }
-
- public Object getValue(String s)
- {
- return getAttribute(s);
- }
-
- public Enumeration getAttributeNames()
- {
- return delegate.getAttributeNames(scope);
- }
-
- public String[] getValueNames()
- {
- ArrayList<String> names = Collections.list(delegate.getAttributeNames());
-
- //
- return names.toArray(new String[names.size()]);
- }
-
- public void setAttribute(String s, Object o)
- {
- delegate.setAttribute(s, o, scope);
- }
-
- public void putValue(String s, Object o)
- {
- setAttribute(s, o);
- }
-
- public void removeAttribute(String s)
- {
- delegate.removeAttribute(s, scope);
- }
-
- public void removeValue(String s)
- {
- removeAttribute(s);
- }
-
- public void invalidate()
- {
- delegate.invalidate();
- }
-
- public boolean isNew()
- {
- return delegate.isNew();
- }
- }
}
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/HTTPSessionInvalidationInvalidesPortletSessionTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/HTTPSessionInvalidationInvalidesPortletSessionTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/HTTPSessionInvalidationInvalidesPortletSessionTestCase.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -0,0 +1,95 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.portlet.jsr168.ext.session;
+
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.PortletTestContext;
+import org.jboss.portal.unit.annotations.TestCase;
+import org.jboss.portal.unit.actions.PortletRenderTestAction;
+import org.jboss.portal.test.portlet.framework.UTP1;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+import static org.jboss.unit.api.Assert.*;
+
+import javax.portlet.Portlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletSession;
+import javax.servlet.http.HttpSessionBindingListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@TestCase
+public class HTTPSessionInvalidationInvalidesPortletSessionTestCase
+{
+
+ public HTTPSessionInvalidationInvalidesPortletSessionTestCase(PortletTestCase seq)
+ {
+ seq.bindAction(0, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ PortletSession session = request.getPortletSession();
+
+ // Invalidates the real http session
+ SessionInvalidator invalidator = new SessionInvalidator();
+ invalidator.invalidate(session);
+
+ // Now it should be null
+ session = request.getPortletSession(false);
+ assertNull(session);
+
+ //
+ return new EndTestResponse();
+ }
+ });
+ }
+
+ private static class SessionInvalidator implements HttpSessionBindingListener
+ {
+
+ /** . */
+ private HttpSession realSession;
+
+ public void valueBound(HttpSessionBindingEvent event)
+ {
+ this.realSession = event.getSession();
+ }
+
+ public void valueUnbound(HttpSessionBindingEvent event)
+ {
+ }
+
+ public void invalidate(PortletSession session)
+ {
+ session.setAttribute("foo", this);
+ realSession.invalidate();
+ }
+ }
+}
\ No newline at end of file
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/ObtainNonNullSessionUsingCreateEqualsFalseTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/ObtainNonNullSessionUsingCreateEqualsFalseTestCase.java 2008-02-03
02:13:01 UTC (rev 9719)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/ObtainNonNullSessionUsingCreateEqualsFalseTestCase.java 2008-02-03
11:59:52 UTC (rev 9720)
@@ -52,6 +52,10 @@
@TestCase
public class ObtainNonNullSessionUsingCreateEqualsFalseTestCase
{
+
+ /** . */
+ private String sessionId;
+
public ObtainNonNullSessionUsingCreateEqualsFalseTestCase(PortletTestCase seq)
{
seq.bindAction(0, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
@@ -60,9 +64,9 @@
{
PortletSession session = request.getPortletSession();
assertNotNull(session);
+ sessionId = session.getId();
session.setAttribute("foo_1", "bar_1");
- InvokeGetResponse igr = new
InvokeGetResponse(response.createActionURL().toString());
- return igr;
+ return new InvokeGetResponse(response.createActionURL().toString());
}
});
seq.bindAction(1, UTP1.ACTION_JOIN_POINT, new PortletActionTestAction()
@@ -71,6 +75,7 @@
{
PortletSession session = request.getPortletSession(false);
assertNotNull(session);
+ assertEquals(sessionId, session.getId());
assertEquals("bar_1", session.getAttribute("foo_1"));
session.setAttribute("foo_2", "bar_2");
}
@@ -81,6 +86,7 @@
{
PortletSession session = request.getPortletSession(false);
assertNotNull(session);
+ assertEquals(sessionId, session.getId());
assertEquals("bar_1", session.getAttribute("foo_1"));
assertEquals("bar_2", session.getAttribute("foo_2"));
return new EndTestResponse();