Author: julien(a)jboss.com
Date: 2008-01-29 18:20:28 -0500 (Tue, 29 Jan 2008)
New Revision: 9637
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ForwardedContainerAttributesTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/IncludedContainerAttributesTestCase.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/ContentBuffer.java
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/api/PortletRequestDispatcherImpl.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java
Log:
- use an hybrid approach for request dispatching support of forward/include
- added test case for forward container request attributes
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/ContentBuffer.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/ContentBuffer.java 2008-01-29
17:12:14 UTC (rev 9636)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/ContentBuffer.java 2008-01-29
23:20:28 UTC (rev 9637)
@@ -227,10 +227,10 @@
*/
public void commit() throws IllegalStateException
{
- if (contentType == null)
- {
- throw new IllegalStateException("No content type defined");
- }
+// if (contentType == null)
+// {
+// throw new IllegalStateException("No content type defined");
+// }
commited = true;
}
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-01-29
17:12:14 UTC (rev 9636)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java 2008-01-29
23:20:28 UTC (rev 9637)
@@ -43,6 +43,9 @@
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+import java.util.Iterator;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
import java.io.BufferedReader;
@@ -68,11 +71,15 @@
private static final int QUERY_STRING = 3;
/** . */
+ private static final int CONTEXT_PATH = 4;
+
+ /** . */
private static final String[] INCLUDE_KEYS = {
"javax.servlet.include.request_uri",
"javax.servlet.include.servlet_path",
"javax.servlet.include.path_info",
- "javax.servlet.include.query_string"
+ "javax.servlet.include.query_string",
+ "javax.servlet.include.context_path"
};
/** . */
@@ -80,7 +87,8 @@
"javax.servlet.forward.request_uri",
"javax.servlet.forward.servlet_path",
"javax.servlet.forward.path_info",
- "javax.servlet.forward.query_string"
+ "javax.servlet.forward.query_string",
+ "javax.servlet.forward.context_path"
};
/** . */
@@ -96,9 +104,12 @@
private final Map<String, String[]> parameters;
/** . */
- private final String[] keys;
+ private final String[] containerKeys;
/** . */
+ private final Map<String, String> containerAttrs;
+
+ /** . */
private final int sessionScope = PortletSession.APPLICATION_SCOPE;
public DispatchedHttpServletRequest(
@@ -113,41 +124,57 @@
this.dispatchType = dispatchType;
this.preq = preq;
this.dreq = dreq;
- this.keys = dispatchType == DispatchType.INCLUDE ? INCLUDE_KEYS : FORWARD_KEYS;
+ this.containerKeys = dispatchType == DispatchType.INCLUDE ? INCLUDE_KEYS :
FORWARD_KEYS;
//
if (path != null)
{
+ String servletPath;
+ String pathInfo;
String queryString;
-
- //
int endOfServletPath = path.indexOf('/', 1);
if (endOfServletPath == -1)
{
endOfServletPath = path.indexOf('?', 1);
if (endOfServletPath == -1)
{
+ servletPath = path;
+ pathInfo = "";
queryString = "";
}
else
{
+ servletPath = path.substring(0, endOfServletPath);
+ pathInfo = "";
queryString = path.substring(endOfServletPath + 1);
}
}
else
{
+ servletPath = path.substring(0, endOfServletPath);
int endOfPathInfo = path.indexOf('?', endOfServletPath + 1);
if (endOfPathInfo == -1)
{
+ pathInfo = path.substring(endOfServletPath);
queryString = "";
}
else
{
+ pathInfo = path.substring(endOfServletPath, endOfPathInfo);
queryString = path.substring(endOfPathInfo + 1);
}
}
+ String requestURI = preq.getContextPath() + servletPath + pathInfo;
//
+ Map<String, String> attrs = new HashMap<String, String>();
+ attrs.put(containerKeys[SERVLET_PATH], servletPath);
+ attrs.put(containerKeys[PATH_INFO], pathInfo);
+ attrs.put(containerKeys[QUERY_STRING], queryString);
+ attrs.put(containerKeys[REQUEST_URI], requestURI);
+ attrs.put(containerKeys[CONTEXT_PATH], preq.getContextPath());
+
+ //
if (queryString.length() > 0)
{
ParameterMap tmp = new ParameterMap();
@@ -155,15 +182,18 @@
tmp.append(preq.getParameterMap());
//
+ this.containerAttrs = attrs;
this.parameters = tmp;
}
else
{
+ this.containerAttrs = Collections.emptyMap();
this.parameters = preq.getParameterMap();
}
}
else
{
+ this.containerAttrs = Collections.emptyMap();
this.parameters = preq.getParameterMap();
}
}
@@ -216,7 +246,7 @@
public final String getPathInfo()
{
- return (String)getAttribute(keys[PATH_INFO]);
+ return (String)getAttribute(containerKeys[PATH_INFO]);
}
public final String getPathTranslated()
@@ -226,17 +256,17 @@
public final String getQueryString()
{
- return (String)getAttribute(keys[QUERY_STRING]);
+ return (String)getAttribute(containerKeys[QUERY_STRING]);
}
public final String getRequestURI()
{
- return (String)getAttribute(keys[REQUEST_URI]);
+ return (String)getAttribute(containerKeys[REQUEST_URI]);
}
public final String getServletPath()
{
- return (String)getAttribute(keys[SERVLET_PATH]);
+ return (String)getAttribute(containerKeys[SERVLET_PATH]);
}
// Must be equivalent to the method of the PortletRequest
@@ -258,22 +288,78 @@
public final Object getAttribute(String s)
{
+ if (containerAttrs.containsKey(s))
+ {
+ return containerAttrs.get(s);
+ }
+
+ //
return preq.getAttributes().getAttribute(s, (HttpServletRequest)getRequest());
}
public final Enumeration getAttributeNames()
{
- return
Tools.toEnumeration(preq.getAttributes().getAttributeNames((HttpServletRequest)getRequest()));
+ final Iterator<String> i =
preq.getAttributes().getAttributeNames((HttpServletRequest)getRequest());
+
+ //
+ return new Enumeration()
+ {
+ // The next element
+ String next;
+
+ {
+ next();
+ }
+
+ public boolean hasMoreElements()
+ {
+ return next != null;
+ }
+
+ public Object nextElement()
+ {
+ Object next = this.next;
+ next();
+ return next;
+ }
+
+ private void next()
+ {
+ next = null;
+ while (true)
+ {
+ if (i.hasNext())
+ {
+ String next = i.next();
+ if (!containerAttrs.containsKey(next))
+ {
+ this.next = next;
+ break;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ };
}
public final void setAttribute(String s, Object o)
{
- preq.getAttributes().setAttribute(s, o);
+ if (s != null && !containerAttrs.containsKey(s))
+ {
+ preq.getAttributes().setAttribute(s, o);
+ }
}
public final void removeAttribute(String s)
{
- preq.getAttributes().removeAttribute(s);
+ if (s != null && !containerAttrs.containsKey(s))
+ {
+ preq.getAttributes().removeAttribute(s);
+ }
}
public final Locale getLocale()
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-01-29
17:12:14 UTC (rev 9636)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java 2008-01-29
23:20:28 UTC (rev 9637)
@@ -189,14 +189,14 @@
{
/** . */
- private final StateAwareResponseImpl mresp;
+ private final StateAwareResponseImpl saresp;
- public StateAware(DispatchedHttpServletRequest req, StateAwareResponseImpl mresp,
HttpServletResponse dresp)
+ public StateAware(DispatchedHttpServletRequest req, StateAwareResponseImpl saresp,
HttpServletResponse dresp)
{
- super(req, mresp, dresp);
+ super(req, saresp, dresp);
//
- this.mresp = mresp;
+ this.saresp = saresp;
}
// Must return null
@@ -275,11 +275,11 @@
{
}
- // Must return true
+ // Must return true for include and false for forward
public boolean isCommitted()
{
- return true;
+ return req.dispatchType == DispatchType.INCLUDE;
}
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestDispatcherImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestDispatcherImpl.java 2008-01-29
17:12:14 UTC (rev 9636)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestDispatcherImpl.java 2008-01-29
23:20:28 UTC (rev 9637)
@@ -127,6 +127,13 @@
dispatcher.include(direq, diresp);
break;
case FORWARD:
+// diresp.resetBuffer();
+//
+// //
+// dispatcher.include(direq, diresp);
+//
+// // Flush
+// diresp.flushBuffer();
dispatcher.forward(direq, diresp);
break;
}
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java 2008-01-29
17:12:14 UTC (rev 9636)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java 2008-01-29
23:20:28 UTC (rev 9637)
@@ -32,13 +32,10 @@
import org.jboss.portal.unit.actions.PortletResourceTestAction;
import org.jboss.portal.test.portlet.framework.UTP1;
import org.jboss.portal.test.portlet.framework.UTS1;
-import org.jboss.portal.unit.annotations.TestCase;
-import org.jboss.portal.unit.Assertion;
+import org.jboss.portal.common.util.Tools;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.response.EndTestResponse;
-import static org.jboss.unit.api.Assert.assertNotNull;
import static org.jboss.unit.api.Assert.assertEquals;
-import static org.jboss.unit.api.Assert.assertNull;
import org.jboss.unit.remote.driver.handler.http.response.InvokeGetResponse;
import javax.portlet.Portlet;
@@ -59,13 +56,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.util.List;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-(a)TestCase({Assertion.JSR168_127})
-public class DispatchedContainerAttributesTestCase
+public abstract class DispatchedContainerAttributesTestCase
{
private Object requestURI;
@@ -124,15 +121,24 @@
seq.bindAction(2, UTS1.SERVICE_JOIN_POINT, service);
}
- private void checkAttributes(Portlet portlet, PortletRequest request, PortletResponse
response) throws PortletException, IOException
+ protected abstract void dispatch(PortletRequestDispatcher dispatcher, PortletRequest
request, PortletResponse response) throws IOException, PortletException;
+
+ protected abstract String getDispatchType();
+
+ private void checkAttributes(
+ Portlet portlet,
+ PortletRequest request,
+ PortletResponse response) throws PortletException, IOException
{
//assert that servlet HAS access to specific request attributes
try
{
PortletRequestDispatcher dispatcher =
((AbstractUniversalTestPortlet)portlet).getPortletContext().getRequestDispatcher("/universalServletA/pathinfo?foo=bar");
- dispatcher.include(request, response);
//
+ dispatch(dispatcher, request, response);
+
+ //
assertEquals("/test-jsr286-tck-dispatcher/universalServletA/pathinfo",
requestURI);
assertEquals("/test-jsr286-tck-dispatcher", contextPath);
assertEquals("/universalServletA", servletPath);
@@ -153,9 +159,11 @@
try
{
PortletRequestDispatcher dispatcher =
((AbstractUniversalTestPortlet)portlet).getPortletContext().getNamedDispatcher("UniversalServletA");
- dispatcher.include(request, response);
//
+ dispatch(dispatcher, request, response);
+
+ //
assertEquals(null, requestURI);
assertEquals(null, contextPath);
assertEquals(null, servletPath);
@@ -176,12 +184,14 @@
{
protected DriverResponse run(Servlet servlet, HttpServletRequest request,
HttpServletResponse response, PortletTestContext context) throws ServletException,
IOException
{
- requestURI =
request.getAttribute("javax.servlet.include.request_uri");
- contextPath =
request.getAttribute("javax.servlet.include.context_path");
- servletPath =
request.getAttribute("javax.servlet.include.servlet_path");
- pathInfo = request.getAttribute("javax.servlet.include.path_info");
- queryString =
request.getAttribute("javax.servlet.include.query_string");
+ String dispatchType = getDispatchType();
+ requestURI = request.getAttribute("javax.servlet." + dispatchType +
".request_uri");
+ contextPath = request.getAttribute("javax.servlet." + dispatchType +
".context_path");
+ servletPath = request.getAttribute("javax.servlet." + dispatchType +
".servlet_path");
+ pathInfo = request.getAttribute("javax.servlet." + dispatchType +
".path_info");
+ queryString = request.getAttribute("javax.servlet." + dispatchType +
".query_string");
+
//
return null;
}
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ForwardedContainerAttributesTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ForwardedContainerAttributesTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ForwardedContainerAttributesTestCase.java 2008-01-29
23:20:28 UTC (rev 9637)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * 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.jsr286.tck.dispatcher;
+
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.Assertion;
+import org.jboss.portal.unit.annotations.TestCase;
+
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@TestCase
+public class ForwardedContainerAttributesTestCase extends
DispatchedContainerAttributesTestCase
+{
+ public ForwardedContainerAttributesTestCase(PortletTestCase seq)
+ {
+ super(seq);
+ }
+
+ protected void dispatch(PortletRequestDispatcher dispatcher, PortletRequest request,
PortletResponse response) throws IOException, PortletException
+ {
+ dispatcher.forward(request, response);
+ }
+
+ protected String getDispatchType()
+ {
+ return "forward";
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/IncludedContainerAttributesTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/IncludedContainerAttributesTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/IncludedContainerAttributesTestCase.java 2008-01-29
23:20:28 UTC (rev 9637)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * 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.jsr286.tck.dispatcher;
+
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.Assertion;
+import org.jboss.portal.unit.annotations.TestCase;
+
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+(a)TestCase({Assertion.JSR168_127})
+public class IncludedContainerAttributesTestCase extends
DispatchedContainerAttributesTestCase
+{
+ public IncludedContainerAttributesTestCase(PortletTestCase seq)
+ {
+ super(seq);
+ }
+
+ protected void dispatch(PortletRequestDispatcher dispatcher, PortletRequest request,
PortletResponse response) throws IOException, PortletException
+ {
+ dispatcher.include(request, response);
+ }
+
+ protected String getDispatchType()
+ {
+ return "include";
+ }
+}