Source Code Cross Referenced for RimfaxeHttpServletRequest.java in  » Web-Server » Rimfaxe-Web-Server » com » rimfaxe » webserver » servletapi » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Rimfaxe Web Server » com.rimfaxe.webserver.servletapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * RimfaxeHttpServletRequest.java
003:         *
004:         *
005:         * Copyright (c) 2003 Rimfaxe ApS  (www.rimfaxe.com).  
006:         * All rights reserved.
007:         *
008:         * This package is written by Lars Andersen <lars@rimfaxe.com> 
009:         * and licensed by Rimfaxe ApS.
010:         *
011:         * Redistribution and use in source and binary forms, with or without
012:         * modification, are permitted provided that the following conditions
013:         * are met:
014:         *
015:         * 1. Redistributions of source code must retain the above copyright
016:         *    notice, this list of conditions and the following disclaimer.
017:         *
018:         * 2. Redistributions in binary form must reproduce the above copyright
019:         *    notice, this list of conditions and the following disclaimer in
020:         *    the documentation and/or other materials provided with the
021:         *    distribution.
022:         *
023:         * 3. The end-user documentation included with the redistribution, if
024:         *    any, must include the following acknowlegement:
025:         *       "This product includes software developed by Rimfaxe ApS
026:                  (www.rimfaxe.com)"
027:         *    Alternately, this acknowlegement may appear in the software itself,
028:         *    if and wherever such third-party acknowlegements normally appear.
029:         *
030:         * 4. The names "Rimfaxe", "Rimfaxe Software", "Lars Andersen" and 
031:         *    "Rimfaxe WebServer" must not be used to endorse or promote products 
032:         *    derived from this software without prior written permission. For written
033:         *    permission, please contact info@rimfaxe.com
034:         *
035:         * 5. Products derived from this software may not be called "Rimfaxe"
036:         *    nor may "Rimfaxe" appear in their names without prior written
037:         *    permission of the Rimfaxe ApS.
038:         *
039:         * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
040:         * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
041:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
042:         * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
043:         * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
044:         * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
045:         * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
046:         * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
047:         * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
048:         * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
049:         * SUCH DAMAGE.
050:         *
051:         */
052:
053:        package com.rimfaxe.webserver.servletapi;
054:
055:        import java.io.*;
056:        import java.net.*;
057:        import java.util.*;
058:        import java.security.Principal;
059:        import javax.servlet.*;
060:        import javax.servlet.http.*;
061:
062:        import seda.sandStorm.lib.http.httpRequest;
063:
064:        import com.rimfaxe.webserver.servletapi.session.SessionStore;
065:        import com.rimfaxe.webserver.*;
066:
067:        public class RimfaxeHttpServletRequest implements  HttpServletRequest {
068:
069:            WebContext webcontext;
070:            SessionStore sessionstore;
071:
072:            /** getHttpVer() code corresponding to HTTP/0.9. */
073:            public static final int HTTPVER_09 = 0;
074:            /** getHttpVer() code corresponding to HTTP/1.0. */
075:            public static final int HTTPVER_10 = 1;
076:            /** getHttpVer() code corresponding to HTTP/1.1. */
077:            public static final int HTTPVER_11 = 2;
078:
079:            /**
080:             * The initial state of the request InputStream 
081:             */
082:            private final static int STREAM_STATE_INITIAL = 0;
083:
084:            /**
085:             * One reader has been created and is probably used.
086:             */
087:            private final static int STREAM_READER_USED = 1;
088:
089:            /**
090:             * The input stream is used
091:             */
092:            private final static int INPUT_STREAM_USED = 2;
093:
094:            /**
095:             * The inputstream state
096:             */
097:            private int stream_state = STREAM_STATE_INITIAL;
098:
099:            public final static String STATE_PARAMETERS = "com.rimfaxe.servlet.stateParam";
100:
101:            /** 
102:             * The initial request.
103:             */
104:            private httpRequest request = null;
105:
106:            /**
107:             * The attached servlet.
108:             */
109:            private Servlet servlet = null;
110:
111:            private Hashtable postparameters = new Hashtable();
112:            private Hashtable attributes = new Hashtable();
113:
114:            protected RimfaxeHttpServletResponse response = null;
115:            protected RimfaxeHttpSession httpSession = null;
116:
117:            protected String requestedSessionID = null;
118:
119:            /**
120:             * Return the code corresponding to the HTTP version. Each code has
121:             * one of the HTTPVER_* values from this class.
122:             */
123:            public int getHttpVer() {
124:                return request.getHttpVer();
125:            }
126:
127:            /**
128:             * Return the Charset parameter of content type
129:             * @return A String instance
130:             */
131:            public String getCharacterEncoding() {
132:                return "iso-8859-1";
133:            }
134:
135:            /**
136:             * ServletRequest implementation - Get the length of request data.
137:             * @return An int, or <strong>-1</strong>.
138:             */
139:            public int getContentLength() {
140:                return -1;
141:            }
142:
143:            /**
144:             * ServletRequest implementation - Get the type of the request's body.
145:             * @return A String encoded mime type, or <strong>null</strong>.
146:             */
147:            public String getContentType() {
148:                return request.getHeader("Content-Type");
149:            }
150:
151:            /**
152:             * ServletRequest implementation - Get the protocol of that request.
153:             * @return A String encoded version of the protocol.
154:             */
155:            public String getProtocol() {
156:
157:                return "HTTP";
158:            }
159:
160:            /**
161:             * ServletRequest implementation - Get the name of queried server.
162:             * @return Name of server, as a String.
163:             */
164:            public String getServerName() {
165:
166:                String host = request.getHeader("Host");
167:                if (host != null) {
168:                    int idx = host.lastIndexOf(':');
169:                    if (idx != -1) {
170:                        return host.substring(0, host.lastIndexOf(':'));
171:                    } else {
172:                        return host;
173:                    }
174:                } else {
175:                    return "localhost";
176:                }
177:            }
178:
179:            /**
180:             * ServletRequest implementation - Get the port of queried server.
181:             * @return A port number (int).
182:             */
183:            public int getServerPort() {
184:                return request.getServerPort();
185:            }
186:
187:            /**
188:             * ServletRequest implementation - Get the IP address of requests's sender.
189:             * @return Numeric IP address, as a String.
190:             */
191:
192:            public String getRemoteAddr() {
193:                //return "unknown";
194:                return request.getConnection().getConnection().getAddress()
195:                        .getHostAddress();
196:            }
197:
198:            /**
199:             * ServletRequest implementation - FQDN of request's sender.
200:             * @return Name of client's machine (FQDN).
201:             */
202:            public String getRemoteHost() {
203:
204:                //return "unknown";
205:                return request.getConnection().getConnection().getAddress()
206:                        .getHostName();
207:            }
208:
209:            public String getRealPath(String name) {
210:
211:                String ctxt_root = "";
212:                if (request.getURL().startsWith("/")) {
213:                    ctxt_root = webcontext.getUrlpath().substring(0,
214:                            webcontext.getUrlpath().length() - 1);
215:                } else {
216:                    ctxt_root = webcontext.getUrlpath();
217:                }
218:                return request.getURL();
219:            }
220:
221:            public String prependRealPath(String name) {
222:                String ctxt_root = webcontext.getUrlpath().substring(0,
223:                        webcontext.getUrlpath().length() - 1);
224:                return ctxt_root + name;
225:            }
226:
227:            public ServletInputStream getInputStream() throws IOException {
228:                if (stream_state == STREAM_READER_USED)
229:                    throw new IllegalStateException("Reader used");
230:                stream_state = INPUT_STREAM_USED;
231:                return null;
232:            }
233:
234:            /**
235:             * ServletRequest implementation - Get a parameter value.
236:             * @return The String encoded value for the parameter.
237:             */
238:
239:            public String getParameter(String name) {
240:                //System.out.println("Get Parameter  -  "+name+"="+request.getQuery(name));  
241:                return request.getQuery(name);
242:            }
243:
244:            /**
245:             * ServletRequest implementation - Get the parameters value.
246:             * @return The String array encoded value for the parameter.
247:             */
248:            public String[] getParameterValues(String parameter) {
249:                //System.out.println("Get ParameterValues");  
250:                return request.getQuerySet(parameter);
251:            }
252:
253:            /**
254:             * ServletRequest implementation - List available parameters.
255:             * @return An enumeration of parameter names.
256:             */
257:
258:            public Enumeration getParameterNames() 
259:    {
260:        //System.out.println("Get ParameterNames"); 
261:        Enumeration enum = request.getQueryKeys();
262:        
263:        if (enum==null) 
264:        {
265:          //System.out.println("Get ParameterNames - enum is null");
266:          Vector vec = new Vector();
267:          enum = vec.elements();
268:        }
269:        
270:        
271:	return enum;
272:    }
273:
274:            public Object getAttribute(String name) {
275:                return attributes.get(name);
276:            }
277:
278:            public void setAttribute(String name, Object object) {
279:                attributes.put(name, object);
280:            }
281:
282:            /**
283:             * Removes an attribute from this request.  This method is not
284:             * generally needed as attributes only persist as long as the request
285:             * is being handled.
286:             *
287:             * <p>Attribute names should follow the same conventions as
288:             * package names. Names beginning with <code>java.*</code>,
289:             * <code>javax.*</code>, and <code>com.sun.*</code>, are
290:             * reserved for use by Sun Microsystems.
291:             *
292:             * @param name a <code>String</code> specifying 
293:             * the name of the attribute to remove
294:             */
295:            public void removeAttribute(String name) {
296:                attributes.remove(name);
297:            }
298:
299:            public Enumeration getAttributeNames() {
300:                return attributes.keys();
301:            }
302:
303:            /**
304:             * Returns the preferred <code>Locale</code> that the client will 
305:             * accept content in, based on the Accept-Language header.
306:             * If the client request doesn't provide an Accept-Language header,
307:             * this method returns the default locale for the server.
308:             *
309:             * @return the preferred <code>Locale</code> for the client
310:             */
311:            public Locale getLocale() {
312:                return (Locale) getLocales().nextElement();
313:            }
314:
315:            /**
316:             * Returns an <code>Enumeration</code> of <code>Locale</code> objects
317:             * indicating, in decreasing order starting with the preferred locale, the
318:             * locales that are acceptable to the client based on the Accept-Language
319:             * header.
320:             * If the client request doesn't provide an Accept-Language header,
321:             * this method returns an <code>Enumeration</code> containing one 
322:             * <code>Locale</code>, the default locale for the server.
323:             *
324:             * @return an <code>Enumeration</code> of preferred 
325:             * <code>Locale</code> objects for the client
326:             */
327:            public Enumeration getLocales() {
328:                Vector locales = new Vector();
329:
330:                String accept_lang = getHeader("Accept-Language");
331:
332:                if (accept_lang != null) {
333:                    StringTokenizer tkz = new StringTokenizer(accept_lang,
334:                            " ,", false);
335:                    while (tkz.hasMoreTokens()) {
336:                        String lang = tkz.nextToken();
337:                        RimfaxeLocale ql = new RimfaxeLocale(lang.trim());
338:                        locales.addElement(ql.getLocale());
339:                    }
340:                } else {
341:                    locales.addElement(Locale.getDefault());
342:                }
343:
344:                return locales.elements();
345:            }
346:
347:            /**
348:             * Returns a boolean indicating whether this request was made using a
349:             * secure channel, such as HTTPS.
350:             *
351:             * @return a boolean indicating if the request was made using a
352:             * secure channel
353:             */
354:            public boolean isSecure() {
355:                // only https secure?
356:                return false;
357:            }
358:
359:            /**
360:             * HttpServletRequest implementation - Get the request's method.
361:             * @return A String instance.
362:             */
363:            public String getMethod() {
364:                //System.out.println("Get Method"); 
365:                return request.getMethod();
366:            }
367:
368:            /**
369:             * HttpServletRequest implementation - Get the request's path info.
370:             * @return A String instance or <strong>null</strong>.
371:             */
372:            public String getPathInfo() {
373:                return null;
374:            }
375:
376:            /**
377:             * HttpServletRequest implementation - Get the request's path translated.
378:             * @return A String instance or <strong>null</strong>.
379:             */
380:            public String getPathTranslated() {
381:                String pathinfo = getPathInfo();
382:                if (pathinfo != null)
383:                    return getRealPath(pathinfo);
384:                return null;
385:            }
386:
387:            /**
388:             * Returns the portion of the request URI that indicates the context
389:             * of the request.  The context path always comes first in a request
390:             * URI.  The path starts with a "/" character but does not end with a "/"
391:             * character.  For servlets in the default (root) context, this method
392:             * returns "".
393:             * @return a <code>String</code> specifying the portion of the request 
394:             * URI that indicates the context of the request
395:             */
396:            public String getContextPath() {
397:                String cpath = webcontext.getUrlpath();
398:                if (cpath.endsWith("/"))
399:                    return cpath.substring(0, cpath.length() - 1);
400:                return cpath;
401:            }
402:
403:            public boolean hasQueryString() {
404:                if (request.getQueryString() != null)
405:                    return true;
406:                else
407:                    return false;
408:            }
409:
410:            /**
411:             * HttpServletRequest implementation - Get the request's query string.
412:             * @return A String instance or <strong>null</strong>.
413:             */
414:            public String getQueryString() {
415:
416:                return request.getQueryString();
417:            }
418:
419:            /**
420:             * HttpServletRequest implementation - Get the request's user (if any).
421:             * @return A String instance or <strong>null</strong>.
422:             */
423:            public String getRemoteUser() {
424:
425:                return null;
426:            }
427:
428:            /**
429:             * Returns a boolean indicating whether the authenticated user is included
430:             * in the specified logical "role".  Roles and role membership can be
431:             * defined using deployment descriptors.  If the user has not been
432:             * authenticated, the method returns <code>false</code>.
433:             *
434:             * @param role a <code>String</code> specifying the name of the role
435:             * @return a <code>boolean</code> indicating whether the user making this
436:             * request belongs to a given role; <code>false</code> if the user has not
437:             * been authenticated
438:             */
439:
440:            public boolean isUserInRole(String role) {
441:                throw new RuntimeException("Not Yet Implemented");
442:            }
443:
444:            /**
445:             * Returns a <code>java.security.Principal</code> object containing
446:             * the name of the current authenticated user. If the user has not been
447:             * authenticated, the method returns <code>null</code>.
448:             *
449:             * @return a <code>java.security.Principal</code> containing
450:             * the name of the user making this request; <code>null</code> if the 
451:             * user has not been authenticated
452:             */
453:            public Principal getUserPrincipal() {
454:                return null;
455:            }
456:
457:            /**
458:             * HttpServletRequest implementation - Get the request's auth method.
459:             * @return A String instance or <strong>null</strong>.
460:             */
461:
462:            public String getAuthType() {
463:                return null;
464:            }
465:
466:            /**
467:             * HttpServletRequest implementation - Get a request header as a String.
468:             * @return A String instance or <strong>null</strong>.
469:             */
470:            public String getHeader(String name) {
471:                return request.getHeader(name);
472:            }
473:
474:            /**
475:             * Returns all the values of the specified request header
476:             * as an <code>Enumeration</code> of <code>String</code> objects.
477:             *
478:             *
479:             * @param name a <code>String</code> specifying the header name
480:             * @return a <code>Enumeration</code> containing the values of the 
481:             * requested header, or <code>null</code> if the request does not
482:             * have any headers of that name
483:             */
484:            public Enumeration getHeaders(String name) {
485:                String value = getHeader(name);
486:
487:                if (value == null)
488:                    return null;
489:
490:                Vector vec = new Vector();
491:                vec.addElement(value);
492:
493:                return vec.elements();
494:            }
495:
496:            /**
497:             * HttpServletRequest implementation - Get a request header as an int.
498:             * @return An int, or <strong>-1</strong>.
499:             */
500:            public int getIntHeader(String name) {
501:                String v = getHeader(name);
502:                if (v != null) {
503:                    try {
504:                        Integer ival = new Integer(v);
505:                        return ival.intValue();
506:                    } catch (NumberFormatException e) {
507:                        System.out.println("Error parsing Header [" + name
508:                                + ": " + v + "] to integer, return -1 instead");
509:                    }
510:
511:                }
512:                return -1;
513:            }
514:
515:            /**
516:             * HttpServletRequest implementation - Get a request header as an date.
517:             * @return An long (as a number of milliseconds), or <strong>-1</strong>.
518:             */
519:            public long getDateHeader(String name) {
520:                return (long) -1;
521:            }
522:
523:            /**
524:             * HttpServletRequest implementation - Get a all header names.
525:             * @return An enumeration.
526:             */
527:            public Enumeration getHeaderNames() {
528:                return request.enumerateHeaders();
529:            }
530:
531:            /**
532:             * Gets, from the first line of the HTTP request, 
533:             * the part of this request's URI that is to the left of any query string.
534:             */
535:            public String getRequestURI() {
536:
537:                String uri = request.getURL();
538:
539:                return uri;
540:            }
541:
542:            /**
543:             * Returns a {@link RequestDispatcher} object that acts as a wrapper for
544:             * the resource located at the given path.  
545:             * A <code>RequestDispatcher</code> object can be used to forward
546:             * a request to the resource or to include the resource in a response.
547:             * The resource can be dynamic or static.
548:             *
549:             * <p>The pathname specified may be relative, although it cannot extend
550:             * outside the current servlet context.  If the path begins with 
551:             * a "/" it is interpreted as relative to the current context root.  
552:             * This method returns <code>null</code> if the servlet container
553:             * cannot return a <code>RequestDispatcher</code>.
554:             *
555:             * <p>The difference between this method and {@link
556:             * ServletContext#getRequestDispatcher} is that this method can take a
557:             * relative path.
558:             *
559:             * @param path a <code>String</code> specifying the pathname
560:             * to the resource
561:             * @return a <code>RequestDispatcher</code> object that acts as a 
562:             * wrapper for the resource at the specified path
563:             * @see RequestDispatcher
564:             * @see ServletContext#getRequestDispatcher
565:             */
566:            public RequestDispatcher getRequestDispatcher(String path) {
567:                if (path == null) {
568:                    throw new IllegalArgumentException("null");
569:                }
570:
571:                //return null;
572:                return RimfaxeRequestDispatcher.getRequestDispatcher(path,
573:                        webcontext.getVirtualHost(), webcontext);
574:            }
575:
576:            /**
577:             * Gets the part of this request's URI that refers to the servlet 
578:             * being invoked. Analogous to the CGI variable SCRIPT_NAME. 
579:             */
580:            public String getServletPath() {
581:                return request.getURL();
582:            }
583:
584:            /**
585:             * @return the scheme of the URL used in this request, for example "http",
586:             * "https", or "ftp". Different schemes have different rules
587:             * for constructing URLs, as noted in RFC 1738. The URL used to create 
588:             * a request may be reconstructed using this scheme, the server name 
589:             * and port, and additional information such as URIs.
590:             */
591:            public String getScheme() {
592:                return "http";
593:            }
594:
595:            /**
596:             * Gets the array of cookies found in this request.
597:             * @return the array of cookies found in this request or
598:             * <strong>null</strong> if there is no cookie.
599:             */
600:            public Cookie[] getCookies() {
601:                Vector vec = new Vector();
602:                String cookie_str = getHeader("Cookie");
603:
604:                if (cookie_str == null)
605:                    return null;
606:
607:                StringTokenizer tkz = new StringTokenizer(cookie_str, " ;",
608:                        false);
609:                while (tkz.hasMoreTokens()) {
610:                    String ck = tkz.nextToken();
611:                    StringTokenizer tkz2 = new StringTokenizer(ck, "=", false);
612:                    String name = tkz2.nextToken();
613:                    String value = tkz2.nextToken();
614:                    vec.addElement(new Cookie(name, value));
615:                }
616:
617:                Cookie[] clist = new Cookie[vec.size()];
618:                for (int i = 0; i < vec.size(); i++) {
619:                    clist[i] = (Cookie) vec.elementAt(i);
620:                }
621:
622:                return clist;
623:            }
624:
625:            protected String getRequestedSessionIdFromCookie() {
626:                Cookie[] clist = getCookies();
627:                if (clist == null)
628:                    return null;
629:
630:                for (int i = 0; i < clist.length; i++) {
631:                    if (clist[i].getName().equalsIgnoreCase(getCookieName()))
632:                        return clist[i].getValue();
633:                }
634:
635:                return null;
636:            }
637:
638:            protected String getRequestedSessionIdFromURL() {
639:                return getParameter(getCookieName());
640:            }
641:
642:            /**
643:             * Gets the session id specified with this request. This may differ 
644:             * from the actual session id. For example, if the request specified an
645:             * id for an invalid session, then this will get a new session with a 
646:             * new id. 
647:             * @return the session id specified by this request, or null if the 
648:             * request did not specify a session id.
649:             */
650:            public String getRequestedSessionId() {
651:                if (requestedSessionID == null) {
652:                    requestedSessionID = getRequestedSessionIdFromCookie();
653:                    if (requestedSessionID == null)
654:                        requestedSessionID = getRequestedSessionIdFromURL();
655:                }
656:                return requestedSessionID;
657:            }
658:
659:            /**
660:             * Gets the current valid session associated with this request, if create
661:             * is false or, if necessary, creates a new session for the request, if 
662:             * create is true. 
663:             * @return the session associated with this request or null if create 
664:             * was false and no valid session is associated with this request. 
665:             */
666:            public HttpSession getSession(boolean create) {
667:                if (httpSession == null) {
668:                    httpSession = (RimfaxeHttpSession) getSession(getRequestedSessionId());
669:                    if (httpSession != null)
670:                        httpSession.setNoMoreNew();
671:                }
672:                if (httpSession == null & create) {
673:                    httpSession = new RimfaxeHttpSession(createCookie(),
674:                            webcontext);
675:                    response.addCookie(httpSession.getCookie());
676:                    sessionstore.putSessionObject(httpSession.getCookie()
677:                            .getValue(), (RimfaxeHttpSession) httpSession);
678:                } else if (httpSession != null) {
679:                    httpSession.setLastAccessedTime();
680:                    if (!httpSession.isValid()) {
681:                        httpSession = new RimfaxeHttpSession(createCookie(),
682:                                webcontext);
683:                        response.addCookie(httpSession.getCookie());
684:                        sessionstore.putSessionObject(httpSession.getCookie()
685:                                .getValue(), (RimfaxeHttpSession) httpSession);
686:                    }
687:                }
688:                return httpSession;
689:            }
690:
691:            /**
692:             * Gets the current valid session associated with this request.
693:             * @return the session associated with this request.
694:             */
695:            public HttpSession getSession() {
696:                return getSession(true);
697:            }
698:
699:            protected String getCookieName() {
700:                return "RWS";
701:            }
702:
703:            protected Cookie createCookie() {
704:
705:                String name = getCookieName();
706:
707:                String path = webcontext.getUrlpath(); //"/";
708:                String domain = null;
709:                String comment = null;
710:                int maxage = 86400;
711:                boolean secure = false;
712:
713:                Cookie cookie = new Cookie(name, sessionstore
714:                        .getNewCookieValue());
715:                cookie.setPath(path);
716:                cookie.setMaxAge(maxage);
717:                if ((comment != null) && (comment.length() > 0))
718:                    cookie.setComment(comment);
719:                if ((domain != null) && (domain.length() > 0))
720:                    cookie.setDomain(domain);
721:                cookie.setSecure(secure);
722:                return cookie;
723:            }
724:
725:            protected HttpSession getSession(String sessionId) {
726:                RimfaxeHttpSession rhs = sessionstore
727:                        .getSessionObject(sessionId);
728:
729:                return rhs;
730:            }
731:
732:            /**
733:             * Checks whether this request is associated with a session that is valid 
734:             * in the current session context. If it is not valid, the requested
735:             * session will never be returned from the getSession method. 
736:             * @return true if this request is assocated with a session that is valid 
737:             * in the current session context. 
738:             */
739:            public boolean isRequestedSessionIdValid() {
740:                RimfaxeHttpSession session = (RimfaxeHttpSession) getSession(getRequestedSessionId());
741:                if (session == null)
742:                    return false;
743:                return (session.isValid());
744:            }
745:
746:            /**
747:             * Checks whether the session id specified by this request came in as 
748:             * a cookie. (The requested session may not be one returned by the 
749:             * getSession method.)
750:             * @return true if the session id specified by this request came 
751:             * in as a cookie; false otherwise 
752:             */
753:            public boolean isRequestedSessionIdFromCookie() {
754:                return (getRequestedSessionIdFromCookie() != null);
755:            }
756:
757:            /**
758:             * Checks whether the session id specified by this request came in as 
759:             * part of the URL. (The requested session may not be the one returned 
760:             * by the getSession method.)
761:             * @return true if the session id specified by the request for this 
762:             * session came in as part of the URL; false otherwise
763:             * @deprecated since jsdk2.1
764:             */
765:            public boolean isRequestedSessionIdFromUrl() {
766:                return (getRequestedSessionIdFromURL() != null);
767:            }
768:
769:            /**
770:             * Checks whether the session id specified by this request came in as 
771:             * part of the URL. (The requested session may not be the one returned 
772:             * by the getSession method.)
773:             * @return true if the session id specified by the request for this 
774:             * session came in as part of the URL; false otherwise
775:             */
776:            public boolean isRequestedSessionIdFromURL() {
777:                return (getRequestedSessionIdFromURL() != null);
778:            }
779:
780:            protected BufferedReader reader = null;
781:
782:            /**
783:             * Returns a buffered reader for reading text in the request body. 
784:             * This translates character set encodings as appropriate.
785:             * @exception UnsupportedEncodingException if the character set encoding 
786:             * is unsupported, so the text can't be correctly decoded. 
787:             * @exception IllegalStateException if getInputStream has been called on 
788:             * this same request. 
789:             * @exception IOException on other I/O related errors. 
790:             */
791:            public BufferedReader getReader() throws IOException {
792:                return null;
793:            }
794:
795:            /**
796:             * Get the wrapped Seda Request.
797:             * @return the request
798:             */
799:            protected httpRequest getRequest() {
800:                return request;
801:            }
802:
803:            public java.util.Map getParameterMap() {
804:                return null;
805:            }
806:
807:            public StringBuffer getRequestURL() {
808:                StringBuffer buf = new StringBuffer();
809:                String host = request.getHeader("Host");
810:                if (host == null)
811:                    host = "127.0.0.1";
812:
813:                buf.append(this .getProtocol() + "://" + host
814:                        + this .request.getURL());
815:                return buf;
816:            }
817:
818:            public void setCharacterEncoding(String str)
819:                    throws java.io.UnsupportedEncodingException {
820:            }
821:
822:            RimfaxeHttpServletRequest(Servlet servlet, httpRequest request,
823:                    RimfaxeHttpServletResponse response, WebContext webcontext)
824:
825:            {
826:                this.webcontext = webcontext;
827:                this.servlet = servlet;
828:                this.request = request;
829:                this.response = response;
830:                this.sessionstore = webcontext.getVirtualHost()
831:                        .getSessionStore();
832:            }
833:
834:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.