KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > impl > PortletRequestDispatcherImpl


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.impl;
10
11 import java.io.IOException JavaDoc;
12
13 import javax.portlet.PortletConfig;
14 import javax.portlet.PortletException;
15 import javax.portlet.PortletRequestDispatcher;
16 import javax.portlet.RenderRequest;
17 import javax.portlet.RenderResponse;
18 import javax.servlet.RequestDispatcher JavaDoc;
19 import javax.servlet.ServletException JavaDoc;
20 import javax.servlet.FilterChain JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
24
25 import org.jboss.portal.portlet.invocation.PortletKey;
26 import org.jboss.portal.server.PortalRequest;
27 import org.jboss.portal.server.PortalResponse;
28 import org.jboss.portal.server.invocation.AttachmentKey;
29 import org.jboss.portal.server.invocation.Invocation;
30 import org.jboss.portal.server.invocation.component.ContextDispatcherInterceptor;
31 import org.jboss.portal.server.servlet.CommandServlet;
32 import org.jboss.portal.server.servlet.FilterCommand;
33 import org.jboss.portal.server.servlet.ServletCommand;
34
35 /**
36  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
37  * @version $Revision: 1.4 $
38  */

39 public class PortletRequestDispatcherImpl
40    implements PortletRequestDispatcher,
41    FilterCommand
42 {
43
44    /** The servlet request dispatcher. */
45    private RequestDispatcher dispatcher;
46
47    /** . */
48    private String JavaDoc path;
49
50    public PortletRequestDispatcherImpl(RequestDispatcher dispatcher)
51    {
52       this(dispatcher, null);
53    }
54
55    public PortletRequestDispatcherImpl(RequestDispatcher dispatcher, String JavaDoc path)
56    {
57       this.dispatcher = dispatcher;
58       this.path = path;
59    }
60
61    public Object JavaDoc execute(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp, FilterChain JavaDoc chain) throws ServletException JavaDoc, IOException JavaDoc
62    {
63       HttpServletRequest JavaDoc wrappedReq = new HttpServletRequestWrapper JavaDoc(req)
64       {
65          public StringBuffer JavaDoc getRequestURL()
66          {
67             // Per the spec
68
return null;
69          }
70       };
71       chain.doFilter(wrappedReq, resp);
72       return null;
73    }
74
75    public void include(RenderRequest req, RenderResponse resp) throws PortletException, IOException JavaDoc
76    {
77       try
78       {
79          // Get the invocation that is still in the request
80
ContextDispatcherInterceptor.InvokeNextCommand cmd = (ContextDispatcherInterceptor.InvokeNextCommand)req.getAttribute(ServletCommand.REQ_ATT_KEY);
81          Invocation invocation = cmd.getInvocation();
82
83          //
84
PortalRequest preq = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST);
85          PortalResponse presp = (PortalResponse)invocation.getAttachment(AttachmentKey.PORTAL_RESPONSE);
86
87          //
88
HttpServletRequest JavaDoc hreq = (HttpServletRequest JavaDoc)invocation.getAttachment(AttachmentKey.DISPATCHED_REQUEST);
89          HttpServletResponse JavaDoc hresp = (HttpServletResponse JavaDoc)invocation.getAttachment(AttachmentKey.DISPATCHED_RESPONSE);
90
91          //
92
DispatchedHttpServletRequest dreq = new DispatchedHttpServletRequest(preq, req, hreq, path);
93          DispatchedHttpServletResponse dresp = new DispatchedHttpServletResponse(presp, resp, hresp);
94
95          //
96
PortletConfig cfg = (PortletConfig)invocation.getAttachment(PortletKey.PORTLET_CONFIG);
97
98          try
99          {
100             //
101

102             // Add
103
/*
104             dreq.setAttribute("javax.portlet.config", cfg);
105             dreq.setAttribute("javax.portlet.request", req);
106             dreq.setAttribute("javax.portlet.response", resp);
107 */

108
109             //
110
dreq.setAttribute(FilterCommand.REQ_ATT_KEY, this);
111
112             //
113
dispatcher.include(dreq, dresp);
114          }
115          finally
116          {
117             //
118
dreq.removeAttribute(FilterCommand.REQ_ATT_KEY);
119
120             // Remove
121
/*
122             dreq.removeAttribute("javax.portlet.config");
123             dreq.removeAttribute("javax.portlet.request");
124             dreq.removeAttribute("javax.portlet.response");
125 */

126          }
127       }
128       catch (ServletException JavaDoc e)
129       {
130          // We must translate the servlet exception into a portlet exception for the calling portlet
131
throw new PortletException(e);
132       }
133    }
134 }
135
Popular Tags