KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > coyote > tomcat5 > CoyoteRequest


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27
28
29 package org.apache.coyote.tomcat5;
30
31
32 import java.io.InputStream JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.BufferedReader JavaDoc;
35 import java.io.UnsupportedEncodingException JavaDoc;
36 import java.net.InetAddress JavaDoc;
37 import java.net.Socket JavaDoc;
38 // START SJSAS 6347215
39
import java.net.UnknownHostException JavaDoc;
40 // END SJSAS 6347215
41
import java.security.Principal JavaDoc;
42 import java.text.SimpleDateFormat JavaDoc;
43 import java.util.ArrayList JavaDoc;
44 import java.util.Enumeration JavaDoc;
45 import java.util.HashMap JavaDoc;
46 import java.util.Iterator JavaDoc;
47 import java.util.Locale JavaDoc;
48 import java.util.Map JavaDoc;
49 import java.util.TimeZone JavaDoc;
50 import java.util.TreeMap JavaDoc;
51 import java.security.AccessController JavaDoc;
52 import java.security.PrivilegedExceptionAction JavaDoc;
53 import java.security.PrivilegedActionException JavaDoc;
54
55 import javax.security.auth.Subject JavaDoc;
56 import javax.servlet.FilterChain JavaDoc;
57 import javax.servlet.RequestDispatcher JavaDoc;
58 import javax.servlet.ServletContext JavaDoc;
59 import javax.servlet.ServletInputStream JavaDoc;
60 import javax.servlet.ServletRequestAttributeEvent JavaDoc;
61 import javax.servlet.ServletRequestAttributeListener JavaDoc;
62 import javax.servlet.http.Cookie JavaDoc;
63 import javax.servlet.http.HttpServletRequest JavaDoc;
64 import javax.servlet.http.HttpServletResponse JavaDoc;
65 import javax.servlet.http.HttpSession JavaDoc;
66
67 import org.apache.tomcat.util.buf.B2CConverter;
68 // START CR 6309511
69
import org.apache.tomcat.util.buf.ByteChunk;
70 import org.apache.tomcat.util.buf.CharChunk;
71 // END CR 6309511
72
import org.apache.tomcat.util.buf.MessageBytes;
73 import org.apache.tomcat.util.http.Cookies;
74 import org.apache.tomcat.util.http.FastHttpDateFormat;
75 import org.apache.tomcat.util.http.Parameters;
76 import org.apache.tomcat.util.http.ServerCookie;
77 import org.apache.tomcat.util.http.mapper.MappingData;
78
79 import org.apache.coyote.ActionCode;
80 import org.apache.coyote.Request;
81
82 import org.apache.catalina.Connector;
83 import org.apache.catalina.Context;
84 import org.apache.catalina.Globals;
85 import org.apache.catalina.Host;
86 import org.apache.catalina.HttpRequest;
87 import org.apache.catalina.HttpResponse;
88 import org.apache.catalina.Logger;
89 import org.apache.catalina.Manager;
90 import org.apache.catalina.Realm;
91 import org.apache.catalina.Session;
92 import org.apache.catalina.ValveContext;
93 import org.apache.catalina.Wrapper;
94
95 import org.apache.catalina.core.ApplicationFilterFactory;
96 import org.apache.catalina.util.Enumerator;
97 import org.apache.catalina.util.ParameterMap;
98 import org.apache.catalina.util.RequestUtil;
99 import org.apache.catalina.util.StringManager;
100 import org.apache.catalina.util.StringParser;
101 import org.apache.catalina.security.SecurityUtil;
102 import com.sun.org.apache.commons.logging.Log;
103 // START CR 6309511
104
import com.sun.org.apache.commons.logging.LogFactory;
105 // END CR 6309511
106

107 // START S1AS 6170450
108
import com.sun.appserv.ProxyHandler;
109 // END S1AS 6170450
110

111 /**
112  * Wrapper object for the Coyote request.
113  *
114  * @author Remy Maucherat
115  * @author Craig R. McClanahan
116  * @version $Revision: 1.20.2.1 $ $Date: 2006/06/14 18:51:38 $
117  */

118
119 public class CoyoteRequest
120     implements HttpRequest, HttpServletRequest JavaDoc {
121
122
123     // ----------------------------------------------------------- Constructors
124

125
126     public CoyoteRequest() {
127          // START OF SJSAS 6231069
128
formats = (SimpleDateFormat JavaDoc[]) staticDateFormats.get();
129         formats[0].setTimeZone(TimeZone.getTimeZone("GMT"));
130         formats[1].setTimeZone(TimeZone.getTimeZone("GMT"));
131         formats[2].setTimeZone(TimeZone.getTimeZone("GMT"));
132         // END OF SJSAS 6231069
133
}
134
135
136     // ------------------------------------------------------------- Properties
137

138
139     /**
140      * Coyote request.
141      */

142     protected Request JavaDoc coyoteRequest;
143
144     /**
145      * Set the Coyote request.
146      *
147      * @param coyoteRequest The Coyote request
148      */

149     public void setCoyoteRequest(Request JavaDoc coyoteRequest) {
150         this.coyoteRequest = coyoteRequest;
151         inputBuffer.setRequest(coyoteRequest);
152
153         // START SJSAS 6419950
154
populateSSLAttributes();
155         // END SJSAS 6419950
156
}
157
158     /**
159      * Get the Coyote request.
160      */

161     public Request JavaDoc getCoyoteRequest() {
162         return (this.coyoteRequest);
163     }
164
165
166     // ----------------------------------------------------- Instance Variables
167

168
169     /**
170      * The string manager for this package.
171      */

172     protected static StringManager sm =
173         StringManager.getManager(Constants.Package);
174
175     // START CR 6309511
176
private static final Log log = LogFactory.getLog(CoyoteRequest.class);
177     // END CR 6309511
178

179     /**
180      * The set of cookies associated with this Request.
181      */

182     protected Cookie JavaDoc[] cookies = null;
183
184     // START OF SJSAS 6231069
185
/*
186     protected SimpleDateFormat formats[] = {
187         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
188         new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
189         new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
190     }*/

191
192     /**
193      * The set of SimpleDateFormat formats to use in getDateHeader().
194      */

195     private static ThreadLocal JavaDoc staticDateFormats = new ThreadLocal JavaDoc() {
196         protected Object JavaDoc initialValue() {
197             SimpleDateFormat JavaDoc[] f = new SimpleDateFormat JavaDoc[3];
198             f[0] = new SimpleDateFormat JavaDoc("EEE, dd MMM yyyy HH:mm:ss zzz",
199                                         Locale.US);
200             f[1] = new SimpleDateFormat JavaDoc("EEEEEE, dd-MMM-yy HH:mm:ss zzz",
201                                         Locale.US);
202             f[2] = new SimpleDateFormat JavaDoc("EEE MMMM d HH:mm:ss yyyy", Locale.US);
203             return f;
204         }
205     };
206     protected SimpleDateFormat JavaDoc formats[];
207     // END OF SJSAS 6231069
208

209     /**
210      * The default Locale if none are specified.
211      */

212     protected static Locale JavaDoc defaultLocale = Locale.getDefault();
213
214
215     /**
216      * The attributes associated with this Request, keyed by attribute name.
217      */

218     protected HashMap JavaDoc attributes = new HashMap JavaDoc();
219
220
221     /**
222      * List of read only attributes for this Request.
223      */

224     private HashMap JavaDoc readOnlyAttributes = new HashMap JavaDoc();
225
226
227     /**
228      * The preferred Locales assocaited with this Request.
229      */

230     protected ArrayList JavaDoc locales = new ArrayList JavaDoc();
231
232
233     /**
234      * Internal notes associated with this request by Catalina components
235      * and event listeners.
236      */

237     private transient HashMap JavaDoc notes = new HashMap JavaDoc();
238
239
240     /**
241      * Authentication type.
242      */

243     protected String JavaDoc authType = null;
244
245
246     /**
247      * The current dispatcher type.
248      */

249     protected Object JavaDoc dispatcherType = null;
250
251
252     /**
253      * The associated input buffer.
254      */

255     protected InputBuffer inputBuffer = new InputBuffer();
256
257
258     /**
259      * ServletInputStream.
260      */

261     protected CoyoteInputStream inputStream =
262         new CoyoteInputStream(inputBuffer);
263
264
265     /**
266      * Reader.
267      */

268     protected CoyoteReader reader = new CoyoteReader(inputBuffer);
269
270
271     /**
272      * Using stream flag.
273      */

274     protected boolean usingInputStream = false;
275
276
277     /**
278      * Using writer flag.
279      */

280     protected boolean usingReader = false;
281
282
283     /**
284      * User principal.
285      */

286     protected Principal JavaDoc userPrincipal = null;
287
288
289     /**
290      * Session parsed flag.
291      */

292     protected boolean sessionParsed = false;
293
294
295     /**
296      * Request parameters parsed flag.
297      */

298     protected boolean requestParametersParsed = false;
299
300
301      /**
302      * Cookies parsed flag.
303      */

304     protected boolean cookiesParsed = false;
305
306
307     /**
308      * Secure flag.
309      */

310     protected boolean secure = false;
311
312     
313     /**
314      * The Subject associated with the current AccessControllerContext
315      */

316     protected Subject JavaDoc subject = null;
317
318
319     /**
320      * Post data buffer.
321      */

322     protected static int CACHED_POST_LEN = 8192;
323     protected byte[] postData = null;
324
325
326     /**
327      * Hash map used in the getParametersMap method.
328      */

329     protected ParameterMap parameterMap = new ParameterMap();
330
331
332     /**
333      * The currently active session for this request.
334      */

335     protected Session JavaDoc session = null;
336
337
338     /**
339      * The current request dispatcher path.
340      */

341     protected Object JavaDoc requestDispatcherPath = null;
342
343
344     /**
345      * Was the requested session ID received in a cookie?
346      */

347     protected boolean requestedSessionCookie = false;
348
349
350     /**
351      * The requested session ID (if any) for this request.
352      */

353     protected String JavaDoc requestedSessionId = null;
354
355
356     /**
357      * Was the requested session ID received in a URL?
358      */

359     protected boolean requestedSessionURL = false;
360
361
362     /**
363      * The socket through which this Request was received.
364      */

365     protected Socket JavaDoc socket = null;
366
367
368     /**
369      * Parse locales.
370      */

371     protected boolean localesParsed = false;
372
373
374     /**
375      * The string parser we will use for parsing request lines.
376      */

377     private StringParser parser = new StringParser();
378
379     /**
380      * Local port
381      */

382     protected int localPort = -1;
383
384     /**
385      * Remote address.
386      */

387     protected String JavaDoc remoteAddr = null;
388
389
390     /**
391      * Remote host.
392      */

393     protected String JavaDoc remoteHost = null;
394
395     
396     /**
397      * Remote port
398      */

399     protected int remotePort = -1;
400     
401     /**
402      * Local address
403      */

404     protected String JavaDoc localName = null;
405
406
407     /**
408      * Local address
409      */

410     protected String JavaDoc localAddr = null;
411     
412     /** After the request is mapped to a ServletContext, we can also
413      * map it to a logger.
414      */

415     /* CR 6309511
416     protected Log log=null;
417     */

418
419     // START S1AS 4703023
420
/**
421      * The current application dispatch depth.
422      */

423     private int dispatchDepth = 0;
424
425     /**
426      * The maximum allowed application dispatch depth.
427      */

428     private static int maxDispatchDepth = Constants.DEFAULT_MAX_DISPATCH_DEPTH;
429     // END S1AS 4703023
430

431
432     // START CR 6309511
433
/**
434      * The match string for identifying a session ID parameter.
435      */

436     private static final String JavaDoc match =
437         ";" + Globals.SESSION_PARAMETER_NAME + "=";
438
439     /**
440      * The match string for identifying a session ID parameter.
441      */

442     private static final char[] SESSION_ID = match.toCharArray();
443     // END CR 6309511
444

445
446     // START SJSAS 6346226
447
private String JavaDoc jrouteId;
448     // END SJSAS 6346226
449

450
451     // --------------------------------------------------------- Public Methods
452

453     /**
454      * Release all object references, and initialize instance variables, in
455      * preparation for reuse of this object.
456      */

457     public void recycle() {
458
459         context = null;
460         wrapper = null;
461
462         dispatcherType = null;
463         requestDispatcherPath = null;
464
465         authType = null;
466         inputBuffer.recycle();
467         usingInputStream = false;
468         usingReader = false;
469         userPrincipal = null;
470         subject = null;
471         sessionParsed = false;
472         requestParametersParsed = false;
473         cookiesParsed = false;
474         locales.clear();
475         localesParsed = false;
476         secure = false;
477         remoteAddr = null;
478         remoteHost = null;
479         remotePort = -1;
480         localPort = -1;
481         localAddr = null;
482         localName = null;
483
484         attributes.clear();
485         notes.clear();
486         cookies = null;
487
488         if (session != null) {
489             session.endAccess();
490         }
491         session = null;
492         requestedSessionCookie = false;
493         requestedSessionId = null;
494         requestedSessionURL = false;
495         /* CR 6309511
496         log = null;
497         */

498         dispatchDepth = 0; // S1AS 4703023
499

500         parameterMap.setLocked(false);
501         parameterMap.clear();
502
503         mappingData.recycle();
504
505         if (Constants.SECURITY) {
506             if (facade != null) {
507                 facade.clear();
508                 facade = null;
509             }
510             if (inputStream != null) {
511                 inputStream.clear();
512                 inputStream = null;
513             }
514             if (reader != null) {
515                 reader.clear();
516                 reader = null;
517             }
518         }
519
520     }
521
522
523     // -------------------------------------------------------- Request Methods
524

525
526     /**
527      * Return the authorization credentials sent with this request.
528      */

529     public String JavaDoc getAuthorization() {
530         return (coyoteRequest.getHeader(Constants.AUTHORIZATION_HEADER));
531     }
532
533     /**
534      * Set the authorization credentials sent with this request.
535      *
536      * @param authorization The new authorization credentials
537      */

538     public void setAuthorization(String JavaDoc authorization) {
539         // Not used
540
}
541
542
543     /**
544      * Associated Catalina connector.
545      */

546     protected Connector connector;
547
548     /**
549      * Return the Connector through which this Request was received.
550      */

551     public Connector getConnector() {
552         return (this.connector);
553     }
554
555     /**
556      * Set the Connector through which this Request was received.
557      *
558      * @param connector The new connector
559      */

560     public void setConnector(Connector connector) {
561         this.connector = connector;
562     }
563
564
565     /**
566      * Associated context.
567      */

568     protected Context JavaDoc context = null;
569
570     /**
571      * Return the Context within which this Request is being processed.
572      */

573     public Context JavaDoc getContext() {
574         return (this.context);
575     }
576
577
578     /**
579      * Set the Context within which this Request is being processed. This
580      * must be called as soon as the appropriate Context is identified, because
581      * it identifies the value to be returned by <code>getContextPath()</code>,
582      * and thus enables parsing of the request URI.
583      *
584      * @param context The newly associated Context
585      */

586     public void setContext(Context JavaDoc context) {
587         this.context = context;
588     }
589
590
591     /**
592      * Filter chain associated with the request.
593      */

594     protected FilterChain JavaDoc filterChain = null;
595
596     /**
597      * Get filter chain associated with the request.
598      */

599     public FilterChain JavaDoc getFilterChain() {
600         return (this.filterChain);
601     }
602
603     /**
604      * Set filter chain associated with the request.
605      *
606      * @param filterChain new filter chain
607      */

608     public void setFilterChain(FilterChain JavaDoc filterChain) {
609         this.filterChain = filterChain;
610     }
611
612
613     /**
614      * Return the Host within which this Request is being processed.
615      */

616     public Host getHost() {
617         if (getContext() == null)
618             return null;
619         return (Host) getContext().getParent();
620         //return ((Host) mappingData.host);
621
}
622
623
624     /**
625      * Set the Host within which this Request is being processed. This
626      * must be called as soon as the appropriate Host is identified, and
627      * before the Request is passed to a context.
628      *
629      * @param host The newly associated Host
630      */

631     public void setHost(Host host) {
632         mappingData.host = host;
633     }
634
635
636     /**
637      * Descriptive information about this Request implementation.
638      */

639     protected static final String JavaDoc info =
640         "org.apache.coyote.catalina.CoyoteRequest/1.0";
641
642     /**
643      * Return descriptive information about this Request implementation and
644      * the corresponding version number, in the format
645      * <code>&lt;description&gt;/&lt;version&gt;</code>.
646      */

647     public String JavaDoc getInfo() {
648         return (info);
649     }
650
651
652     /**
653      * Mapping data.
654      */

655     protected MappingData mappingData = new MappingData();
656
657     /**
658      * Return mapping data.
659      */

660     public MappingData getMappingData() {
661         return (mappingData);
662     }
663
664
665     /**
666      * The facade associated with this request.
667      */

668     protected CoyoteRequestFacade facade = null;
669
670     /**
671      * Return the <code>ServletRequest</code> for which this object
672      * is the facade. This method must be implemented by a subclass.
673      */

674     public HttpServletRequest JavaDoc getRequest() {
675         if (facade == null) {
676             facade = new CoyoteRequestFacade(this);
677         }
678         return (facade);
679     }
680
681
682     /**
683      * The response with which this request is associated.
684      */

685     protected org.apache.catalina.Response response = null;
686
687     /**
688      * Return the Response with which this Request is associated.
689      */

690     public org.apache.catalina.Response getResponse() {
691         return (this.response);
692     }
693
694     /**
695      * Set the Response with which this Request is associated.
696      *
697      * @param response The new associated response
698      */

699     public void setResponse(org.apache.catalina.Response response) {
700         this.response = response;
701     }
702
703
704     /**
705      * Return the Socket (if any) through which this Request was received.
706      * This should <strong>only</strong> be used to access underlying state
707      * information about this Socket, such as the SSLSession associated with
708      * an SSLSocket.
709      */

710     public Socket JavaDoc getSocket() {
711         return (socket);
712     }
713
714     /**
715      * Set the Socket (if any) through which this Request was received.
716      *
717      * @param socket The socket through which this request was received
718      */

719     public void setSocket(Socket JavaDoc socket) {
720         this.socket = socket;
721         remoteHost = null;
722         remoteAddr = null;
723         remotePort = -1;
724         localPort = -1;
725         localAddr = null;
726         localName = null;
727     }
728
729
730     /**
731      * Return the input stream associated with this Request.
732      */

733     public InputStream JavaDoc getStream() {
734         if (inputStream == null) {
735             inputStream = new CoyoteInputStream(inputBuffer);
736         }
737         return inputStream;
738     }
739
740     /**
741      * Set the input stream associated with this Request.
742      *
743      * @param stream The new input stream
744      */

745     public void setStream(InputStream JavaDoc stream) {
746         // Ignore
747
}
748
749
750     /**
751      * URI byte to char converter (not recycled).
752      */

753     protected B2CConverter URIConverter = null;
754
755     /**
756      * Return the URI converter.
757      */

758     protected B2CConverter getURIConverter() {
759         return URIConverter;
760     }
761
762     /**
763      * Set the URI converter.
764      *
765      * @param URIConverter the new URI connverter
766      */

767     protected void setURIConverter(B2CConverter URIConverter) {
768         this.URIConverter = URIConverter;
769     }
770
771
772     /**
773      * The valve context associated with this request.
774      */

775     protected ValveContext valveContext = null;
776
777     /**
778      * Get valve context.
779      */

780     public ValveContext getValveContext() {
781         return (this.valveContext);
782     }
783
784     /**
785      * Set valve context.
786      *
787      * @param valveContext New valve context object
788      */

789     public void setValveContext(ValveContext valveContext) {
790         this.valveContext = valveContext;
791     }
792
793
794     /**
795      * Associated wrapper.
796      */

797     protected Wrapper wrapper = null;
798
799     /**
800      * Return the Wrapper within which this Request is being processed.
801      */

802     public Wrapper getWrapper() {
803         return (this.wrapper);
804     }
805
806
807     /**
808      * Set the Wrapper within which this Request is being processed. This
809      * must be called as soon as the appropriate Wrapper is identified, and
810      * before the Request is ultimately passed to an application servlet.
811      * @param wrapper The newly associated Wrapper
812      */

813     public void setWrapper(Wrapper wrapper) {
814         this.wrapper = wrapper;
815     }
816
817
818     // ------------------------------------------------- Request Public Methods
819

820
821     /**
822      * Create and return a ServletInputStream to read the content
823      * associated with this Request.
824      *
825      * @exception IOException if an input/output error occurs
826      */

827     public ServletInputStream JavaDoc createInputStream()
828         throws IOException JavaDoc {
829         if (inputStream == null) {
830             inputStream = new CoyoteInputStream(inputBuffer);
831         }
832         return inputStream;
833     }
834
835
836     /**
837      * Perform whatever actions are required to flush and close the input
838      * stream or reader, in a single operation.
839      *
840      * @exception IOException if an input/output error occurs
841      */

842     public void finishRequest() throws IOException JavaDoc {
843         // The reader and input stream don't need to be closed
844
}
845
846
847     /**
848      * Return the object bound with the specified name to the internal notes
849      * for this request, or <code>null</code> if no such binding exists.
850      *
851      * @param name Name of the note to be returned
852      */

853     public Object JavaDoc getNote(String JavaDoc name) {
854         return (notes.get(name));
855     }
856
857
858     /**
859      * Return an Iterator containing the String names of all notes bindings
860      * that exist for this request.
861      */

862     public Iterator JavaDoc getNoteNames() {
863         return (notes.keySet().iterator());
864     }
865
866
867     /**
868      * Remove any object bound to the specified name in the internal notes
869      * for this request.
870      *
871      * @param name Name of the note to be removed
872      */

873     public void removeNote(String JavaDoc name) {
874         notes.remove(name);
875     }
876
877
878     /**
879      * Bind an object to a specified name in the internal notes associated
880      * with this request, replacing any existing binding for this name.
881      *
882      * @param name Name to which the object should be bound
883      * @param value Object to be bound to the specified name
884      */

885     public void setNote(String JavaDoc name, Object JavaDoc value) {
886         notes.put(name, value);
887     }
888
889
890     /**
891      * Set the content length associated with this Request.
892      *
893      * @param length The new content length
894      */

895     public void setContentLength(int length) {
896         // Not used
897
}
898
899
900     /**
901      * Set the content type (and optionally the character encoding)
902      * associated with this Request. For example,
903      * <code>text/html; charset=ISO-8859-4</code>.
904      *
905      * @param type The new content type
906      */

907     public void setContentType(String JavaDoc type) {
908         // Not used
909
}
910
911
912     /**
913      * Set the protocol name and version associated with this Request.
914      *
915      * @param protocol Protocol name and version
916      */

917     public void setProtocol(String JavaDoc protocol) {
918         // Not used
919
}
920
921
922     /**
923      * Set the IP address of the remote client associated with this Request.
924      *
925      * @param remoteAddr The remote IP address
926      */

927     public void setRemoteAddr(String JavaDoc remoteAddr) {
928         // Not used
929
}
930
931
932     /**
933      * Set the fully qualified name of the remote client associated with this
934      * Request.
935      *
936      * @param remoteHost The remote host name
937      */

938     public void setRemoteHost(String JavaDoc remoteHost) {
939         // Not used
940
}
941
942
943     /**
944      * Set the name of the scheme associated with this request. Typical values
945      * are <code>http</code>, <code>https</code>, and <code>ftp</code>.
946      *
947      * @param scheme The scheme
948      */

949     public void setScheme(String JavaDoc scheme) {
950         // Not used
951
}
952
953
954     /**
955      * Set the value to be returned by <code>isSecure()</code>
956      * for this Request.
957      *
958      * @param secure The new isSecure value
959      */

960     public void setSecure(boolean secure) {
961         this.secure = secure;
962     }
963
964
965     /**
966      * Set the name of the server (virtual host) to process this request.
967      *
968      * @param name The server name
969      */

970     public void setServerName(String JavaDoc name) {
971         coyoteRequest.serverName().setString(name);
972     }
973
974
975     /**
976      * Set the port number of the server to process this request.
977      *
978      * @param port The server port
979      */

980     public void setServerPort(int port) {
981         coyoteRequest.setServerPort(port);
982     }
983
984
985     // ------------------------------------------------- ServletRequest Methods
986

987
988     /**
989      * Return the specified request attribute if it exists; otherwise, return
990      * <code>null</code>.
991      *
992      * @param name Name of the request attribute to return
993      */

994     public Object JavaDoc getAttribute(String JavaDoc name) {
995
996         if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
997             return (dispatcherType == null)
998                 ? ApplicationFilterFactory.REQUEST_INTEGER
999                 : dispatcherType;
1000        } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
1001            return (requestDispatcherPath == null)
1002                ? getRequestPathMB().toString()
1003                : requestDispatcherPath.toString();
1004        }
1005
1006        Object JavaDoc attr=attributes.get(name);
1007
1008        if(attr!=null)
1009            return(attr);
1010
1011        attr = coyoteRequest.getAttribute(name);
1012        if(attr != null)
1013            return attr;
1014        // XXX Should move to Globals
1015
if(Constants.SSL_CERTIFICATE_ATTR.equals(name)) {
1016            coyoteRequest.action(ActionCode.ACTION_REQ_SSL_CERTIFICATE, null);
1017            attr = getAttribute(Globals.CERTIFICATES_ATTR);
1018            if(attr != null)
1019                attributes.put(name, attr);
1020        } else if( isSSLAttribute(name) ) {
1021            /* SJSAS 6419950
1022            coyoteRequest.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE,
1023                                 coyoteRequest);
1024            attr = coyoteRequest.getAttribute(Globals.CERTIFICATES_ATTR);
1025            if( attr != null) {
1026                attributes.put(Globals.CERTIFICATES_ATTR, attr);
1027            }
1028            attr = coyoteRequest.getAttribute(Globals.CIPHER_SUITE_ATTR);
1029            if(attr != null) {
1030                attributes.put(Globals.CIPHER_SUITE_ATTR, attr);
1031            }
1032            attr = coyoteRequest.getAttribute(Globals.KEY_SIZE_ATTR);
1033            if(attr != null) {
1034                attributes.put(Globals.KEY_SIZE_ATTR, attr);
1035            }
1036            */

1037            // START SJSAS 6419950
1038
populateSSLAttributes();
1039            // END SJSAS 6419950
1040
attr = attributes.get(name);
1041        }
1042        return attr;
1043    }
1044
1045
1046    /**
1047     * Test if a given name is one of the special Servlet-spec SSL attributes.
1048     */

1049    static boolean isSSLAttribute(String JavaDoc name) {
1050        return Globals.CERTIFICATES_ATTR.equals(name) ||
1051            Globals.CIPHER_SUITE_ATTR.equals(name) ||
1052            Globals.KEY_SIZE_ATTR.equals(name);
1053    }
1054
1055    /**
1056     * Return the names of all request attributes for this Request, or an
1057     * empty <code>Enumeration</code> if there are none.
1058     */

1059    public Enumeration JavaDoc getAttributeNames() {
1060        return new Enumerator(attributes.keySet(), true);
1061    }
1062
1063
1064    /**
1065     * Return the character encoding for this Request.
1066     */

1067    public String JavaDoc getCharacterEncoding() {
1068      return (coyoteRequest.getCharacterEncoding());
1069    }
1070
1071
1072    /**
1073     * Return the content length for this Request.
1074     */

1075    public int getContentLength() {
1076        return (coyoteRequest.getContentLength());
1077    }
1078
1079
1080    /**
1081     * Return the content type for this Request.
1082     */

1083    public String JavaDoc getContentType() {
1084        return (coyoteRequest.getContentType());
1085    }
1086
1087
1088    /**
1089     * Return the servlet input stream for this Request. The default
1090     * implementation returns a servlet input stream created by
1091     * <code>createInputStream()</code>.
1092     *
1093     * @exception IllegalStateException if <code>getReader()</code> has
1094     * already been called for this request
1095     * @exception IOException if an input/output error occurs
1096     */

1097    public ServletInputStream JavaDoc getInputStream() throws IOException JavaDoc {
1098
1099        if (usingReader)
1100            throw new IllegalStateException JavaDoc
1101                (sm.getString("coyoteRequest.getInputStream.ise"));
1102
1103        usingInputStream = true;
1104        if (inputStream == null) {
1105            inputStream = new CoyoteInputStream(inputBuffer);
1106        }
1107        return inputStream;
1108
1109    }
1110
1111
1112    /**
1113     * Return the preferred Locale that the client will accept content in,
1114     * based on the value for the first <code>Accept-Language</code> header
1115     * that was encountered. If the request did not specify a preferred
1116     * language, the server's default Locale is returned.
1117     */

1118    public Locale JavaDoc getLocale() {
1119
1120        if (!localesParsed)
1121            parseLocales();
1122
1123        if (locales.size() > 0) {
1124            return ((Locale JavaDoc) locales.get(0));
1125        } else {
1126            return (defaultLocale);
1127        }
1128
1129    }
1130
1131
1132    /**
1133     * Return the set of preferred Locales that the client will accept
1134     * content in, based on the values for any <code>Accept-Language</code>
1135     * headers that were encountered. If the request did not specify a
1136     * preferred language, the server's default Locale is returned.
1137     */

1138    public Enumeration JavaDoc getLocales() {
1139
1140        if (!localesParsed)
1141            parseLocales();
1142
1143        if (locales.size() > 0)
1144            return (new Enumerator(locales));
1145        ArrayList JavaDoc results = new ArrayList JavaDoc();
1146        results.add(defaultLocale);
1147        return (new Enumerator(results));
1148
1149    }
1150
1151
1152    /**
1153     * Return the value of the specified request parameter, if any; otherwise,
1154     * return <code>null</code>. If there is more than one value defined,
1155     * return only the first one.
1156     *
1157     * @param name Name of the desired request parameter
1158     */

1159    public String JavaDoc getParameter(String JavaDoc name) {
1160
1161        if (!requestParametersParsed)
1162            parseRequestParameters();
1163
1164        return coyoteRequest.getParameters().getParameter(name);
1165
1166    }
1167
1168
1169
1170    /**
1171     * Returns a <code>Map</code> of the parameters of this request.
1172     * Request parameters are extra information sent with the request.
1173     * For HTTP servlets, parameters are contained in the query string
1174     * or posted form data.
1175     *
1176     * @return A <code>Map</code> containing parameter names as keys
1177     * and parameter values as map values.
1178     */

1179    public Map JavaDoc getParameterMap() {
1180
1181        if (parameterMap.isLocked())
1182            return parameterMap;
1183
1184        Enumeration JavaDoc e = getParameterNames();
1185        while (e.hasMoreElements()) {
1186            String JavaDoc name = e.nextElement().toString();
1187            String JavaDoc[] values = getParameterValues(name);
1188            parameterMap.put(name, values);
1189        }
1190
1191        parameterMap.setLocked(true);
1192
1193        return parameterMap;
1194
1195    }
1196
1197
1198    /**
1199     * Return the names of all defined request parameters for this request.
1200     */

1201    public Enumeration JavaDoc getParameterNames() {
1202
1203        if (!requestParametersParsed)
1204            parseRequestParameters();
1205
1206        return coyoteRequest.getParameters().getParameterNames();
1207
1208    }
1209
1210
1211    /**
1212     * Return the defined values for the specified request parameter, if any;
1213     * otherwise, return <code>null</code>.
1214     *
1215     * @param name Name of the desired request parameter
1216     */

1217    public String JavaDoc[] getParameterValues(String JavaDoc name) {
1218
1219        if (!requestParametersParsed)
1220            parseRequestParameters();
1221
1222        return coyoteRequest.getParameters().getParameterValues(name);
1223
1224    }
1225
1226
1227    /**
1228     * Return the protocol and version used to make this Request.
1229     */

1230    public String JavaDoc getProtocol() {
1231        return coyoteRequest.protocol().toString();
1232    }
1233
1234
1235    /**
1236     * Read the Reader wrapping the input stream for this Request. The
1237     * default implementation wraps a <code>BufferedReader</code> around the
1238     * servlet input stream returned by <code>createInputStream()</code>.
1239     *
1240     * @exception IllegalStateException if <code>getInputStream()</code>
1241     * has already been called for this request
1242     * @exception IOException if an input/output error occurs
1243     */

1244    public BufferedReader JavaDoc getReader() throws IOException JavaDoc {
1245
1246        if (usingInputStream)
1247            throw new IllegalStateException JavaDoc
1248                (sm.getString("coyoteRequest.getReader.ise"));
1249
1250        usingReader = true;
1251        inputBuffer.checkConverter();
1252        if (reader == null) {
1253            reader = new CoyoteReader(inputBuffer);
1254        }
1255        return reader;
1256
1257    }
1258
1259
1260    /**
1261     * Return the real path of the specified virtual path.
1262     *
1263     * @param path Path to be translated
1264     *
1265     * @deprecated As of version 2.1 of the Java Servlet API, use
1266     * <code>ServletContext.getRealPath()</code>.
1267     */

1268    public String JavaDoc getRealPath(String JavaDoc path) {
1269
1270        if (context == null)
1271            return (null);
1272        ServletContext JavaDoc servletContext = context.getServletContext();
1273        if (servletContext == null)
1274            return (null);
1275        else {
1276            try {
1277                return (servletContext.getRealPath(path));
1278            } catch (IllegalArgumentException JavaDoc e) {
1279                return (null);
1280            }
1281        }
1282
1283    }
1284
1285
1286    /**
1287     * Return the remote IP address making this Request.
1288     */

1289    public String JavaDoc getRemoteAddr() {
1290        if (remoteAddr == null) {
1291
1292            // START SJSAS 6347215
1293
if (connector.getAuthPassthroughEnabled()
1294                    && connector.getProxyHandler() != null) {
1295                remoteAddr = connector.getProxyHandler().getRemoteAddress(
1296                                            getRequest());
1297                if (remoteAddr == null) {
1298                    log.warn(sm.getString(
1299                        "coyoteRequest.nullRemoteAddressFromProxy"));
1300                }
1301                return remoteAddr;
1302            }
1303            // END SJSAS 6347215
1304

1305            if (socket != null) {
1306                InetAddress JavaDoc inet = socket.getInetAddress();
1307                remoteAddr = inet.getHostAddress();
1308            } else {
1309                coyoteRequest.action
1310                    (ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE, coyoteRequest);
1311                remoteAddr = coyoteRequest.remoteAddr().toString();
1312            }
1313        }
1314        return remoteAddr;
1315    }
1316
1317
1318    /**
1319     * Return the remote host name making this Request.
1320     */

1321    public String JavaDoc getRemoteHost() {
1322        if (remoteHost == null) {
1323            if (!connector.getEnableLookups()) {
1324                remoteHost = getRemoteAddr();
1325            // START SJSAS 6347215
1326
} else if (connector.getAuthPassthroughEnabled()
1327                    && connector.getProxyHandler() != null) {
1328                String JavaDoc addr =
1329                    connector.getProxyHandler().getRemoteAddress(getRequest());
1330                if (addr != null) {
1331                    try {
1332                        remoteHost = InetAddress.getByName(addr).getHostName();
1333                    } catch (UnknownHostException JavaDoc e) {
1334                        log.warn(sm.getString(
1335                                    "coyoteRequest.unknownHost",
1336                                    addr),
1337                                 e);
1338                    }
1339                } else {
1340                    log.warn(sm.getString(
1341                        "coyoteRequest.nullRemoteAddressFromProxy"));
1342                }
1343            // END SJSAS 6347215
1344
} else if (socket != null) {
1345                InetAddress JavaDoc inet = socket.getInetAddress();
1346                remoteHost = inet.getHostName();
1347            } else {
1348                coyoteRequest.action
1349                    (ActionCode.ACTION_REQ_HOST_ATTRIBUTE, coyoteRequest);
1350                remoteHost = coyoteRequest.remoteHost().toString();
1351            }
1352        }
1353        return remoteHost;
1354    }
1355
1356    /**
1357     * Returns the Internet Protocol (IP) source port of the client
1358     * or last proxy that sent the request.
1359     */

1360    public int getRemotePort(){
1361        if (remotePort == -1) {
1362            if (socket != null) {
1363                remotePort = socket.getPort();
1364            } else {
1365                coyoteRequest.action
1366                    (ActionCode.ACTION_REQ_REMOTEPORT_ATTRIBUTE, coyoteRequest);
1367                remotePort = coyoteRequest.getRemotePort();
1368            }
1369        }
1370        return remotePort;
1371    }
1372
1373    /**
1374     * Returns the host name of the Internet Protocol (IP) interface on
1375     * which the request was received.
1376     */

1377    public String JavaDoc getLocalName(){
1378       if (localName == null) {
1379            if (socket != null) {
1380                InetAddress JavaDoc inet = socket.getLocalAddress();
1381                localName = inet.getHostName();
1382            } else {
1383                coyoteRequest.action
1384                    (ActionCode.ACTION_REQ_LOCAL_NAME_ATTRIBUTE, coyoteRequest);
1385                localName = coyoteRequest.localName().toString();
1386            }
1387        }
1388        return localName;
1389    }
1390
1391    /**
1392     * Returns the Internet Protocol (IP) address of the interface on
1393     * which the request was received.
1394     */

1395    public String JavaDoc getLocalAddr(){
1396        if (localAddr == null) {
1397            if (socket != null) {
1398                InetAddress JavaDoc inet = socket.getLocalAddress();
1399                localAddr = inet.getHostAddress();
1400            } else {
1401                coyoteRequest.action
1402                    (ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE, coyoteRequest);
1403                localAddr = coyoteRequest.localAddr().toString();
1404            }
1405        }
1406        return localAddr;
1407    }
1408
1409
1410    /**
1411     * Returns the Internet Protocol (IP) port number of the interface
1412     * on which the request was received.
1413     */

1414    public int getLocalPort(){
1415        if (localPort == -1){
1416            if (socket != null) {
1417                localPort = socket.getLocalPort();
1418            } else {
1419                coyoteRequest.action
1420                    (ActionCode.ACTION_REQ_LOCALPORT_ATTRIBUTE, coyoteRequest);
1421                localPort = coyoteRequest.getLocalPort();
1422            }
1423        }
1424        return localPort;
1425    }
1426    
1427    /**
1428     * Return a RequestDispatcher that wraps the resource at the specified
1429     * path, which may be interpreted as relative to the current request path.
1430     *
1431     * @param path Path of the resource to be wrapped
1432     */

1433    public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc path) {
1434
1435        if (context == null)
1436            return (null);
1437
1438        // If the path is already context-relative, just pass it through
1439
if (path == null)
1440            return (null);
1441        else if (path.startsWith("/"))
1442            return (context.getServletContext().getRequestDispatcher(path));
1443
1444        // Convert a request-relative path to a context-relative one
1445
String JavaDoc servletPath = (String JavaDoc) getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
1446        if (servletPath == null)
1447            servletPath = getServletPath();
1448
1449        // Add the path info, if there is any
1450
String JavaDoc pathInfo = getPathInfo();
1451        String JavaDoc requestPath = null;
1452
1453        if (pathInfo == null) {
1454            requestPath = servletPath;
1455        } else {
1456            requestPath = servletPath + pathInfo;
1457        }
1458
1459        int pos = requestPath.lastIndexOf('/');
1460        String JavaDoc relative = null;
1461        if (pos >= 0) {
1462            relative = RequestUtil.normalize
1463                (requestPath.substring(0, pos + 1) + path);
1464        } else {
1465            relative = RequestUtil.normalize(requestPath + path);
1466        }
1467
1468        return (context.getServletContext().getRequestDispatcher(relative));
1469
1470    }
1471
1472
1473    /**
1474     * Return the scheme used to make this Request.
1475     */

1476    public String JavaDoc getScheme() {
1477        // START S1AS 6170450
1478
if (getConnector() != null
1479                && getConnector().getAuthPassthroughEnabled()) {
1480            ProxyHandler proxyHandler = getConnector().getProxyHandler();
1481            if (proxyHandler != null
1482                    && proxyHandler.getSSLKeysize(getRequest()) > 0) {
1483                return "https";
1484            }
1485        }
1486        // END S1AS 6170450
1487

1488        return (coyoteRequest.scheme().toString());
1489    }
1490
1491
1492    /**
1493     * Return the server name responding to this Request.
1494     */

1495    public String JavaDoc getServerName() {
1496        return (coyoteRequest.serverName().toString());
1497    }
1498
1499
1500    /**
1501     * Return the server port responding to this Request.
1502     */

1503    public int getServerPort() {
1504        return (coyoteRequest.getServerPort());
1505    }
1506
1507
1508    /**
1509     * Was this request received on a secure connection?
1510     */

1511    public boolean isSecure() {
1512        return (secure);
1513    }
1514
1515
1516    /**
1517     * Remove the specified request attribute if it exists.
1518     *
1519     * @param name Name of the request attribute to remove
1520     */

1521    public void removeAttribute(String JavaDoc name) {
1522        Object JavaDoc value = null;
1523        boolean found = false;
1524
1525        // Remove the specified attribute
1526
// Check for read only attribute
1527
// requests are per thread so synchronization unnecessary
1528
if (readOnlyAttributes.containsKey(name)) {
1529            return;
1530        }
1531        found = attributes.containsKey(name);
1532        if (found) {
1533            value = attributes.get(name);
1534            attributes.remove(name);
1535        } else {
1536            return;
1537        }
1538
1539        // Notify interested application event listeners
1540
Object JavaDoc listeners[] = context.getApplicationEventListeners();
1541        if ((listeners == null) || (listeners.length == 0))
1542            return;
1543        ServletRequestAttributeEvent JavaDoc event =
1544          new ServletRequestAttributeEvent JavaDoc(context.getServletContext(),
1545                                           getRequest(), name, value);
1546        for (int i = 0; i < listeners.length; i++) {
1547            if (!(listeners[i] instanceof ServletRequestAttributeListener JavaDoc))
1548                continue;
1549            ServletRequestAttributeListener JavaDoc listener =
1550                (ServletRequestAttributeListener JavaDoc) listeners[i];
1551            try {
1552                listener.attributeRemoved(event);
1553            } catch (Throwable JavaDoc t) {
1554                log(sm.getString("coyoteRequest.attributeEvent"), t);
1555                // Error valve will pick this execption up and display it to user
1556
attributes.put( Globals.EXCEPTION_ATTR, t );
1557            }
1558        }
1559    }
1560
1561
1562    /**
1563     * Set the specified request attribute to the specified value.
1564     *
1565     * @param name Name of the request attribute to set
1566     * @param value The associated value
1567     */

1568    public void setAttribute(String JavaDoc name, Object JavaDoc value) {
1569    
1570        // Name cannot be null
1571
if (name == null)
1572            throw new IllegalArgumentException JavaDoc
1573                (sm.getString("coyoteRequest.setAttribute.namenull"));
1574
1575        // Null value is the same as removeAttribute()
1576
if (value == null) {
1577            removeAttribute(name);
1578            return;
1579        }
1580
1581        if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
1582            dispatcherType = value;
1583            return;
1584        } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
1585            requestDispatcherPath = value;
1586            return;
1587        }
1588
1589        Object JavaDoc oldValue = null;
1590        boolean replaced = false;
1591
1592        // Add or replace the specified attribute
1593
// Check for read only attribute
1594
// requests are per thread so synchronization unnecessary
1595
if (readOnlyAttributes.containsKey(name)) {
1596            return;
1597        }
1598
1599        oldValue = attributes.put(name, value);
1600        if (oldValue != null) {
1601            replaced = true;
1602        }
1603        
1604        // START SJSAS 6231069
1605
// Pass special attributes to the ngrizzly layer
1606
if (name.startsWith("grizzly.")) {
1607            coyoteRequest.setAttribute(name, value);
1608        }
1609        // END SJSAS 6231069
1610

1611        // Notify interested application event listeners
1612
Object JavaDoc listeners[] = context.getApplicationEventListeners();
1613        if ((listeners == null) || (listeners.length == 0))
1614            return;
1615        ServletRequestAttributeEvent JavaDoc event = null;
1616        if (replaced)
1617            event =
1618                new ServletRequestAttributeEvent JavaDoc(context.getServletContext(),
1619                                                 getRequest(), name, oldValue);
1620        else
1621            event =
1622                new ServletRequestAttributeEvent JavaDoc(context.getServletContext(),
1623                                                 getRequest(), name, value);
1624
1625        for (int i = 0; i < listeners.length; i++) {
1626            if (!(listeners[i] instanceof ServletRequestAttributeListener JavaDoc))
1627                continue;
1628            ServletRequestAttributeListener JavaDoc listener =
1629                (ServletRequestAttributeListener JavaDoc) listeners[i];
1630            try {
1631                if (replaced) {
1632                    listener.attributeReplaced(event);
1633                } else {
1634                    listener.attributeAdded(event);
1635                }
1636            } catch (Throwable JavaDoc t) {
1637                log(sm.getString("coyoteRequest.attributeEvent"), t);
1638                // Error valve will pick this execption up and display it to user
1639
attributes.put( Globals.EXCEPTION_ATTR, t );
1640            }
1641        }
1642    }
1643
1644
1645    /**
1646     * Overrides the name of the character encoding used in the body of this
1647     * request.
1648     *
1649     * This method must be called prior to reading request parameters or
1650     * reading input using <code>getReader()</code>. Otherwise, it has no
1651     * effect.
1652     *
1653     * @param env <code>String</code> containing the name of
1654     * the character encoding.
1655     * @throws java.io.UnsupportedEncodingException if this
1656     * ServletRequest is still in a state where a
1657     * character encoding may be set, but the specified
1658     * encoding is invalid
1659     *
1660     * @since Servlet 2.3
1661     */

1662    public void setCharacterEncoding(String JavaDoc enc)
1663        throws UnsupportedEncodingException JavaDoc {
1664
1665        // START SJSAS 4936855
1666
if (requestParametersParsed || usingReader) {
1667            log.warn(sm.getString("coyoteRequest.setCharacterEncoding.ise",
1668                                  enc));
1669            return;
1670        }
1671        // END SJSAS 4936855
1672

1673        // Ensure that the specified encoding is valid
1674
byte buffer[] = new byte[1];
1675        buffer[0] = (byte) 'a';
1676
1677        // START S1AS 6179607: Workaround for 6181598. Workaround should be
1678
// removed once the underlying issue in J2SE has been fixed.
1679
/*
1680         * String dummy = new String(buffer, enc);
1681         */

1682        // END S1AS 6179607
1683
// START S1AS 6179607
1684
final byte[] finalBuffer = buffer;
1685        final String JavaDoc finalEnc = enc;
1686        String JavaDoc dummy = null;
1687        if (System.getSecurityManager() != null) {
1688            try {
1689                dummy = (String JavaDoc) AccessController.doPrivileged(
1690                    new PrivilegedExceptionAction JavaDoc() {
1691                        public Object JavaDoc run() throws UnsupportedEncodingException JavaDoc {
1692                            return new String JavaDoc(finalBuffer, finalEnc);
1693                        }
1694                    });
1695            } catch (PrivilegedActionException JavaDoc pae) {
1696                throw (UnsupportedEncodingException JavaDoc) pae.getCause();
1697            }
1698        } else {
1699            dummy = new String JavaDoc(buffer, enc);
1700        }
1701        // END S1AS 6179607
1702

1703        // Save the validated encoding
1704
coyoteRequest.setCharacterEncoding(enc);
1705
1706    }
1707
1708
1709    // START S1AS 4703023
1710
/**
1711     * Static setter method for the maximum dispatch depth
1712     */

1713    public static void setMaxDispatchDepth(int depth) {
1714        maxDispatchDepth = depth;
1715    }
1716
1717
1718    public static int getMaxDispatchDepth(){
1719        return maxDispatchDepth;
1720    }
1721
1722    /**
1723     * Increment the depth of application dispatch
1724     */

1725    public int incrementDispatchDepth() {
1726        return ++dispatchDepth;
1727    }
1728
1729
1730    /**
1731     * Decrement the depth of application dispatch
1732     */

1733    public int decrementDispatchDepth() {
1734        return --dispatchDepth;
1735    }
1736
1737
1738    /**
1739     * Check if the application dispatching has reached the maximum
1740     */

1741    public boolean isMaxDispatchDepthReached() {
1742        return dispatchDepth > maxDispatchDepth;
1743    }
1744    // END S1AS 4703023
1745

1746
1747    // ---------------------------------------------------- HttpRequest Methods
1748

1749
1750    /**
1751     * Add a Cookie to the set of Cookies associated with this Request.
1752     *
1753     * @param cookie The new cookie
1754     */

1755    public void addCookie(Cookie JavaDoc cookie) {
1756
1757        // For compatibility only
1758
if (!cookiesParsed)
1759            parseCookies();
1760
1761        int size = 0;
1762        if (cookies != null) {
1763            size = cookies.length;
1764        }
1765
1766        Cookie JavaDoc[] newCookies = new Cookie JavaDoc[size + 1];
1767        for (int i = 0; i < size; i++) {
1768            newCookies[i] = cookies[i];
1769        }
1770        newCookies[size] = cookie;
1771
1772        cookies = newCookies;
1773
1774    }
1775
1776
1777    /**
1778     * Add a Header to the set of Headers associated with this Request.
1779     *
1780     * @param name The new header name
1781     * @param value The new header value
1782     */

1783    public void addHeader(String JavaDoc name, String JavaDoc value) {
1784        // Not used
1785
}
1786
1787
1788    /**
1789     * Add a Locale to the set of preferred Locales for this Request. The
1790     * first added Locale will be the first one returned by getLocales().
1791     *
1792     * @param locale The new preferred Locale
1793     */

1794    public void addLocale(Locale JavaDoc locale) {
1795        locales.add(locale);
1796    }
1797
1798
1799    /**
1800     * Add a parameter name and corresponding set of values to this Request.
1801     * (This is used when restoring the original request on a form based
1802     * login).
1803     *
1804     * @param name Name of this request parameter
1805     * @param values Corresponding values for this request parameter
1806     */

1807    public void addParameter(String JavaDoc name, String JavaDoc values[]) {
1808        coyoteRequest.getParameters().addParameterValues(name, values);
1809    }
1810
1811
1812    /**
1813     * Clear the collection of Cookies associated with this Request.
1814     */

1815    public void clearCookies() {
1816        cookiesParsed = true;
1817        cookies = null;
1818    }
1819
1820
1821    /**
1822     * Clear the collection of Headers associated with this Request.
1823     */

1824    public void clearHeaders() {
1825        // Not used
1826
}
1827
1828
1829    /**
1830     * Clear the collection of Locales associated with this Request.
1831     */

1832    public void clearLocales() {
1833        locales.clear();
1834    }
1835
1836
1837    /**
1838     * Clear the collection of parameters associated with this Request.
1839     */

1840    public void clearParameters() {
1841        // Not used
1842
}
1843
1844
1845    /**
1846     * Set the authentication type used for this request, if any; otherwise
1847     * set the type to <code>null</code>. Typical values are "BASIC",
1848     * "DIGEST", or "SSL".
1849     *
1850     * @param type The authentication type used
1851     */

1852    public void setAuthType(String JavaDoc type) {
1853        this.authType = type;
1854    }
1855
1856
1857    /**
1858     * Set the context path for this Request. This will normally be called
1859     * when the associated Context is mapping the Request to a particular
1860     * Wrapper.
1861     *
1862     * @param path The context path
1863     */

1864    public void setContextPath(String JavaDoc path) {
1865
1866        if (path == null) {
1867            mappingData.contextPath.setString("");
1868        } else {
1869            mappingData.contextPath.setString(path);
1870        }
1871
1872    }
1873
1874
1875    /**
1876     * Set the HTTP request method used for this Request.
1877     *
1878     * @param method The request method
1879     */

1880    public void setMethod(String JavaDoc method) {
1881        // Not used
1882
}
1883
1884
1885    /**
1886     * Set the query string for this Request. This will normally be called
1887     * by the HTTP Connector, when it parses the request headers.
1888     *
1889     * @param query The query string
1890     */

1891    public void setQueryString(String JavaDoc query) {
1892        // Not used
1893
}
1894
1895
1896    /**
1897     * Set the path information for this Request. This will normally be called
1898     * when the associated Context is mapping the Request to a particular
1899     * Wrapper.
1900     *
1901     * @param path The path information
1902     */

1903    public void setPathInfo(String JavaDoc path) {
1904        mappingData.pathInfo.setString(path);
1905    }
1906
1907
1908    /**
1909     * Set a flag indicating whether or not the requested session ID for this
1910     * request came in through a cookie. This is normally called by the
1911     * HTTP Connector, when it parses the request headers.
1912     *
1913     * @param flag The new flag
1914     */

1915    public void setRequestedSessionCookie(boolean flag) {
1916
1917        this.requestedSessionCookie = flag;
1918
1919    }
1920
1921
1922    /**
1923     * Set the requested session ID for this request. This is normally called
1924     * by the HTTP Connector, when it parses the request headers.
1925     *
1926     * @param id The new session id
1927     */

1928    public void setRequestedSessionId(String JavaDoc id) {
1929
1930        this.requestedSessionId = id;
1931
1932    }
1933
1934
1935    /**
1936     * Set a flag indicating whether or not the requested session ID for this
1937     * request came in through a URL. This is normally called by the
1938     * HTTP Connector, when it parses the request headers.
1939     *
1940     * @param flag The new flag
1941     */

1942    public void setRequestedSessionURL(boolean flag) {
1943
1944        this.requestedSessionURL = flag;
1945
1946    }
1947
1948
1949    /**
1950     * Set the unparsed request URI for this Request. This will normally be
1951     * called by the HTTP Connector, when it parses the request headers.
1952     *
1953     * @param uri The request URI
1954     */

1955    public void setRequestURI(String JavaDoc uri) {
1956        // Not used
1957
}
1958
1959
1960    /**
1961     * Set the decoded request URI.
1962     *
1963     * @param uri The decoded request URI
1964     */

1965    public void setDecodedRequestURI(String JavaDoc uri) {
1966        // Not used
1967
}
1968
1969
1970    /**
1971     * Get the decoded request URI.
1972     *
1973     * @return the URL decoded request URI
1974     */

1975    public String JavaDoc getDecodedRequestURI() {
1976        return (coyoteRequest.decodedURI().toString());
1977    }
1978
1979
1980    /**
1981     * Get the decoded request URI.
1982     *
1983     * @return the URL decoded request URI
1984     */

1985    public MessageBytes getDecodedRequestURIMB() {
1986        return (coyoteRequest.decodedURI());
1987    }
1988
1989
1990    /**
1991     * Set the servlet path for this Request. This will normally be called
1992     * when the associated Context is mapping the Request to a particular
1993     * Wrapper.
1994     *
1995     * @param path The servlet path
1996     */

1997    public void setServletPath(String JavaDoc path) {
1998        if (path != null)
1999            mappingData.wrapperPath.setString(path);
2000    }
2001
2002
2003    /**
2004     * Set the Principal who has been authenticated for this Request. This
2005     * value is also used to calculate the value to be returned by the
2006     * <code>getRemoteUser()</code> method.
2007     *
2008     * @param principal The user Principal
2009     */

2010    public void setUserPrincipal(Principal JavaDoc principal) {
2011
2012        if (SecurityUtil.isPackageProtectionEnabled()){
2013            HttpSession JavaDoc session = getSession(false);
2014            if ( (subject != null) &&
2015                 (!subject.getPrincipals().contains(principal)) ){
2016                subject.getPrincipals().add(principal);
2017            } else if (session != null &&
2018                            session.getAttribute(Globals.SUBJECT_ATTR) == null) {
2019                subject = new Subject JavaDoc();
2020                subject.getPrincipals().add(principal);
2021            }
2022            if (session != null){
2023                session.setAttribute(Globals.SUBJECT_ATTR, subject);
2024            }
2025        }
2026
2027        this.userPrincipal = principal;
2028    }
2029
2030
2031    // --------------------------------------------- HttpServletRequest Methods
2032

2033
2034    /**
2035     * Return the authentication type used for this Request.
2036     */

2037    public String JavaDoc getAuthType() {
2038        return (authType);
2039    }
2040
2041
2042    /**
2043     * Return the portion of the request URI used to select the Context
2044     * of the Request.
2045     */

2046    public String JavaDoc getContextPath() {
2047        return (mappingData.contextPath.toString());
2048    }
2049
2050
2051    /**
2052     * Get the context path.
2053     *
2054     * @return the context path
2055     */

2056    public MessageBytes getContextPathMB() {
2057        return (mappingData.contextPath);
2058    }
2059
2060
2061    /**
2062     * Return the set of Cookies received with this Request.
2063     */

2064    public Cookie JavaDoc[] getCookies() {
2065
2066        if (!cookiesParsed)
2067            parseCookies();
2068
2069        return cookies;
2070
2071    }
2072
2073
2074    /**
2075     * Set the set of cookies recieved with this Request.
2076     */

2077    public void setCookies(Cookie JavaDoc[] cookies) {
2078
2079        this.cookies = cookies;
2080
2081    }
2082
2083
2084    /**
2085     * Return the value of the specified date header, if any; otherwise
2086     * return -1.
2087     *
2088     * @param name Name of the requested date header
2089     *
2090     * @exception IllegalArgumentException if the specified header value
2091     * cannot be converted to a date
2092     */

2093    public long getDateHeader(String JavaDoc name) {
2094
2095        String JavaDoc value = getHeader(name);
2096        if (value == null)
2097            return (-1L);
2098
2099        // Attempt to convert the date header in a variety of formats
2100
long result = FastHttpDateFormat.parseDate(value, formats);
2101        if (result != (-1L)) {
2102            return result;
2103        }
2104        throw new IllegalArgumentException JavaDoc(value);
2105
2106    }
2107
2108
2109    /**
2110     * Return the first value of the specified header, if any; otherwise,
2111     * return <code>null</code>
2112     *
2113     * @param name Name of the requested header
2114     */

2115    public String JavaDoc getHeader(String JavaDoc name) {
2116        return coyoteRequest.getHeader(name);
2117    }
2118
2119
2120    /**
2121     * Return all of the values of the specified header, if any; otherwise,
2122     * return an empty enumeration.
2123     *
2124     * @param name Name of the requested header
2125     */

2126    public Enumeration JavaDoc getHeaders(String JavaDoc name) {
2127        return coyoteRequest.getMimeHeaders().values(name);
2128    }
2129
2130
2131    /**
2132     * Return the names of all headers received with this request.
2133     */

2134    public Enumeration JavaDoc getHeaderNames() {
2135        return coyoteRequest.getMimeHeaders().names();
2136    }
2137
2138
2139    /**
2140     * Return the value of the specified header as an integer, or -1 if there
2141     * is no such header for this request.
2142     *
2143     * @param name Name of the requested header
2144     *
2145     * @exception IllegalArgumentException if the specified header value
2146     * cannot be converted to an integer
2147     */

2148    public int getIntHeader(String JavaDoc name) {
2149
2150        String JavaDoc value = getHeader(name);
2151        if (value == null) {
2152            return (-1);
2153        } else {
2154            return (Integer.parseInt(value));
2155        }
2156
2157    }
2158
2159
2160    /**
2161     * Return the HTTP request method used in this Request.
2162     */

2163    public String JavaDoc getMethod() {
2164        return coyoteRequest.method().toString();
2165    }
2166
2167
2168    /**
2169     * Return the path information associated with this Request.
2170     */

2171    public String JavaDoc getPathInfo() {
2172        return (mappingData.pathInfo.toString());
2173    }
2174
2175
2176    /**
2177     * Get the path info.
2178     *
2179     * @return the path info
2180     */

2181    public MessageBytes getPathInfoMB() {
2182        return (mappingData.pathInfo);
2183    }
2184
2185
2186    /**
2187     * Return the extra path information for this request, translated
2188     * to a real path.
2189     */

2190    public String JavaDoc getPathTranslated() {
2191
2192        if (context == null)
2193            return (null);
2194
2195        if (getPathInfo() == null) {
2196            return (null);
2197        } else {
2198            return (context.getServletContext().getRealPath(getPathInfo()));
2199        }
2200
2201    }
2202
2203
2204    /**
2205     * Return the query string associated with this request.
2206     */

2207    public String JavaDoc getQueryString() {
2208        String JavaDoc queryString = coyoteRequest.queryString().toString();
2209
2210        if (queryString == null || queryString.equals("")) {
2211            return (null);
2212        } else {
2213            return queryString;
2214        }
2215    }
2216
2217
2218    /**
2219     * Return the name of the remote user that has been authenticated
2220     * for this Request.
2221     */

2222    public String JavaDoc getRemoteUser() {
2223
2224        if (userPrincipal != null) {
2225            return (userPrincipal.getName());
2226        } else {
2227            return (null);
2228        }
2229
2230    }
2231
2232
2233    /**
2234     * Get the request path.
2235     *
2236     * @return the request path
2237     */

2238    public MessageBytes getRequestPathMB() {
2239        return (mappingData.requestPath);
2240    }
2241
2242
2243    /**
2244     * Return the session identifier included in this request, if any.
2245     */

2246    public String JavaDoc getRequestedSessionId() {
2247        return (requestedSessionId);
2248    }
2249
2250
2251    /**
2252     * Return the request URI for this request.
2253     */

2254    public String JavaDoc getRequestURI() {
2255        return coyoteRequest.requestURI().toString();
2256    }
2257
2258
2259    /**
2260     * Reconstructs the URL the client used to make the request.
2261     * The returned URL contains a protocol, server name, port
2262     * number, and server path, but it does not include query
2263     * string parameters.
2264     * <p>
2265     * Because this method returns a <code>StringBuffer</code>,
2266     * not a <code>String</code>, you can modify the URL easily,
2267     * for example, to append query parameters.
2268     * <p>
2269     * This method is useful for creating redirect messages and
2270     * for reporting errors.
2271     *
2272     * @return A <code>StringBuffer</code> object containing the
2273     * reconstructed URL
2274     */

2275    public StringBuffer JavaDoc getRequestURL() {
2276
2277        StringBuffer JavaDoc url = new StringBuffer JavaDoc();
2278        String JavaDoc scheme = getScheme();
2279        int port = getServerPort();
2280        if (port < 0)
2281            port = 80; // Work around java.net.URL bug
2282

2283        url.append(scheme);
2284        url.append("://");
2285        url.append(getServerName());
2286        if ((scheme.equals("http") && (port != 80))
2287            || (scheme.equals("https") && (port != 443))) {
2288            url.append(':');
2289            url.append(port);
2290        }
2291        url.append(getRequestURI());
2292
2293        return (url);
2294
2295    }
2296
2297
2298    /**
2299     * Return the portion of the request URI used to select the servlet
2300     * that will process this request.
2301     */

2302    public String JavaDoc getServletPath() {
2303        return (mappingData.wrapperPath.toString());
2304    }
2305
2306
2307    /**
2308     * Get the servlet path.
2309     *
2310     * @return the servlet path
2311     */

2312    public MessageBytes getServletPathMB() {
2313        return (mappingData.wrapperPath);
2314    }
2315
2316
2317    /**
2318     * Return the session associated with this Request, creating one
2319     * if necessary.
2320     */

2321    public HttpSession JavaDoc getSession() {
2322        Session JavaDoc session = doGetSession(true);
2323        if (session != null) {
2324            return session.getSession();
2325        } else {
2326            return null;
2327        }
2328    }
2329
2330
2331    /**
2332     * Return the session associated with this Request, creating one
2333     * if necessary and requested.
2334     *
2335     * @param create Create a new session if one does not exist
2336     */

2337    public HttpSession JavaDoc getSession(boolean create) {
2338        Session JavaDoc session = doGetSession(create);
2339        if (session != null) {
2340            return session.getSession();
2341        } else {
2342            return null;
2343        }
2344    }
2345    
2346    /**
2347     * set the session - this method is not for general use
2348     *
2349     * @param the new session
2350     */

2351    public void setSession(Session JavaDoc newSess) {
2352        session = newSess;
2353    }
2354
2355
2356    /**
2357     * Return <code>true</code> if the session identifier included in this
2358     * request came from a cookie.
2359     */

2360    public boolean isRequestedSessionIdFromCookie() {
2361
2362        if (requestedSessionId != null)
2363            return (requestedSessionCookie);
2364        else
2365            return (false);
2366
2367    }
2368
2369
2370    /**
2371     * Return <code>true</code> if the session identifier included in this
2372     * request came from the request URI.
2373     */

2374    public boolean isRequestedSessionIdFromURL() {
2375
2376        if (requestedSessionId != null)
2377            return (requestedSessionURL);
2378        else
2379            return (false);
2380
2381    }
2382
2383
2384    /**
2385     * Return <code>true</code> if the session identifier included in this
2386     * request came from the request URI.
2387     *
2388     * @deprecated As of Version 2.1 of the Java Servlet API, use
2389     * <code>isRequestedSessionIdFromURL()</code> instead.
2390     */

2391    public boolean isRequestedSessionIdFromUrl() {
2392        return (isRequestedSessionIdFromURL());
2393    }
2394
2395
2396    /**
2397     * Return <code>true</code> if the session identifier included in this
2398     * request identifies a valid session.
2399     */

2400    public boolean isRequestedSessionIdValid() {
2401
2402        if (requestedSessionId == null)
2403            return (false);
2404        if (context == null)
2405            return (false);
2406        Manager manager = context.getManager();
2407        if (manager == null)
2408            return (false);
2409        Session JavaDoc session = null;
2410        try {
2411            session = manager.findSession(requestedSessionId);
2412        } catch (IOException JavaDoc e) {
2413            session = null;
2414        }
2415        if ((session != null) && session.isValid())
2416            return (true);
2417        else
2418            return (false);
2419
2420    }
2421
2422
2423    /**
2424     * Return <code>true</code> if the authenticated user principal
2425     * possesses the specified role name.
2426     *
2427     * @param role Role name to be validated
2428     */

2429    public boolean isUserInRole(String JavaDoc role) {
2430
2431        // BEGIN RIMOD 4949842
2432
/*
2433         * Must get userPrincipal through getUserPrincipal(), can't assume
2434         * it has already been set since it may be coming from core.
2435         */

2436        Principal JavaDoc userPrincipal = this.getUserPrincipal();
2437        // END RIMOD 4949842
2438

2439        // Have we got an authenticated principal at all?
2440
if (userPrincipal == null)
2441            return (false);
2442
2443        // Identify the Realm we will use for checking role assignmenets
2444
if (context == null)
2445            return (false);
2446        Realm realm = context.getRealm();
2447        if (realm == null)
2448            return (false);
2449
2450        // Check for a role alias defined in a <security-role-ref> element
2451
if (wrapper != null) {
2452            String JavaDoc realRole = wrapper.findSecurityReference(role);
2453
2454            //START SJSAS 6232464
2455
if ((realRole != null) &&
2456                //realm.hasRole(userPrincipal, realRole))
2457
realm.hasRole(this, (HttpResponse) response,
2458                    userPrincipal, realRole))
2459                return (true);
2460        }
2461
2462        // Check for a role defined directly as a <security-role>
2463

2464        //return (realm.hasRole(userPrincipal, role));
2465
return (realm.hasRole(this, (HttpResponse) response,
2466                    userPrincipal, role));
2467        //END SJSAS 6232464
2468
}
2469
2470
2471    /**
2472     * Return the principal that has been authenticated for this Request.
2473     */

2474    public Principal JavaDoc getUserPrincipal() {
2475        return (userPrincipal);
2476    }
2477
2478
2479    /**
2480     * Return the session associated with this Request, creating one
2481     * if necessary.
2482     */

2483    public Session JavaDoc getSessionInternal() {
2484        return doGetSession(true);
2485    }
2486
2487
2488    /**
2489     * Return the session associated with this Request, creating one
2490     * if necessary and requested.
2491     *
2492     * @param create Create a new session if one does not exist
2493     */

2494    public Session JavaDoc getSessionInternal(boolean create) {
2495        return doGetSession(create);
2496    }
2497
2498
2499    // ------------------------------------------------------ Protected Methods
2500

2501
2502    protected Session JavaDoc doGetSession(boolean create) {
2503
2504        // There cannot be a session if no context has been assigned yet
2505
if (context == null)
2506            return (null);
2507
2508        // Return the current session if it exists and is valid
2509
if ((session != null) && !session.isValid())
2510            session = null;
2511        if (session != null)
2512            return (session);
2513
2514        // Return the requested session if it exists and is valid
2515
Manager manager = null;
2516        if (context != null)
2517            manager = context.getManager();
2518        if (manager == null)
2519            return (null); // Sessions are not supported
2520
if (requestedSessionId != null) {
2521            try {
2522                session = manager.findSession(requestedSessionId);
2523            } catch (IOException JavaDoc e) {
2524                session = null;
2525            }
2526            if ((session != null) && !session.isValid())
2527                session = null;
2528            if (session != null) {
2529                session.access();
2530                return (session);
2531            }
2532        }
2533
2534        // Create a new session if requested and the response is not committed
2535
if (!create)
2536            return (null);
2537        if ((context != null) && (response != null) &&
2538            context.getCookies() &&
2539            response.getResponse().isCommitted()) {
2540            throw new IllegalStateException JavaDoc
2541              (sm.getString("coyoteRequest.sessionCreateCommitted"));
2542        }
2543
2544        // START S1AS8PE 4817642
2545
if (requestedSessionId != null && context.getReuseSessionID()) {
2546            session = manager.createSession(requestedSessionId);
2547        } else {
2548        // END S1AS8PE 4817642
2549
session = manager.createSession();
2550        // START S1AS8PE 4817642
2551
}
2552        // END S1AS8PE 4817642
2553

2554        // Creating a new session cookie based on that session
2555
if ((session != null) && (getContext() != null)
2556                && getContext().getCookies()) {
2557            Cookie JavaDoc cookie = new Cookie JavaDoc(Globals.SESSION_COOKIE_NAME,
2558                                       session.getIdInternal());
2559            configureSessionCookie(cookie);
2560            ((HttpServletResponse JavaDoc) response).addCookie(cookie);
2561        }
2562
2563        if (session != null) {
2564            session.access();
2565            return (session);
2566        } else {
2567            return (null);
2568        }
2569
2570    }
2571
2572    /**
2573     * Configures the given JSESSIONID cookie.
2574     *
2575     * @param cookie The JSESSIONID cookie to be configured
2576     */

2577    protected void configureSessionCookie(Cookie JavaDoc cookie) {
2578        cookie.setMaxAge(-1);
2579        String JavaDoc contextPath = null;
2580        if (getContext() != null) {
2581            // START OF SJSAS 6231069
2582
// contextPath = getContext().getEncodedPath();
2583
contextPath = getContext().getPath();
2584            // END OF SJSAS 6231069
2585
}
2586        if ((contextPath != null) && (contextPath.length() > 0)) {
2587            cookie.setPath(contextPath);
2588        } else {
2589            cookie.setPath("/");
2590        }
2591        if (isSecure()) {
2592            cookie.setSecure(true);
2593        }
2594    }
2595
2596
2597    /**
2598     * Parse cookies.
2599     */

2600    protected void parseCookies() {
2601
2602        cookiesParsed = true;
2603
2604        Cookies serverCookies = coyoteRequest.getCookies();
2605        int count = serverCookies.getCookieCount();
2606        if (count <= 0)
2607            return;
2608
2609        cookies = new Cookie JavaDoc[count];
2610
2611        int idx=0;
2612        for (int i = 0; i < count; i++) {
2613            ServerCookie scookie = serverCookies.getCookie(i);
2614            try {
2615                Cookie JavaDoc cookie = new Cookie JavaDoc(scookie.getName().toString(),
2616                                           scookie.getValue().toString());
2617                cookie.setPath(scookie.getPath().toString());
2618                cookie.setVersion(scookie.getVersion());
2619                String JavaDoc domain = scookie.getDomain().toString();
2620                if (domain != null) {
2621                    cookie.setDomain(scookie.getDomain().toString());
2622                }
2623                cookies[idx++] = cookie;
2624            } catch(IllegalArgumentException JavaDoc e) {
2625                ; // Ignore bad cookie.
2626
}
2627        }
2628        if( idx < count ) {
2629            Cookie JavaDoc [] ncookies = new Cookie JavaDoc[idx];
2630            System.arraycopy(cookies, 0, ncookies, 0, idx);
2631            cookies = ncookies;
2632        }
2633
2634    }
2635
2636
2637    /**
2638     * Parse request parameters.
2639     */

2640    protected void parseRequestParameters() {
2641
2642        /* SJSAS 4936855
2643        requestParametersParsed = true;
2644        */

2645
2646        Parameters parameters = coyoteRequest.getParameters();
2647
2648        // getCharacterEncoding() may have been overridden to search for
2649
// hidden form field containing request encoding
2650
String JavaDoc enc = getCharacterEncoding();
2651        // START SJSAS 4936855
2652
// Delay updating requestParametersParsed to TRUE until
2653
// after getCharacterEncoding() has been called, because
2654
// getCharacterEncoding() may cause setCharacterEncoding() to be
2655
// called, and the latter will ignore the specified encoding if
2656
// requestParametersParsed is TRUE
2657
requestParametersParsed = true;
2658        // END SJSAS 4936855
2659
if (enc != null) {
2660            parameters.setEncoding(enc);
2661            parameters.setQueryStringEncoding(enc);
2662        } else {
2663            parameters.setEncoding
2664                (org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING);
2665            parameters.setQueryStringEncoding
2666                (org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING);
2667        }
2668
2669        parameters.handleQueryParameters();
2670
2671        if (usingInputStream || usingReader)
2672            return;
2673
2674        if (!getMethod().equalsIgnoreCase("POST"))
2675            return;
2676
2677        String JavaDoc contentType = getContentType();
2678        if (contentType == null)
2679            contentType = "";
2680        int semicolon = contentType.indexOf(';');
2681        if (semicolon >= 0) {
2682            contentType = contentType.substring(0, semicolon).trim();
2683        } else {
2684            contentType = contentType.trim();
2685        }
2686        if (!("application/x-www-form-urlencoded".equals(contentType)))
2687            return;
2688
2689        int len = getContentLength();
2690
2691        if (len > 0) {
2692            int maxPostSize = ((CoyoteConnector) connector).getMaxPostSize();
2693            if ((maxPostSize > 0) && (len > maxPostSize)) {
2694                log(sm.getString("coyoteRequest.postTooLarge"));
2695                throw new IllegalStateException JavaDoc("Post too large");
2696            }
2697            try {
2698                /* SJSAS 6346738
2699                byte[] formData = null;
2700                if (len < CACHED_POST_LEN) {
2701                    if (postData == null)
2702                        postData = new byte[CACHED_POST_LEN];
2703                    formData = postData;
2704                } else {
2705                    formData = new byte[len];
2706                }
2707                int actualLen = readPostBody(formData, len);
2708                if (actualLen == len) {
2709                    parameters.processParameters(formData, 0, len);
2710                }
2711                */

2712                // START SJSAS 6346738
2713
byte[] formData = getPostBody();
2714                if (formData != null) {
2715                    parameters.processParameters(formData, 0, len);
2716                }
2717                // END SJSAS 6346738
2718
} catch (Throwable JavaDoc t) {
2719                ; // Ignore
2720
}
2721        }
2722
2723    }
2724
2725
2726    // START SJSAS 6346738
2727
/**
2728     * Gets the POST body of this request.
2729     *
2730     * @return The POST body of this request
2731     */

2732    protected byte[] getPostBody() throws IOException JavaDoc {
2733
2734        int len = getContentLength();
2735        byte[] formData = null;
2736
2737        if (len < CACHED_POST_LEN) {
2738            if (postData == null)
2739                postData = new byte[CACHED_POST_LEN];
2740            formData = postData;
2741        } else {
2742            formData = new byte[len];
2743        }
2744        int actualLen = readPostBody(formData, len);
2745        if (actualLen == len) {
2746            return formData;
2747        }
2748
2749        return null;
2750    }
2751    // END SJSAS 6346738
2752

2753
2754    /**
2755     * Read post body in an array.
2756     */

2757    protected int readPostBody(byte body[], int len)
2758        throws IOException JavaDoc {
2759
2760        int offset = 0;
2761        do {
2762            int inputLen = getStream().read(body, offset, len - offset);
2763            if (inputLen <= 0) {
2764                return offset;
2765            }
2766            offset += inputLen;
2767        } while ((len - offset) > 0);
2768        return len;
2769
2770    }
2771
2772
2773    /**
2774     * Parse request locales.
2775     */

2776    protected void parseLocales() {
2777
2778        localesParsed = true;
2779
2780        Enumeration JavaDoc values = getHeaders("accept-language");
2781
2782        while (values.hasMoreElements()) {
2783            String JavaDoc value = values.nextElement().toString();
2784            parseLocalesHeader(value);
2785        }
2786
2787    }
2788
2789
2790    /**
2791     * Parse accept-language header value.
2792     */

2793    protected void parseLocalesHeader(String JavaDoc value) {
2794
2795        // Store the accumulated languages that have been requested in
2796
// a local collection, sorted by the quality value (so we can
2797
// add Locales in descending order). The values will be ArrayLists
2798
// containing the corresponding Locales to be added
2799
TreeMap JavaDoc locales = new TreeMap JavaDoc();
2800
2801        // Preprocess the value to remove all whitespace
2802
int white = value.indexOf(' ');
2803        if (white < 0)
2804            white = value.indexOf('\t');
2805        if (white >= 0) {
2806            StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
2807            int len = value.length();
2808            for (int i = 0; i < len; i++) {
2809                char ch = value.charAt(i);
2810                if ((ch != ' ') && (ch != '\t'))
2811                    sb.append(ch);
2812            }
2813            value = sb.toString();
2814        }
2815
2816        // Process each comma-delimited language specification
2817
parser.setString(value); // ASSERT: parser is available to us
2818
int length = parser.getLength();
2819        while (true) {
2820
2821            // Extract the next comma-delimited entry
2822
int start = parser.getIndex();
2823            if (start >= length)
2824                break;
2825            int end = parser.findChar(',');
2826            String JavaDoc entry = parser.extract(start, end).trim();
2827            parser.advance(); // For the following entry
2828

2829            // Extract the quality factor for this entry
2830
double quality = 1.0;
2831            int semi = entry.indexOf(";q=");
2832            if (semi >= 0) {
2833                try {
2834                    quality = Double.parseDouble(entry.substring(semi + 3));
2835                } catch (NumberFormatException JavaDoc e) {
2836                    quality = 0.0;
2837                }
2838                entry = entry.substring(0, semi);
2839            }
2840
2841            // Skip entries we are not going to keep track of
2842
if (quality < 0.00005)
2843                continue; // Zero (or effectively zero) quality factors
2844
if ("*".equals(entry))
2845                continue; // FIXME - "*" entries are not handled
2846

2847            // Extract the language and country for this entry
2848
String JavaDoc language = null;
2849            String JavaDoc country = null;
2850            String JavaDoc variant = null;
2851            int dash = entry.indexOf('-');
2852            if (dash < 0) {
2853                language = entry;
2854                country = "";
2855                variant = "";
2856            } else {
2857                language = entry.substring(0, dash);
2858                country = entry.substring(dash + 1);
2859                int vDash = country.indexOf('-');
2860                if (vDash > 0) {
2861                    String JavaDoc cTemp = country.substring(0, vDash);
2862                    variant = country.substring(vDash + 1);
2863                    country = cTemp;
2864                } else {
2865                    variant = "";
2866                }
2867            }
2868
2869            // Add a new Locale to the list of Locales for this quality level
2870
Locale JavaDoc locale = new Locale JavaDoc(language, country, variant);
2871            Double JavaDoc key = new Double JavaDoc(-quality); // Reverse the order
2872
ArrayList JavaDoc values = (ArrayList JavaDoc) locales.get(key);
2873            if (values == null) {
2874                values = new ArrayList JavaDoc();
2875                locales.put(key, values);
2876            }
2877            values.add(locale);
2878
2879        }
2880
2881        // Process the quality values in highest->lowest order (due to
2882
// negating the Double value when creating the key)
2883
Iterator JavaDoc keys = locales.keySet().iterator();
2884        while (keys.hasNext()) {
2885            Double JavaDoc key = (Double JavaDoc) keys.next();
2886            ArrayList JavaDoc list = (ArrayList JavaDoc) locales.get(key);
2887            Iterator JavaDoc values = list.iterator();
2888            while (values.hasNext()) {
2889                Locale JavaDoc locale = (Locale JavaDoc) values.next();
2890                addLocale(locale);
2891            }
2892        }
2893
2894    }
2895
2896
2897    // START CR 6309511
2898
/**
2899     * Parse session id in URL.
2900     */

2901    protected void parseSessionId() {
2902
2903        CharChunk uriCC = coyoteRequest.decodedURI().getCharChunk();
2904        int semicolon = uriCC.indexOf(match, 0, match.length(), 0);
2905
2906        if (semicolon > 0) {
2907
2908            // Parse session ID, and extract it from the decoded request URI
2909
int start = uriCC.getStart();
2910            int end = uriCC.getEnd();
2911
2912            int sessionIdStart = start + semicolon + match.length();
2913            int semicolon2 = uriCC.indexOf(';', sessionIdStart);
2914            /* SJSAS 6346226
2915            if (semicolon2 >= 0) {
2916                setRequestedSessionId
2917                    (new String(uriCC.getBuffer(), sessionIdStart,
2918                                semicolon2 - semicolon - match.length()));
2919            } else {
2920                setRequestedSessionId
2921                    (new String(uriCC.getBuffer(), sessionIdStart,
2922                                end - sessionIdStart));
2923            }
2924            */

2925            // START SJSAS 6346226
2926
String JavaDoc sessionId = null;
2927            if (semicolon2 >= 0) {
2928                sessionId = new String JavaDoc(uriCC.getBuffer(), sessionIdStart,
2929                                       semicolon2 - semicolon - match.length());
2930            } else {
2931                sessionId = new String JavaDoc(uriCC.getBuffer(), sessionIdStart,
2932                                       end - sessionIdStart);
2933            }
2934            int jrouteIndex = sessionId.lastIndexOf(':');
2935            if (jrouteIndex > 0) {
2936                setRequestedSessionId(sessionId.substring(0, jrouteIndex));
2937                if (jrouteIndex < (sessionId.length()-1)) {
2938            setJrouteId(sessionId.substring(jrouteIndex+1));
2939                }
2940        } else {
2941                setRequestedSessionId(sessionId);
2942            }
2943            // END SJSAS 6346226
2944

2945            setRequestedSessionURL(true);
2946
2947            // Extract session ID from request URI
2948
ByteChunk uriBC = coyoteRequest.requestURI().getByteChunk();
2949            start = uriBC.getStart();
2950            end = uriBC.getEnd();
2951            semicolon = uriBC.indexOf(match, 0, match.length(), 0);
2952
2953            if (semicolon > 0) {
2954                sessionIdStart = start + semicolon;
2955                semicolon2 = uriCC.indexOf
2956                    (';', start + semicolon + match.length());
2957                uriBC.setEnd(start + semicolon);
2958                byte[] buf = uriBC.getBuffer();
2959                if (semicolon2 >= 0) {
2960                    for (int i = 0; i < end - start - semicolon2; i++) {
2961                        buf[start + semicolon + i]
2962                            = buf[start + i + semicolon2];
2963                    }
2964                    uriBC.setBytes(buf, start, semicolon
2965                                   + (end - start - semicolon2));
2966                }
2967            }
2968
2969        } else {
2970            setRequestedSessionId(null);
2971            setRequestedSessionURL(false);
2972        }
2973
2974    }
2975    // END CR 6309511
2976

2977
2978    // START SJSAS 6346226
2979
/**
2980     * Parses the value of the JROUTE cookie, if present.
2981     */

2982    void parseJrouteCookie() {
2983
2984        Cookies serverCookies = coyoteRequest.getCookies();
2985        int count = serverCookies.getCookieCount();
2986        if (count <= 0) {
2987            return;
2988        }
2989
2990        for (int i=0; i<count; i++) {
2991            ServerCookie scookie = serverCookies.getCookie(i);
2992            if (scookie.getName().equals(Constants.JROUTE_COOKIE)) {
2993                setJrouteId(scookie.getValue().toString());
2994                break;
2995            }
2996        }
2997    }
2998
2999    /**
3000     * Sets the jroute id of this request.
3001     *
3002     * @param jrouteId The jroute id
3003     */

3004    void setJrouteId(String JavaDoc jrouteId) {
3005        this.jrouteId = jrouteId;
3006    }
3007
3008    /**
3009     * Gets the jroute id of this request, which may have been
3010     * sent as a separate <code>JROUTE</code> cookie or appended to the
3011     * session identifier encoded in the URI (if cookies have been disabled).
3012     *
3013     * @return The jroute id of this request, or null if this request does not
3014     * carry any jroute id
3015     */

3016    public String JavaDoc getJrouteId() {
3017        return jrouteId;
3018    }
3019    // END SJSAS 6346226
3020

3021
3022    // START CR 6309511
3023
/**
3024     * Parse session id in URL.
3025     */

3026    protected void parseSessionCookiesId() {
3027
3028        // Parse session id from cookies
3029
Cookies serverCookies = coyoteRequest.getCookies();
3030        int count = serverCookies.getCookieCount();
3031        if (count <= 0)
3032            return;
3033
3034        for (int i = 0; i < count; i++) {
3035            ServerCookie scookie = serverCookies.getCookie(i);
3036            if (scookie.getName().equals(Globals.SESSION_COOKIE_NAME)) {
3037                // Override anything requested in the URL
3038
if (!isRequestedSessionIdFromCookie()) {
3039                    // Accept only the first session id cookie
3040
B2CConverter.convertASCII(scookie.getValue());
3041                    setRequestedSessionId
3042                        (scookie.getValue().toString());
3043                    setRequestedSessionCookie(true);
3044                    setRequestedSessionURL(false);
3045                    if (log.isDebugEnabled())
3046                        log.debug(" Requested cookie session id is " +
3047                            ((HttpServletRequest JavaDoc) getRequest())
3048                            .getRequestedSessionId());
3049                } else {
3050                    if (!isRequestedSessionIdValid()) {
3051                        // Replace the session id until one is valid
3052
B2CConverter.convertASCII(scookie.getValue());
3053                        setRequestedSessionId
3054                            (scookie.getValue().toString());
3055                    }
3056                }
3057            }
3058        }
3059
3060    }
3061    // END CR 6309511
3062

3063    // START CR 6309511
3064
/**
3065     * Character conversion of the URI.
3066     */

3067    protected void convertURI(MessageBytes uri)
3068        throws Exception JavaDoc {
3069
3070        ByteChunk bc = uri.getByteChunk();
3071        CharChunk cc = uri.getCharChunk();
3072        cc.allocate(bc.getLength(), -1);
3073
3074        String JavaDoc enc = connector.getURIEncoding();
3075        if (enc != null) {
3076            B2CConverter conv = getURIConverter();
3077            try {
3078                if (conv == null) {
3079                    conv = new B2CConverter(enc);
3080                    setURIConverter(conv);
3081                } else {
3082                    conv.recycle();
3083                }
3084            } catch (IOException JavaDoc e) {
3085                // Ignore
3086
log.error("Invalid URI encoding; using HTTP default");
3087                connector.setURIEncoding(null);
3088            }
3089            if (conv != null) {
3090                try {
3091                    conv.convert(bc, cc);
3092                    uri.setChars(cc.getBuffer(), cc.getStart(),
3093                                 cc.getLength());
3094                    return;
3095                } catch (IOException JavaDoc e) {
3096                    log.error("Invalid URI character encoding; trying ascii");
3097                    cc.recycle();
3098                }
3099            }
3100        }
3101
3102        // Default encoding: fast conversion
3103
byte[] bbuf = bc.getBuffer();
3104        char[] cbuf = cc.getBuffer();
3105        int start = bc.getStart();
3106        for (int i = 0; i < bc.getLength(); i++) {
3107            cbuf[i] = (char) (bbuf[i + start] & 0xff);
3108        }
3109        uri.setChars(cbuf, 0, bc.getLength());
3110
3111    }
3112    // END CR 6309511
3113

3114
3115    /**
3116     * Log a message on the Logger associated with our Container (if any).
3117     *
3118     * @param message Message to be logged
3119     */

3120    private void log(String JavaDoc message) {
3121
3122        Logger logger = connector.getContainer().getLogger();
3123        String JavaDoc localName = "CoyoteRequest";
3124        if (logger != null)
3125            logger.log(localName + " " + message);
3126        else
3127            System.out.println(localName + " " + message);
3128
3129    }
3130
3131
3132    /**
3133     * Log a message on the Logger associated with our Container (if any).
3134     *
3135     * @param message Message to be logged
3136     * @param throwable Associated exception
3137     */

3138    private void log(String JavaDoc message, Throwable JavaDoc throwable) {
3139
3140        Logger logger = connector.getContainer().getLogger();
3141        String JavaDoc localName = "CoyoteRequest";
3142        if (logger != null)
3143            logger.log(localName + " " + message, throwable);
3144        else {
3145            System.out.println(localName + " " + message);
3146            throwable.printStackTrace(System.out);
3147        }
3148
3149    }
3150
3151
3152    // START SJSAS 6419950
3153
private void populateSSLAttributes() {
3154        coyoteRequest.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE,
3155                             coyoteRequest);
3156        Object JavaDoc attr = coyoteRequest.getAttribute(Globals.CERTIFICATES_ATTR);
3157        if( attr != null) {
3158            attributes.put(Globals.CERTIFICATES_ATTR, attr);
3159        }
3160        attr = coyoteRequest.getAttribute(Globals.CIPHER_SUITE_ATTR);
3161        if(attr != null) {
3162            attributes.put(Globals.CIPHER_SUITE_ATTR, attr);
3163        }
3164        attr = coyoteRequest.getAttribute(Globals.KEY_SIZE_ATTR);
3165        if(attr != null) {
3166            attributes.put(Globals.KEY_SIZE_ATTR, attr);
3167        }
3168    }
3169    // END SJSAS 6419950
3170
}
3171
Popular Tags