Author: julien(a)jboss.com
Date: 2007-04-02 19:11:59 -0400 (Mon, 02 Apr 2007)
New Revision: 6903
Added:
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/dispatcher/DispatchingFilter.java
trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/dispatchedFromFilter.jsp
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/dispatcher/DispatcherSequenceBuilder.java
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/tck/dispatcher/DispatcherSequenceBuilder.java
trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/WEB-INF/portlet.xml
trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/WEB-INF/web.xml
trunk/portlet/src/resources/test/jsr168/tck/dispatcher-war/WEB-INF/web.xml
Log:
- improving implementation request dispatching from portlet to servlet
- added more test cases for the request dispatching from portlet to servlet
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java 2007-04-02
21:41:23 UTC (rev 6902)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java 2007-04-02
23:11:59 UTC (rev 6903)
@@ -37,12 +37,9 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
-import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import java.util.Iterator;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -60,7 +57,6 @@
private RenderRequestImpl rreq;
private HttpServletRequest dreq;
- private final Map attrs;
private final Map parameters;
public DispatchedHttpServletRequest(
@@ -77,8 +73,6 @@
//
if (path != null)
{
- String servletPath;
- String pathInfo;
String queryString;
int endOfServletPath = path.indexOf('/', 1);
@@ -87,44 +81,27 @@
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 = rreq.getContextPath() + servletPath + pathInfo;
//
- Map attrs = new HashMap(5);
- attrs.put(CONTEXT_PATH, rreq.getContextPath());
- attrs.put(SERVLET_PATH, servletPath);
- attrs.put(PATH_INFO, pathInfo);
- attrs.put(QUERY_STRING, queryString);
- attrs.put(REQUEST_URI, requestURI);
- this.attrs = Collections.unmodifiableMap(attrs);
-
- //
if (queryString.length() > 0)
{
this.parameters = new PortletParameters(rreq.getParameterMap());
@@ -137,7 +114,6 @@
}
else
{
- this.attrs = Collections.EMPTY_MAP;
this.parameters = rreq.getParameterMap();
}
}
@@ -173,22 +149,22 @@
public String getPathInfo()
{
- return (String)attrs.get(PATH_INFO);
+ return (String)getAttribute(PATH_INFO);
}
public String getQueryString()
{
- return (String)attrs.get(QUERY_STRING);
+ return (String)getAttribute(QUERY_STRING);
}
public String getServletPath()
{
- return (String)attrs.get(SERVLET_PATH);
+ return (String)getAttribute(SERVLET_PATH);
}
public String getRequestURI()
{
- return (String)attrs.get(REQUEST_URI);
+ return (String)getAttribute(REQUEST_URI);
}
public String getPathTranslated()
@@ -216,11 +192,11 @@
public Object getAttribute(String s)
{
// First try the special values
- Object value = attrs.get(s);
- if (value != null)
- {
- return value;
- }
+// Object value = attrs.get(s);
+// if (value != null)
+// {
+// return value;
+// }
// Otherwise try the render request modified attributes
return rreq.getAttributes().getAttribute(s, (HttpServletRequest)getRequest());
@@ -228,49 +204,49 @@
public Enumeration getAttributeNames()
{
- final Iterator i =
rreq.getAttributes().getAttributeNames((HttpServletRequest)getRequest());
- return new Enumeration()
- {
- // The next element
- Object 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())
- {
- Object next = i.next();
- if (attrs != null && !attrs.containsKey(next))
- {
- this.next = next;
- break;
- }
- }
- else
- {
- break;
- }
- }
- }
- };
+ return
Tools.toEnumeration(rreq.getAttributes().getAttributeNames((HttpServletRequest)getRequest()));
+// return new Enumeration()
+// {
+// // The next element
+// Object 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())
+// {
+// Object next = i.next();
+// if (attrs != null && !attrs.containsKey(next))
+// {
+// this.next = next;
+// break;
+// }
+// }
+// else
+// {
+// break;
+// }
+// }
+// }
+// };
}
public void setAttribute(String s, Object o)
@@ -305,7 +281,7 @@
public String getContextPath()
{
- return (String)attrs.get(CONTEXT_PATH);
+ return (String)getAttribute(CONTEXT_PATH);
}
public String getRemoteUser()
Modified:
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/dispatcher/DispatcherSequenceBuilder.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/dispatcher/DispatcherSequenceBuilder.java 2007-04-02
21:41:23 UTC (rev 6902)
+++
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/dispatcher/DispatcherSequenceBuilder.java 2007-04-02
23:11:59 UTC (rev 6903)
@@ -37,6 +37,7 @@
import org.jboss.portal.test.portlet.framework.UTP1;
import org.jboss.portal.test.portlet.framework.UTS1;
import org.jboss.portal.test.portlet.framework.UTP2;
+import org.jboss.portal.test.portlet.framework.UTP3;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
@@ -140,10 +141,10 @@
});
}
- public void createBlah(PortletTestDriver registry)
+ public void createFilters(PortletTestDriver registry)
{
PortletTest seq = new PortletTest();
- registry.addSequence("Blah", seq);
+ registry.addSequence("Filters", seq);
seq.addAction(0, UTP2.RENDER_JOINPOINT, new PortletRenderTestAction()
{
protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
@@ -166,4 +167,32 @@
}
});
}
+
+ public void createDispatchingFilter(PortletTestDriver registry)
+ {
+ PortletTest seq = new PortletTest();
+ registry.addSequence("DispatchingFilter", seq);
+ seq.addAction(0, UTP3.RENDER_JOINPOINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
+ {
+
+ // Need to set content type as we will include a JSP that will produce
output
+ response.setContentType("text/html");
+
+ //
+ PortletRequestDispatcher prd =
request.getPortletSession().getPortletContext().getNamedDispatcher("TargetForIncludeNamedDispatchingFilter");
+ assertNotNull(prd);
+ prd.include(request, response);
+
+ //
+ prd =
request.getPortletSession().getPortletContext().getRequestDispatcher("/TargetForIncludeURLPatternDispatchingFilter");
+ assertNotNull(prd);
+ prd.include(request, response);
+
+ //
+ return new EndTestResponse();
+ }
+ });
+ }
}
Added:
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/dispatcher/DispatchingFilter.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/dispatcher/DispatchingFilter.java
(rev 0)
+++
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/dispatcher/DispatchingFilter.java 2007-04-02
23:11:59 UTC (rev 6903)
@@ -0,0 +1,67 @@
+/******************************************************************************
+ * 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.dispatcher;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.FilterChain;
+import javax.servlet.RequestDispatcher;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class DispatchingFilter implements Filter
+{
+
+ private FilterConfig cfg;
+
+ public void init(FilterConfig cfg) throws ServletException
+ {
+ this.cfg = cfg;
+ }
+
+ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
throws IOException, ServletException
+ {
+
+ System.out.println("In the CHAIN " + cfg.getFilterName());
+ System.out.println("In the CHAIN " + cfg.getFilterName());
+ System.out.println("In the CHAIN " + cfg.getFilterName());
+ System.out.println("In the CHAIN " + cfg.getFilterName());
+ System.out.println("In the CHAIN " + cfg.getFilterName());
+ System.out.println("In the CHAIN " + cfg.getFilterName());
+
+ RequestDispatcher rd =
cfg.getServletContext().getRequestDispatcher("/dispatchedFromFilter.jsp");
+ rd.include(req, resp);
+
+ }
+
+ public void destroy()
+ {
+ this.cfg = null;
+ }
+}
Modified:
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/tck/dispatcher/DispatcherSequenceBuilder.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/tck/dispatcher/DispatcherSequenceBuilder.java 2007-04-02
21:41:23 UTC (rev 6902)
+++
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/tck/dispatcher/DispatcherSequenceBuilder.java 2007-04-02
23:11:59 UTC (rev 6903)
@@ -274,18 +274,18 @@
{
protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
{
- PortletRequestDispatcher dispatcher =
((AbstractUniversalTestPortlet)portlet).getPortletContext().getRequestDispatcher("/universalServletA");
+ PortletRequestDispatcher dispatcher =
((AbstractUniversalTestPortlet)portlet).getPortletContext().getRequestDispatcher("/universalServletA/pathinfo?foo=bar");
assertNotNull(dispatcher);
//assert that servlet HAS access to specific request attributes
try
{
dispatcher.include(request, response);
- assertNotNull(UTP1.local1.get());
- assertNotNull(UTP1.local2.get());
- assertNotNull(UTP1.local3.get());
- // assertNotNull(IncludedRequestParametersPortlet.local4.get());
- // assertNotNull(IncludedRequestParametersPortlet.local5.get());
+
assertEquals("/test-jsr168-dispatcher/universalServletA/pathinfo",
UTP1.local1.get());
+ assertEquals("/test-jsr168-dispatcher", UTP1.local2.get());
+ assertEquals("/universalServletA", UTP1.local3.get());
+ assertEquals("/pathinfo", UTP1.local4.get());
+ assertEquals("foo=bar", UTP1.local5.get());
}
finally
{
@@ -296,25 +296,12 @@
UTP1.local5.set(null);
}
- //assert that keys are present in request properties
- Enumeration names = request.getPropertyNames();
- List namesList = new LinkedList();
- while (names.hasMoreElements())
- {
- namesList.add(names.nextElement());
- }
-
/*assertTrue(namesList.contains("javax.servlet.include.request_uri"));
-
assertTrue(namesList.contains("javax.servlet.include.context_path"));
-
assertTrue(namesList.contains("javax.servlet.include.servlet_path"));
- assertTrue(namesList.contains("javax.servlet.include.path_info"));
-
assertTrue(namesList.contains("javax.servlet.include.query_string"));*/
-
-
+ //
dispatcher =
((AbstractUniversalTestPortlet)portlet).getPortletContext().getNamedDispatcher("UniversalServletA");
assertNotNull(dispatcher);
- //assert that servlet has NO access to specific request attributes
- //it shouldn't access that attributes because getNamedDispatcher was
used
+ // Assert that servlet has NO access to specific request attributes
+ // it shouldn't access that attributes because getNamedDispatcher was
used
try
{
dispatcher.include(request, response);
@@ -333,18 +320,6 @@
UTP1.local5.set(null);
}
- //assert that keys are not present in request properties
- names = request.getPropertyNames();
- namesList = new LinkedList();
- while (names.hasMoreElements())
- {
- namesList.add(names.nextElement());
- }
-
assertTrue(!namesList.contains("javax.servlet.include.request_uri"));
-
assertTrue(!namesList.contains("javax.servlet.include.context_path"));
-
assertTrue(!namesList.contains("javax.servlet.include.servlet_path"));
-
assertTrue(!namesList.contains("javax.servlet.include.path_info"));
-
assertTrue(!namesList.contains("javax.servlet.include.query_string"));
return new EndTestResponse();
}
});
@@ -480,7 +455,7 @@
assertNull(request.getRequestURL());
//SPEC:130
- assertEquals("", request.getPathInfo());
+ assertEquals(null, request.getPathInfo());
//TODO:I'm not sure what this should return - but it's not
implemented now so it fails
//assertEquals("",request.getPathTranslated());
assertEquals("key1=k1value1&key2=k2value1",
request.getQueryString());
Modified: trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/WEB-INF/portlet.xml
===================================================================
---
trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/WEB-INF/portlet.xml 2007-04-02
21:41:23 UTC (rev 6902)
+++
trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/WEB-INF/portlet.xml 2007-04-02
23:11:59 UTC (rev 6903)
@@ -50,4 +50,15 @@
</portlet-info>
</portlet>
+ <portlet>
+ <portlet-name>TestUniversalPortletC</portlet-name>
+
<portlet-class>org.jboss.portal.test.portlet.framework.UTP3</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ <portlet-info>
+ <title></title>
+ </portlet-info>
+ </portlet>
+
</portlet-app>
Modified: trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/WEB-INF/web.xml
===================================================================
--- trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/WEB-INF/web.xml 2007-04-02
21:41:23 UTC (rev 6902)
+++ trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/WEB-INF/web.xml 2007-04-02
23:11:59 UTC (rev 6903)
@@ -82,6 +82,24 @@
</init-param>
</filter>
+ <filter>
+ <filter-name>IncludeNamedJSPDispatchingFilter</filter-name>
+
<filter-class>org.jboss.portal.test.portlet.jsr168.ext.dispatcher.DispatchingFilter</filter-class>
+ <init-param>
+ <param-name>id</param-name>
+ <param-value>INCLUDE_NAMED_FILTER</param-value>
+ </init-param>
+ </filter>
+
+ <filter>
+ <filter-name>IncludeURLPatternJSPDispatchingFilter</filter-name>
+
<filter-class>org.jboss.portal.test.portlet.jsr168.ext.dispatcher.DispatchingFilter</filter-class>
+ <init-param>
+ <param-name>id</param-name>
+ <param-value>INCLUDE_URL_PATTERN_FILTER</param-value>
+ </init-param>
+ </filter>
+
<filter-mapping>
<filter-name>IncludeURLPatternFilter</filter-name>
<url-pattern>/noop</url-pattern>
@@ -118,6 +136,18 @@
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
+ <filter-mapping>
+ <filter-name>IncludeNamedJSPDispatchingFilter</filter-name>
+ <servlet-name>TargetForIncludeNamedDispatchingFilter</servlet-name>
+ <dispatcher>INCLUDE</dispatcher>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>IncludeURLPatternJSPDispatchingFilter</filter-name>
+
<url-pattern>/TargetForIncludeURLPatternDispatchingFilter</url-pattern>
+ <dispatcher>INCLUDE</dispatcher>
+ </filter-mapping>
+
<listener>
<listener-class>org.jboss.portal.test.portlet.jsr168.ext.dispatcher.DispatcherSequenceBuilder</listener-class>
</listener>
@@ -132,6 +162,16 @@
<servlet-class>org.jboss.portal.test.portlet.framework.NoopServlet</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>TargetForIncludeNamedDispatchingFilter</servlet-name>
+
<servlet-class>org.jboss.portal.test.portlet.framework.NoopServlet</servlet-class>
+ </servlet>
+
+ <servlet>
+
<servlet-name>TargetForIncludeURLPatternDispatchingFilter</servlet-name>
+
<servlet-class>org.jboss.portal.test.portlet.framework.NoopServlet</servlet-class>
+ </servlet>
+
<servlet-mapping>
<servlet-name>UniversalServletA</servlet-name>
<url-pattern>/universalServletA</url-pattern>
@@ -142,4 +182,9 @@
<url-pattern>/noop</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+
<servlet-name>TargetForIncludeURLPatternDispatchingFilter</servlet-name>
+
<url-pattern>/TargetForIncludeURLPatternDispatchingFilter</url-pattern>
+ </servlet-mapping>
+
</web-app>
Added:
trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/dispatchedFromFilter.jsp
===================================================================
--- trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/dispatchedFromFilter.jsp
(rev 0)
+++
trunk/portlet/src/resources/test/jsr168/ext/dispatcher-war/dispatchedFromFilter.jsp 2007-04-02
23:11:59 UTC (rev 6903)
@@ -0,0 +1,8 @@
+<%@ page language="java" %>
+
+<%
+ System.out.println("HELLO FROM JSP");
+ System.out.println("HELLO FROM JSP");
+ System.out.println("HELLO FROM JSP");
+ System.out.println("HELLO FROM JSP");
+%>
\ No newline at end of file
Modified: trunk/portlet/src/resources/test/jsr168/tck/dispatcher-war/WEB-INF/web.xml
===================================================================
--- trunk/portlet/src/resources/test/jsr168/tck/dispatcher-war/WEB-INF/web.xml 2007-04-02
21:41:23 UTC (rev 6902)
+++ trunk/portlet/src/resources/test/jsr168/tck/dispatcher-war/WEB-INF/web.xml 2007-04-02
23:11:59 UTC (rev 6903)
@@ -36,21 +36,9 @@
<servlet-class>org.jboss.portal.test.portlet.framework.UTS1</servlet-class>
</servlet>
- <servlet>
- <servlet-name>UniversalServletB</servlet-name>
-
<servlet-class>org.jboss.portal.test.portlet.framework.UTS2</servlet-class>
- </servlet>
-
<servlet-mapping>
<servlet-name>UniversalServletA</servlet-name>
- <url-pattern>/universalServletA</url-pattern>
+ <url-pattern>/universalServletA/*</url-pattern>
</servlet-mapping>
- <servlet-mapping>
- <servlet-name>UniversalServletB</servlet-name>
- <url-pattern>/universalServletB</url-pattern>
- </servlet-mapping>
-
-
-
</web-app>