Source Code Cross Referenced for RequestBase.java in  » Web-Server » Rimfaxe-Web-Server » org » apache » catalina » connector » 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 » org.apache.catalina.connector 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/RequestBase.java,v 1.20 2002/05/27 13:34:34 glenn Exp $
0003:         * $Revision: 1.20 $
0004:         * $Date: 2002/05/27 13:34:34 $
0005:         *
0006:         * ====================================================================
0007:         *
0008:         * The Apache Software License, Version 1.1
0009:         *
0010:         * Copyright (c) 1999 The Apache Software Foundation.  All rights
0011:         * reserved.
0012:         *
0013:         * Redistribution and use in source and binary forms, with or without
0014:         * modification, are permitted provided that the following conditions
0015:         * are met:
0016:         *
0017:         * 1. Redistributions of source code must retain the above copyright
0018:         *    notice, this list of conditions and the following disclaimer.
0019:         *
0020:         * 2. Redistributions in binary form must reproduce the above copyright
0021:         *    notice, this list of conditions and the following disclaimer in
0022:         *    the documentation and/or other materials provided with the
0023:         *    distribution.
0024:         *
0025:         * 3. The end-user documentation included with the redistribution, if
0026:         *    any, must include the following acknowlegement:
0027:         *       "This product includes software developed by the
0028:         *        Apache Software Foundation (http://www.apache.org/)."
0029:         *    Alternately, this acknowlegement may appear in the software itself,
0030:         *    if and wherever such third-party acknowlegements normally appear.
0031:         *
0032:         * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
0033:         *    Foundation" must not be used to endorse or promote products derived
0034:         *    from this software without prior written permission. For written
0035:         *    permission, please contact apache@apache.org.
0036:         *
0037:         * 5. Products derived from this software may not be called "Apache"
0038:         *    nor may "Apache" appear in their names without prior written
0039:         *    permission of the Apache Group.
0040:         *
0041:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0042:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0043:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0044:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0045:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0046:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0047:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0048:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0049:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0050:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0051:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0052:         * SUCH DAMAGE.
0053:         * ====================================================================
0054:         *
0055:         * This software consists of voluntary contributions made by many
0056:         * individuals on behalf of the Apache Software Foundation.  For more
0057:         * information on the Apache Software Foundation, please see
0058:         * <http://www.apache.org/>.
0059:         *
0060:         * [Additional notices, if required by prior licensing conditions]
0061:         *
0062:         */
0063:
0064:        package org.apache.catalina.connector;
0065:
0066:        import java.io.BufferedReader;
0067:        import java.io.InputStream;
0068:        import java.io.InputStreamReader;
0069:        import java.io.IOException;
0070:        import java.io.UnsupportedEncodingException;
0071:        import java.net.Socket;
0072:        import java.security.Principal;
0073:        import java.util.ArrayList;
0074:        import java.util.Enumeration;
0075:        import java.util.HashMap;
0076:        import java.util.Iterator;
0077:        import java.util.Locale;
0078:        import java.util.Map;
0079:        import javax.servlet.RequestDispatcher;
0080:        import javax.servlet.ServletContext;
0081:        import javax.servlet.ServletException;
0082:        import javax.servlet.ServletInputStream;
0083:        import javax.servlet.ServletRequest;
0084:        import org.apache.catalina.Connector;
0085:        import org.apache.catalina.Context;
0086:        import org.apache.catalina.Request;
0087:        import org.apache.catalina.Response;
0088:        import org.apache.catalina.Wrapper;
0089:        import org.apache.catalina.util.Enumerator;
0090:        import org.apache.catalina.util.RequestUtil;
0091:        import org.apache.catalina.util.StringManager;
0092:        import org.apache.tomcat.util.log.SystemLogHandler;
0093:
0094:        /**
0095:         * Convenience base implementation of the <b>Request</b> interface, which can
0096:         * be used for the Request implementation required by most Connectors.  Only
0097:         * the connector-specific methods need to be implemented.
0098:         *
0099:         * @author Craig R. McClanahan
0100:         * @version $Revision: 1.20 $ $Date: 2002/05/27 13:34:34 $
0101:         * @deprecated
0102:         */
0103:
0104:        public abstract class RequestBase implements  ServletRequest, Request {
0105:
0106:            // ----------------------------------------------------- Instance Variables
0107:
0108:            /**
0109:             * The attributes associated with this Request, keyed by attribute name.
0110:             */
0111:            protected HashMap attributes = new HashMap();
0112:
0113:            /**
0114:             * The authorization credentials sent with this Request.
0115:             */
0116:            protected String authorization = null;
0117:
0118:            /**
0119:             * The character encoding for this Request.
0120:             */
0121:            protected String characterEncoding = null;
0122:
0123:            /**
0124:             * The Connector through which this Request was received.
0125:             */
0126:            protected Connector connector = null;
0127:
0128:            /**
0129:             * The content length associated with this request.
0130:             */
0131:            protected int contentLength = -1;
0132:
0133:            /**
0134:             * The content type associated with this request.
0135:             */
0136:            protected String contentType = null;
0137:
0138:            /**
0139:             * The Context within which this Request is being processed.
0140:             */
0141:            protected Context context = null;
0142:
0143:            /**
0144:             * The default Locale if none are specified.
0145:             */
0146:            protected static Locale defaultLocale = Locale.getDefault();
0147:
0148:            /**
0149:             * The facade associated with this request.
0150:             */
0151:            protected RequestFacade facade = new RequestFacade(this );
0152:
0153:            /**
0154:             * Descriptive information about this Request implementation.
0155:             */
0156:            protected static final String info = "org.apache.catalina.connector.RequestBase/1.0";
0157:
0158:            /**
0159:             * The input stream associated with this Request.
0160:             */
0161:            protected InputStream input = null;
0162:
0163:            /**
0164:             * The preferred Locales assocaited with this Request.
0165:             */
0166:            protected ArrayList locales = new ArrayList();
0167:
0168:            /**
0169:             * Internal notes associated with this request by Catalina components
0170:             * and event listeners.
0171:             */
0172:            private transient HashMap notes = new HashMap();
0173:
0174:            /**
0175:             * The protocol name and version associated with this Request.
0176:             */
0177:            protected String protocol = null;
0178:
0179:            /**
0180:             * The reader that has been returned by <code>getReader</code>, if any.
0181:             */
0182:            protected BufferedReader reader = null;
0183:
0184:            /**
0185:             * The remote address associated with this request.
0186:             */
0187:            protected String remoteAddr = null;
0188:
0189:            /**
0190:             * The fully qualified name of the remote host.
0191:             */
0192:            protected String remoteHost = null;
0193:
0194:            /**
0195:             * The response with which this request is associated.
0196:             */
0197:            protected Response response = null;
0198:
0199:            /**
0200:             * The scheme associated with this Request.
0201:             */
0202:            protected String scheme = null;
0203:
0204:            /**
0205:             * Was this request received on a secure connection?
0206:             */
0207:            protected boolean secure = false;
0208:
0209:            /**
0210:             * The server name associated with this Request.
0211:             */
0212:            protected String serverName = null;
0213:
0214:            /**
0215:             * The server port associated with this Request.
0216:             */
0217:            protected int serverPort = -1;
0218:
0219:            /**
0220:             * The string manager for this package.
0221:             */
0222:            protected static StringManager sm = StringManager
0223:                    .getManager(Constants.Package);
0224:
0225:            /**
0226:             * The socket through which this Request was received.
0227:             */
0228:            protected Socket socket = null;
0229:
0230:            /**
0231:             * The ServletInputStream that has been returned by
0232:             * <code>getInputStream()</code>, if any.
0233:             */
0234:            protected ServletInputStream stream = null;
0235:
0236:            /**
0237:             * The Wrapper within which this Request is being processed.
0238:             */
0239:            protected Wrapper wrapper = null;
0240:
0241:            // ------------------------------------------------------------- Properties
0242:
0243:            /**
0244:             * Return the authorization credentials sent with this request.
0245:             */
0246:            public String getAuthorization() {
0247:
0248:                return (this .authorization);
0249:
0250:            }
0251:
0252:            /**
0253:             * Set the authorization credentials sent with this request.
0254:             *
0255:             * @param authorization The new authorization credentials
0256:             */
0257:            public void setAuthorization(String authorization) {
0258:
0259:                this .authorization = authorization;
0260:
0261:            }
0262:
0263:            /**
0264:             * Return the Connector through which this Request was received.
0265:             */
0266:            public Connector getConnector() {
0267:
0268:                return (this .connector);
0269:
0270:            }
0271:
0272:            /**
0273:             * Set the Connector through which this Request was received.
0274:             *
0275:             * @param connector The new connector
0276:             */
0277:            public void setConnector(Connector connector) {
0278:
0279:                this .connector = connector;
0280:
0281:            }
0282:
0283:            /**
0284:             * Return the Context within which this Request is being processed.
0285:             */
0286:            public Context getContext() {
0287:
0288:                return (this .context);
0289:
0290:            }
0291:
0292:            /**
0293:             * Set the Context within which this Request is being processed.  This
0294:             * must be called as soon as the appropriate Context is identified, because
0295:             * it identifies the value to be returned by <code>getContextPath()</code>,
0296:             * and thus enables parsing of the request URI.
0297:             *
0298:             * @param context The newly associated Context
0299:             */
0300:            public void setContext(Context context) {
0301:
0302:                this .context = context;
0303:
0304:                SystemLogHandler.startCapture();
0305:            }
0306:
0307:            /**
0308:             * Return descriptive information about this Request implementation and
0309:             * the corresponding version number, in the format
0310:             * <code>&lt;description&gt;/&lt;version&gt;</code>.
0311:             */
0312:            public String getInfo() {
0313:
0314:                return (info);
0315:
0316:            }
0317:
0318:            /**
0319:             * Return the <code>ServletRequest</code> for which this object
0320:             * is the facade.  This method must be implemented by a subclass.
0321:             */
0322:            public ServletRequest getRequest() {
0323:
0324:                return (facade);
0325:
0326:            }
0327:
0328:            /**
0329:             * Return the Response with which this Request is associated.
0330:             */
0331:            public Response getResponse() {
0332:
0333:                return (this .response);
0334:
0335:            }
0336:
0337:            /**
0338:             * Set the Response with which this Request is associated.
0339:             *
0340:             * @param response The new associated response
0341:             */
0342:            public void setResponse(Response response) {
0343:
0344:                this .response = response;
0345:
0346:            }
0347:
0348:            /**
0349:             * Return the Socket (if any) through which this Request was received.
0350:             * This should <strong>only</strong> be used to access underlying state
0351:             * information about this Socket, such as the SSLSession associated with
0352:             * an SSLSocket.
0353:             */
0354:            public Socket getSocket() {
0355:
0356:                return (this .socket);
0357:
0358:            }
0359:
0360:            /**
0361:             * Set the Socket (if any) through which this Request was received.
0362:             *
0363:             * @param socket The socket through which this request was received
0364:             */
0365:            public void setSocket(Socket socket) {
0366:
0367:                this .socket = socket;
0368:
0369:            }
0370:
0371:            /**
0372:             * Return the input stream associated with this Request.
0373:             */
0374:            public InputStream getStream() {
0375:
0376:                return (this .input);
0377:
0378:            }
0379:
0380:            /**
0381:             * Set the input stream associated with this Request.
0382:             *
0383:             * @param input The new input stream
0384:             */
0385:            public void setStream(InputStream input) {
0386:
0387:                this .input = input;
0388:
0389:            }
0390:
0391:            /**
0392:             * Return the Wrapper within which this Request is being processed.
0393:             */
0394:            public Wrapper getWrapper() {
0395:
0396:                return (this .wrapper);
0397:
0398:            }
0399:
0400:            /**
0401:             * Set the Wrapper within which this Request is being processed.  This
0402:             * must be called as soon as the appropriate Wrapper is identified, and
0403:             * before the Request is ultimately passed to an application servlet.
0404:             *
0405:             * @param wrapper The newly associated Wrapper
0406:             */
0407:            public void setWrapper(Wrapper wrapper) {
0408:
0409:                this .wrapper = wrapper;
0410:
0411:            }
0412:
0413:            // --------------------------------------------------------- Public Methods
0414:
0415:            /**
0416:             * Add a Locale to the set of preferred Locales for this Request.  The
0417:             * first added Locale will be the first one returned by getLocales().
0418:             *
0419:             * @param locale The new preferred Locale
0420:             */
0421:            public void addLocale(Locale locale) {
0422:
0423:                synchronized (locales) {
0424:                    locales.add(locale);
0425:                }
0426:
0427:            }
0428:
0429:            /**
0430:             * Create and return a ServletInputStream to read the content
0431:             * associated with this Request.  The default implementation creates an
0432:             * instance of RequestStream associated with this request, but this can
0433:             * be overridden if necessary.
0434:             *
0435:             * @exception IOException if an input/output error occurs
0436:             */
0437:            public ServletInputStream createInputStream() throws IOException {
0438:
0439:                return (new RequestStream(this ));
0440:
0441:            }
0442:
0443:            /**
0444:             * Perform whatever actions are required to flush and close the input
0445:             * stream or reader, in a single operation.
0446:             *
0447:             * @exception IOException if an input/output error occurs
0448:             */
0449:            public void finishRequest() throws IOException {
0450:
0451:                // If a Reader has been acquired, close it
0452:                if (reader != null) {
0453:                    try {
0454:                        reader.close();
0455:                    } catch (IOException e) {
0456:                        ;
0457:                    }
0458:                }
0459:
0460:                // If a ServletInputStream has been acquired, close it
0461:                if (stream != null) {
0462:                    try {
0463:                        stream.close();
0464:                    } catch (IOException e) {
0465:                        ;
0466:                    }
0467:                }
0468:
0469:                // The underlying input stream (perhaps from a socket)
0470:                // is not our responsibility
0471:
0472:            }
0473:
0474:            /**
0475:             * Return the object bound with the specified name to the internal notes
0476:             * for this request, or <code>null</code> if no such binding exists.
0477:             *
0478:             * @param name Name of the note to be returned
0479:             */
0480:            public Object getNote(String name) {
0481:
0482:                synchronized (notes) {
0483:                    return (notes.get(name));
0484:                }
0485:
0486:            }
0487:
0488:            /**
0489:             * Return an Iterator containing the String names of all notes bindings
0490:             * that exist for this request.
0491:             */
0492:            public Iterator getNoteNames() {
0493:
0494:                synchronized (notes) {
0495:                    return (notes.keySet().iterator());
0496:                }
0497:
0498:            }
0499:
0500:            /**
0501:             * Release all object references, and initialize instance variables, in
0502:             * preparation for reuse of this object.
0503:             */
0504:            public void recycle() {
0505:
0506:                String log = SystemLogHandler.stopCapture();
0507:                if (log != null && log.length() > 0) {
0508:                    context.getServletContext().log(log);
0509:                }
0510:                attributes.clear();
0511:                authorization = null;
0512:                characterEncoding = null;
0513:                // connector is NOT reset when recycling
0514:                contentLength = -1;
0515:                contentType = null;
0516:                context = null;
0517:                input = null;
0518:                locales.clear();
0519:                notes.clear();
0520:                protocol = null;
0521:                reader = null;
0522:                remoteAddr = null;
0523:                remoteHost = null;
0524:                response = null;
0525:                scheme = null;
0526:                secure = false;
0527:                serverName = null;
0528:                serverPort = -1;
0529:                socket = null;
0530:                stream = null;
0531:                wrapper = null;
0532:
0533:            }
0534:
0535:            /**
0536:             * Remove any object bound to the specified name in the internal notes
0537:             * for this request.
0538:             *
0539:             * @param name Name of the note to be removed
0540:             */
0541:            public void removeNote(String name) {
0542:
0543:                synchronized (notes) {
0544:                    notes.remove(name);
0545:                }
0546:
0547:            }
0548:
0549:            /**
0550:             * Set the content length associated with this Request.
0551:             *
0552:             * @param length The new content length
0553:             */
0554:            public void setContentLength(int length) {
0555:
0556:                this .contentLength = length;
0557:
0558:            }
0559:
0560:            /**
0561:             * Set the content type (and optionally the character encoding)
0562:             * associated with this Request.  For example,
0563:             * <code>text/html; charset=ISO-8859-4</code>.
0564:             *
0565:             * @param type The new content type
0566:             */
0567:            public void setContentType(String type) {
0568:
0569:                this .contentType = type;
0570:                if (type.indexOf(';') >= 0)
0571:                    characterEncoding = RequestUtil
0572:                            .parseCharacterEncoding(type);
0573:
0574:            }
0575:
0576:            /**
0577:             * Bind an object to a specified name in the internal notes associated
0578:             * with this request, replacing any existing binding for this name.
0579:             *
0580:             * @param name Name to which the object should be bound
0581:             * @param value Object to be bound to the specified name
0582:             */
0583:            public void setNote(String name, Object value) {
0584:
0585:                synchronized (notes) {
0586:                    notes.put(name, value);
0587:                }
0588:
0589:            }
0590:
0591:            /**
0592:             * Set the protocol name and version associated with this Request.
0593:             *
0594:             * @param protocol Protocol name and version
0595:             */
0596:            public void setProtocol(String protocol) {
0597:
0598:                this .protocol = protocol;
0599:
0600:            }
0601:
0602:            /**
0603:             * Set the IP address of the remote client associated with this Request.
0604:             *
0605:             * @param remoteAddr The remote IP address
0606:             */
0607:            public void setRemoteAddr(String remoteAddr) {
0608:
0609:                this .remoteAddr = remoteAddr;
0610:
0611:            }
0612:
0613:            /**
0614:             * Set the fully qualified name of the remote client associated with this
0615:             * Request.
0616:             *
0617:             * @param remoteHost The remote host name
0618:             */
0619:            public void setRemoteHost(String remoteHost) {
0620:
0621:                this .remoteHost = remoteHost;
0622:
0623:            }
0624:
0625:            /**
0626:             * Set the name of the scheme associated with this request.  Typical values
0627:             * are <code>http</code>, <code>https</code>, and <code>ftp</code>.
0628:             *
0629:             * @param scheme The scheme
0630:             */
0631:            public void setScheme(String scheme) {
0632:
0633:                this .scheme = scheme;
0634:
0635:            }
0636:
0637:            /**
0638:             * Set the value to be returned by <code>isSecure()</code>
0639:             * for this Request.
0640:             *
0641:             * @param secure The new isSecure value
0642:             */
0643:            public void setSecure(boolean secure) {
0644:
0645:                this .secure = secure;
0646:
0647:            }
0648:
0649:            /**
0650:             * Set the name of the server (virtual host) to process this request.
0651:             *
0652:             * @param name The server name
0653:             */
0654:            public void setServerName(String name) {
0655:
0656:                this .serverName = name;
0657:
0658:            }
0659:
0660:            /**
0661:             * Set the port number of the server to process this request.
0662:             *
0663:             * @param port The server port
0664:             */
0665:            public void setServerPort(int port) {
0666:
0667:                this .serverPort = port;
0668:
0669:            }
0670:
0671:            // ------------------------------------------------- ServletRequest Methods
0672:
0673:            /**
0674:             * Return the specified request attribute if it exists; otherwise, return
0675:             * <code>null</code>.
0676:             *
0677:             * @param name Name of the request attribute to return
0678:             */
0679:            public Object getAttribute(String name) {
0680:
0681:                synchronized (attributes) {
0682:                    return (attributes.get(name));
0683:                }
0684:
0685:            }
0686:
0687:            /**
0688:             * Return the names of all request attributes for this Request, or an
0689:             * empty <code>Enumeration</code> if there are none.
0690:             */
0691:            public Enumeration getAttributeNames() {
0692:
0693:                synchronized (attributes) {
0694:                    return (new Enumerator(attributes.keySet()));
0695:                }
0696:
0697:            }
0698:
0699:            /**
0700:             * Return the character encoding for this Request.
0701:             */
0702:            public String getCharacterEncoding() {
0703:
0704:                return (this .characterEncoding);
0705:
0706:            }
0707:
0708:            /**
0709:             * Return the content length for this Request.
0710:             */
0711:            public int getContentLength() {
0712:
0713:                return (this .contentLength);
0714:
0715:            }
0716:
0717:            /**
0718:             * Return the content type for this Request.
0719:             */
0720:            public String getContentType() {
0721:
0722:                return (contentType);
0723:
0724:            }
0725:
0726:            /**
0727:             * Return the servlet input stream for this Request.  The default
0728:             * implementation returns a servlet input stream created by
0729:             * <code>createInputStream()</code>.
0730:             *
0731:             * @exception IllegalStateException if <code>getReader()</code> has
0732:             *  already been called for this request
0733:             * @exception IOException if an input/output error occurs
0734:             */
0735:            public ServletInputStream getInputStream() throws IOException {
0736:
0737:                if (reader != null)
0738:                    throw new IllegalStateException(sm
0739:                            .getString("requestBase.getInputStream.ise"));
0740:
0741:                if (stream == null)
0742:                    stream = createInputStream();
0743:                return (stream);
0744:
0745:            }
0746:
0747:            /**
0748:             * Return the preferred Locale that the client will accept content in,
0749:             * based on the value for the first <code>Accept-Language</code> header
0750:             * that was encountered.  If the request did not specify a preferred
0751:             * language, the server's default Locale is returned.
0752:             */
0753:            public Locale getLocale() {
0754:
0755:                synchronized (locales) {
0756:                    if (locales.size() > 0)
0757:                        return ((Locale) locales.get(0));
0758:                    else
0759:                        return (defaultLocale);
0760:                }
0761:
0762:            }
0763:
0764:            /**
0765:             * Return the set of preferred Locales that the client will accept
0766:             * content in, based on the values for any <code>Accept-Language</code>
0767:             * headers that were encountered.  If the request did not specify a
0768:             * preferred language, the server's default Locale is returned.
0769:             */
0770:            public Enumeration getLocales() {
0771:
0772:                synchronized (locales) {
0773:                    if (locales.size() > 0)
0774:                        return (new Enumerator(locales));
0775:                }
0776:                ArrayList results = new ArrayList();
0777:                results.add(defaultLocale);
0778:                return (new Enumerator(results));
0779:
0780:            }
0781:
0782:            /**
0783:             * Return the value of the specified request parameter, if any; otherwise,
0784:             * return <code>null</code>.  If there is more than one value defined,
0785:             * return only the first one.
0786:             *
0787:             * @param name Name of the desired request parameter
0788:             */
0789:            public abstract String getParameter(String name);
0790:
0791:            /**
0792:             * Returns a <code>Map</code> of the parameters of this request.
0793:             * Request parameters are extra information sent with the request.
0794:             * For HTTP servlets, parameters are contained in the query string
0795:             * or posted form data.
0796:             *
0797:             * @return A <code>Map</code> containing parameter names as keys
0798:             *  and parameter values as map values.
0799:             */
0800:            public abstract Map getParameterMap();
0801:
0802:            /**
0803:             * Return the names of all defined request parameters for this request.
0804:             */
0805:            public abstract Enumeration getParameterNames();
0806:
0807:            /**
0808:             * Return the defined values for the specified request parameter, if any;
0809:             * otherwise, return <code>null</code>.
0810:             *
0811:             * @param name Name of the desired request parameter
0812:             */
0813:            public abstract String[] getParameterValues(String name);
0814:
0815:            /**
0816:             * Return the protocol and version used to make this Request.
0817:             */
0818:            public String getProtocol() {
0819:
0820:                return (this .protocol);
0821:
0822:            }
0823:
0824:            /**
0825:             * Read the Reader wrapping the input stream for this Request.  The
0826:             * default implementation wraps a <code>BufferedReader</code> around the
0827:             * servlet input stream returned by <code>createInputStream()</code>.
0828:             *
0829:             * @exception IllegalStateException if <code>getInputStream()</code>
0830:             *  has already been called for this request
0831:             * @exception IOException if an input/output error occurs
0832:             */
0833:            public BufferedReader getReader() throws IOException {
0834:
0835:                if (stream != null)
0836:                    throw new IllegalStateException(sm
0837:                            .getString("requestBase.getReader.ise"));
0838:
0839:                if (reader == null) {
0840:                    String encoding = getCharacterEncoding();
0841:                    if (encoding == null)
0842:                        encoding = "ISO-8859-1";
0843:                    InputStreamReader isr = new InputStreamReader(
0844:                            createInputStream(), encoding);
0845:                    reader = new BufferedReader(isr);
0846:                }
0847:                return (reader);
0848:
0849:            }
0850:
0851:            /**
0852:             * Return the real path of the specified virtual path.
0853:             *
0854:             * @param path Path to be translated
0855:             *
0856:             * @deprecated As of version 2.1 of the Java Servlet API, use
0857:             *  <code>ServletContext.getRealPath()</code>.
0858:             */
0859:            public String getRealPath(String path) {
0860:
0861:                if (context == null)
0862:                    return (null);
0863:                ServletContext servletContext = context.getServletContext();
0864:                if (servletContext == null)
0865:                    return (null);
0866:                else {
0867:                    try {
0868:                        return (servletContext.getRealPath(path));
0869:                    } catch (IllegalArgumentException e) {
0870:                        return (null);
0871:                    }
0872:                }
0873:
0874:            }
0875:
0876:            /**
0877:             * Return the remote IP address making this Request.
0878:             */
0879:            public String getRemoteAddr() {
0880:
0881:                return (this .remoteAddr);
0882:
0883:            }
0884:
0885:            /**
0886:             * Return the remote host name making this Request.
0887:             */
0888:            public String getRemoteHost() {
0889:
0890:                return (this .remoteHost);
0891:
0892:            }
0893:
0894:            /**
0895:             * Return a RequestDispatcher that wraps the resource at the specified
0896:             * path, which may be interpreted as relative to the current request path.
0897:             *
0898:             * @param path Path of the resource to be wrapped
0899:             */
0900:            public abstract RequestDispatcher getRequestDispatcher(String path);
0901:
0902:            /**
0903:             * Return the scheme used to make this Request.
0904:             */
0905:            public String getScheme() {
0906:
0907:                return (this .scheme);
0908:
0909:            }
0910:
0911:            /**
0912:             * Return the server name responding to this Request.
0913:             */
0914:            public String getServerName() {
0915:
0916:                return (this .serverName);
0917:
0918:            }
0919:
0920:            /**
0921:             * Return the server port responding to this Request.
0922:             */
0923:            public int getServerPort() {
0924:
0925:                return (this .serverPort);
0926:
0927:            }
0928:
0929:            /**
0930:             * Was this request received on a secure connection?
0931:             */
0932:            public boolean isSecure() {
0933:
0934:                return (this .secure);
0935:
0936:            }
0937:
0938:            /**
0939:             * Remove the specified request attribute if it exists.
0940:             *
0941:             * @param name Name of the request attribute to remove
0942:             */
0943:            public void removeAttribute(String name) {
0944:
0945:                synchronized (attributes) {
0946:                    attributes.remove(name);
0947:                }
0948:
0949:            }
0950:
0951:            /**
0952:             * Set the specified request attribute to the specified value.
0953:             *
0954:             * @param name Name of the request attribute to set
0955:             * @param value The associated value
0956:             */
0957:            public void setAttribute(String name, Object value) {
0958:
0959:                // Name cannot be null
0960:                if (name == null)
0961:                    throw new IllegalArgumentException(sm
0962:                            .getString("requestBase.setAttribute.namenull"));
0963:
0964:                // Null value is the same as removeAttribute()
0965:                if (value == null) {
0966:                    removeAttribute(name);
0967:                    return;
0968:                }
0969:
0970:                synchronized (attributes) {
0971:                    attributes.put(name, value);
0972:                }
0973:
0974:            }
0975:
0976:            /**
0977:             * Overrides the name of the character encoding used in the body of
0978:             * this request.  This method must be called prior to reading request
0979:             * parameters or reading input using <code>getReader()</code>.
0980:             *
0981:             * @param enc The character encoding to be used
0982:             *
0983:             * @exception UnsupportedEncodingException if the specified encoding
0984:             *  is not supported
0985:             *
0986:             * @since Servlet 2.3
0987:             */
0988:            public void setCharacterEncoding(String enc)
0989:                    throws UnsupportedEncodingException {
0990:
0991:                // Ensure that the specified encoding is valid
0992:                byte buffer[] = new byte[1];
0993:                buffer[0] = (byte) 'a';
0994:                String dummy = new String(buffer, enc);
0995:
0996:                // Save the validated encoding
0997:                this.characterEncoding = enc;
0998:
0999:            }
1000:
1001:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.