KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > impl > invocation > PortalRequestImpl


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.server.impl.invocation;
10
11 import java.io.BufferedReader JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.UnsupportedEncodingException JavaDoc;
14 import java.security.Principal JavaDoc;
15 import java.util.Enumeration JavaDoc;
16 import java.util.Locale JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import javax.servlet.RequestDispatcher JavaDoc;
20 import javax.servlet.ServletInputStream JavaDoc;
21 import javax.servlet.http.Cookie JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpSession JavaDoc;
24
25 import org.apache.log4j.Logger;
26 import org.jboss.portal.server.PortalRequest;
27 import org.jboss.portal.server.PortalServer;
28 import org.jboss.portal.server.ServerObject;
29 import org.jboss.portal.server.ServerURL;
30 import org.jboss.portal.server.Portal;
31 import org.jboss.portal.server.invocation.AttachmentKey;
32 import org.jboss.portal.server.util.Parameters;
33 import org.jboss.portal.server.util.Properties;
34
35 /**
36  * We implement all the methods of HttpServletRequest instead of inheriting
37  * HttpServletRequestWrapper because of the method getRequest() on the wrapper
38  * that can be used to modify the underlying request. For instance tomcat get its
39  * real request to change some values in the request and we assume in the PortalRequest
40  * implementation that this is immutable.
41  *
42  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
43  * @version $Revision: 1.8 $
44  */

45 public class PortalRequestImpl implements PortalRequest
46 {
47
48    protected static final Logger log = Logger.getLogger(PortalRequestImpl.class);
49
50    /** The real request. */
51    protected final HttpServletRequest JavaDoc req;
52
53    /** The invocation. */
54    protected final InvocationImpl invocation;
55
56    /** The properties. */
57    protected final Properties properties;
58
59    /** The idempotent config of this request. */
60    protected Boolean JavaDoc idempotent;
61
62    public PortalRequestImpl(HttpServletRequest JavaDoc req, InvocationImpl invocation)
63    {
64       this.req = req;
65       this.invocation = invocation;
66       this.properties = new Properties();
67    }
68
69    //
70

71    public PortalServer getServer()
72    {
73       return invocation.container;
74    }
75
76    public Parameters getControlParameters()
77    {
78       return invocation.controlParameters;
79    }
80
81    public Parameters getTargetParameters()
82    {
83       return invocation.targetParameters;
84    }
85
86    public ServerObject getTarget()
87    {
88       return invocation.target;
89    }
90
91    public ServerURL getURL()
92    {
93       return invocation.url;
94    }
95
96    public Properties getProperties()
97    {
98       return properties;
99    }
100
101    public Boolean JavaDoc getIdempotent()
102    {
103       return idempotent;
104    }
105
106    public void setIdempotent(Boolean JavaDoc idempotent)
107    {
108       this.idempotent = idempotent;
109    }
110
111    public Portal getPortal()
112    {
113       return (Portal)invocation.getAttachment(AttachmentKey.PORTAL);
114    }
115
116    // HttpSerlvetRequeset implementation
117

118    public String JavaDoc getAuthType()
119    {
120       return req.getAuthType();
121    }
122
123    public String JavaDoc getContextPath()
124    {
125       return req.getContextPath();
126    }
127
128    public Cookie JavaDoc[] getCookies()
129    {
130       return req.getCookies();
131    }
132
133    public long getDateHeader(String JavaDoc key)
134    {
135       return req.getDateHeader(key);
136    }
137
138    public String JavaDoc getHeader(String JavaDoc key)
139    {
140       return req.getHeader(key);
141    }
142
143    public Enumeration JavaDoc getHeaderNames()
144    {
145       return req.getHeaderNames();
146    }
147
148    public Enumeration JavaDoc getHeaders(String JavaDoc key)
149    {
150       return req.getHeaders(key);
151    }
152
153    public int getIntHeader(String JavaDoc key)
154    {
155       return req.getIntHeader(key);
156    }
157
158    public String JavaDoc getMethod()
159    {
160       return req.getMethod();
161    }
162
163    public String JavaDoc getPathInfo()
164    {
165       // return invocation.pathInfo;
166
return req.getPathInfo();
167    }
168
169    public String JavaDoc getPathTranslated()
170    {
171       return req.getPathTranslated();
172    }
173
174    public String JavaDoc getQueryString()
175    {
176       return req.getQueryString();
177    }
178
179    public String JavaDoc getRemoteUser()
180    {
181       return req.getRemoteUser();
182    }
183
184    public String JavaDoc getRequestedSessionId()
185    {
186       return req.getRequestedSessionId();
187    }
188
189    public String JavaDoc getRequestURI()
190    {
191       return getContextPath() + getServletPath() + getPathInfo();
192    }
193
194    public StringBuffer JavaDoc getRequestURL()
195    {
196       throw new UnsupportedOperationException JavaDoc("todo");
197    }
198
199    public String JavaDoc getServletPath()
200    {
201       return req.getServletPath();
202    }
203
204    public HttpSession JavaDoc getSession()
205    {
206       return req.getSession();
207    }
208
209    public HttpSession JavaDoc getSession(boolean b)
210    {
211       return req.getSession(b);
212    }
213
214    public Principal JavaDoc getUserPrincipal()
215    {
216       return req.getUserPrincipal();
217    }
218
219    public boolean isRequestedSessionIdFromCookie()
220    {
221       return req.isRequestedSessionIdFromCookie();
222    }
223
224    public boolean isRequestedSessionIdFromURL()
225    {
226       return req.isRequestedSessionIdFromURL();
227    }
228
229    public boolean isRequestedSessionIdFromUrl()
230    {
231       return req.isRequestedSessionIdFromUrl();
232    }
233
234    public boolean isRequestedSessionIdValid()
235    {
236       return req.isRequestedSessionIdValid();
237    }
238
239    public boolean isUserInRole(String JavaDoc key)
240    {
241       return req.isUserInRole(key);
242    }
243
244    // ServletRequest implementation
245

246    public Object JavaDoc getAttribute(String JavaDoc key)
247    {
248       return req.getAttribute(key);
249    }
250
251    public Enumeration JavaDoc getAttributeNames()
252    {
253       return req.getAttributeNames();
254    }
255
256    public String JavaDoc getCharacterEncoding()
257    {
258       return req.getCharacterEncoding();
259    }
260
261    public int getContentLength()
262    {
263       return req.getContentLength();
264    }
265
266    public String JavaDoc getContentType()
267    {
268       return req.getContentType();
269    }
270
271    public ServletInputStream JavaDoc getInputStream() throws IOException JavaDoc
272    {
273       return req.getInputStream();
274    }
275
276    public String JavaDoc getLocalAddr()
277    {
278       return req.getLocalAddr();
279    }
280
281    public Locale JavaDoc getLocale()
282    {
283       return req.getLocale();
284    }
285
286    public Enumeration JavaDoc getLocales()
287    {
288       return req.getLocales();
289    }
290
291    public String JavaDoc getLocalName()
292    {
293       return req.getLocalName();
294    }
295
296    public int getLocalPort()
297    {
298       return req.getLocalPort();
299    }
300
301    public String JavaDoc getParameter(String JavaDoc key)
302    {
303       return req.getParameter(key);
304    }
305
306    public Map JavaDoc getParameterMap()
307    {
308       return req.getParameterMap();
309    }
310
311    public Enumeration JavaDoc getParameterNames()
312    {
313       return req.getParameterNames();
314    }
315
316    public String JavaDoc[] getParameterValues(String JavaDoc key)
317    {
318       return req.getParameterValues(key);
319    }
320
321    public String JavaDoc getProtocol()
322    {
323       return req.getProtocol();
324    }
325
326    public BufferedReader JavaDoc getReader() throws IOException JavaDoc
327    {
328       return req.getReader();
329    }
330
331    public String JavaDoc getRealPath(String JavaDoc key)
332    {
333       return req.getRealPath(key);
334    }
335
336    public String JavaDoc getRemoteAddr()
337    {
338       return req.getRemoteAddr();
339    }
340
341    public String JavaDoc getRemoteHost()
342    {
343       return req.getRemoteHost();
344    }
345
346    public int getRemotePort()
347    {
348       return req.getRemotePort();
349    }
350
351    public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc key)
352    {
353       return req.getRequestDispatcher(key);
354    }
355
356    public String JavaDoc getScheme()
357    {
358       return req.getScheme();
359    }
360
361    public String JavaDoc getServerName()
362    {
363       return req.getServerName();
364    }
365
366    public int getServerPort()
367    {
368       return req.getServerPort();
369    }
370
371    public boolean isSecure()
372    {
373       return req.isSecure();
374    }
375
376    public void removeAttribute(String JavaDoc key)
377    {
378       req.removeAttribute(key);
379    }
380
381    public void setAttribute(String JavaDoc key, Object JavaDoc o)
382    {
383       req.setAttribute(key, o);
384    }
385
386    public void setCharacterEncoding(String JavaDoc key) throws UnsupportedEncodingException JavaDoc
387    {
388       req.setCharacterEncoding(key);
389    }
390
391    //
392

393    /*
394    private String buildPortalPath()
395    {
396       String contextPath = req.getContextPath();
397       boolean secure = req.isSecure();
398       boolean authenticated = req.getRemoteUser() != null;
399       int mode = (authenticated ? 2 : 0) + (secure ? 1 : 0);
400       switch (mode)
401       {
402          case 0:
403             return contextPath;
404          case 1:
405             return contextPath + "/sec";
406          case 2:
407             return contextPath + "/auth";
408          case 3:
409             return contextPath + "/authsec";
410          default:
411             throw new Error("Not possible");
412       }
413    }
414    */

415 }
416
Popular Tags