1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.dispatcher;
18
19 import java.io.IOException;
20
21 import javax.servlet.RequestDispatcher;
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import javax.portlet.PortletRequestDispatcher;
26 import javax.portlet.RenderResponse;
27 import javax.portlet.RenderRequest;
28 import javax.portlet.PortletException;
29
30 import org.apache.jetspeed.container.PortletDispatcherIncludeAware;
31 import org.apache.pluto.core.impl.RenderRequestImpl;
32 import org.apache.pluto.core.impl.RenderResponseImpl;
33
34 /***
35 * Implements the Portlet API Request Dispatcher to dispatch to portlets
36 *
37 * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
38 * @version $Id: JetspeedRequestDispatcher.java 516448 2007-03-09 16:25:47Z ate $
39 */
40 public class JetspeedRequestDispatcher implements PortletRequestDispatcher
41 {
42 private RequestDispatcher requestDispatcher;
43
44 public JetspeedRequestDispatcher(RequestDispatcher requestDispatcher)
45 {
46 if(requestDispatcher == null)
47 {
48 throw new IllegalArgumentException("RequestDispatcher cannot be null for JetspeedRequestDispatcher.");
49 }
50 this.requestDispatcher = requestDispatcher;
51 }
52
53
54
55 public void include(RenderRequest request, RenderResponse response) throws PortletException, java.io.IOException
56 {
57 HttpServletRequest servletRequest = null;
58 HttpServletResponse servletResponse = null;
59 try
60 {
61 servletRequest = (HttpServletRequest) ((RenderRequestImpl) request).getRequest();
62 servletResponse = (HttpServletResponse) ((RenderResponseImpl) response).getResponse();
63
64 if ( servletRequest instanceof PortletDispatcherIncludeAware )
65 {
66 ((PortletDispatcherIncludeAware)servletRequest).setPortletDispatcherIncluded(true);
67 }
68 if ( servletResponse instanceof PortletDispatcherIncludeAware )
69 {
70 ((PortletDispatcherIncludeAware)servletResponse).setPortletDispatcherIncluded(true);
71 }
72
73 this.requestDispatcher.include(servletRequest, servletResponse);
74
75 }
76 catch (RuntimeException re)
77 {
78
79
80 throw re;
81 }
82 catch (IOException ioe)
83 {
84
85
86 throw ioe;
87 }
88 catch (Exception e)
89 {
90
91
92
93
94 Throwable rootCause = null;
95 if ( e instanceof ServletException)
96 {
97 rootCause = ((ServletException)e).getRootCause();
98 }
99 else
100 {
101 rootCause = e.getCause();
102 }
103 throw new PortletException(rootCause != null ? rootCause : e);
104 }
105 finally
106 {
107 if ( servletRequest != null && servletRequest instanceof PortletDispatcherIncludeAware )
108 {
109 ((PortletDispatcherIncludeAware)servletRequest).setPortletDispatcherIncluded(false);
110 }
111 if ( servletResponse != null && servletResponse instanceof PortletDispatcherIncludeAware )
112 {
113 ((PortletDispatcherIncludeAware)servletResponse).setPortletDispatcherIncluded(false);
114 }
115
116 }
117 }
118 }