Source Code Cross Referenced for HTTPSession.java in  » Portal » Open-Portal » com » sun » portal » rproxy » connectionhandler » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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


001:        /*
002:         * $Id: HTTPSession.java,v 1.8 2005/11/30 11:27:21 ss150821 Exp $
003:         * $Source: /m/portal/ps/srap/src/com/sun/portal/rproxy/connectionhandler/HTTPSession.java,v $
004:         * $Log: HTTPSession.java,v $
005:         * Revision 1.8  2005/11/30 11:27:21  ss150821
006:         * 6356996 - Srap Code base needs to save files in the unix file format and not windows
007:         *
008:         * Revision 1.7  2005/02/25 09:44:13  ss150821
009:         * RFE 6223490 - SRA Should use JDK based logging, changed to start throwing the full stacktrace for the  exception in the logs
010:         *
011:         * Revision 1.6  2005/02/24 07:36:44  ss150821
012:         * RFE 6223490 - SRA Should use JDK based logging
013:         *
014:         * Revision 1.5  2005/02/23 09:15:07  ss150821
015:         * RFE 6223490 - SRA Should use JDK based logging
016:         *
017:         * Revision 1.4  2004/07/27 12:55:01  vt126379
018:         * RFE#5075809, CRT#99
019:         *
020:         * Revision 1.3  2002/08/16 15:13:06  bv131302
021:         * Hana CRT#1888 - Check log settings before logging
022:         *
023:         * Revision 1.2  2002/07/01 10:52:44  ss133690
024:         * CRT 1211 Support for case insensitive certficate enabled list
025:         *
026:         * Revision 1.1  2002/06/14 09:53:53  rt130506
027:         * SRAP rebranding
028:         *
029:         * Revision 1.8  2002/06/11 16:02:03  bv131302
030:         * new branded
031:         *
032:         * Revision 1.7  2002/05/27 07:25:22  ss133690
033:         * CRT 1211 SRAP PDC support & Bug 4670649
034:         *
035:         * Revision 1.6  2002/05/13 06:22:24  mm132998
036:         * Perf related modifications
037:         *
038:         * Revision 1.5  2002/03/21 14:48:58  mm132998
039:         * Bug ID : # 4655970 Hana CRT : # 615 Desc : Lihue PRD 7.4.1.1 - RProxy seperation
040:         *
041:         * Revision 1.4  2002/03/20 04:35:24  mm132998
042:         * Bug ID # 4655269 CRT : # 602 Desc : Support for HTTP persistent connection at gateway
043:         *
044:         * Revision 1.3  2002/03/18 10:19:27  mm132998
045:         * Bug ID : # 4653988 CRT : # 574 Desc : Lihue PRD 7.4.4.1 and requirements for Bug 4195483
046:         *
047:         * Revision 1.2  2002/03/04 09:21:44  mm132998
048:         * Bug ID : 4646277 CRT: 442 Desc : Lihue PRD 4.5
049:         *
050:         *
051:         */
052:        /*
053:         * HTTPSession.java
054:         *
055:         * $Author: ss150821 $
056:         *
057:         * $Date: 2005/11/30 11:27:21 $ $Revision: 1.8 $
058:         *
059:         * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
060:         *
061:         * Developed by SunPS and SunIR
062:         */
063:
064:        package com.sun.portal.rproxy.connectionhandler;
065:
066:        import java.io.BufferedInputStream;
067:        import java.io.EOFException;
068:        import java.io.IOException;
069:        import java.io.InterruptedIOException;
070:        import java.net.Socket;
071:        import java.util.logging.Level;
072:        import java.util.logging.Logger;
073:
074:        import com.sun.portal.log.common.PortalLogger;
075:        import com.sun.portal.util.ServiceIdentifier;
076:
077:        /**
078:         * This class processes the next request and sends a response back to the
079:         * client.
080:         * 
081:         * @author Gabriel Lawrence
082:         */
083:        // JP_Declaration Session 203
084:        public class HTTPSession extends Session {
085:            private static final int MAXREQHEADSIZE = 2048;
086:
087:            // private static Logger logger =
088:            // Logger.getLogger("com.sun.portal.sra.rproxy");
089:            private static Logger logger = PortalLogger
090:                    .getLogger(HTTPSession.class);
091:
092:            // Lihue KeepAlive
093:            // Earlier we were creating a new BufferedInputStream each time we
094:            // entered getRequest() - may cause problems if data gets buffered by the
095:            // stream and we lose that stream. So making it part of class and not
096:            // method.
097:            // - Mridul
098:            private BufferedInputStream in = null;
099:
100:            // End of Code : Lihue KeepAlive
101:
102:            // Lihue PRD : # 7.4.4.1
103:            // public HTTPSession (Socket s, Integer logId) {
104:            public HTTPSession(Socket s) {
105:                // super(s, logId);
106:                super (s);
107:                // EOC :: Lihue PRD : # 7.4.4.1
108:                // Lihue KeepAlive
109:                try {
110:                    in = new BufferedInputStream(_theSocket.getInputStream());
111:                } catch (IOException ex) {
112:                    // logger.log(Level.SEVERE, "Unable to get socket's Inputstream !",
113:                    // ex);
114:                    logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCONHNDLR097", ex);
115:                }
116:                // End of Code : Lihue KeepAlive
117:            }
118:
119:            // Lihue PRD : # 7.4.4.1
120:            // public HTTPSession (Socket s, Integer logId, String str) {
121:            public HTTPSession(Socket s, String str) {
122:                // super(s, logId, str);
123:                super (s, str);
124:                // EOC :: Lihue PRD : # 7.4.4.1
125:                // Lihue KeepAlive
126:                try {
127:                    in = new BufferedInputStream(_theSocket.getInputStream());
128:                } catch (IOException ex) {
129:                }
130:                // End of Code : Lihue KeepAlive
131:            }
132:
133:            // Lihue PRD : 4.5
134:            // Lihue PRD : # 7.4.4.1
135:            // public HTTPSession (Socket s, Integer logId, String str , String protocol
136:            // , int port) {
137:            public HTTPSession(Socket s, String str, String protocol, int port) {
138:                // this(s, logId, str);
139:                this (s, str);
140:                // EOC :: Lihue PRD : # 7.4.4.1
141:                this ._gwprotocol = protocol;
142:                /**
143:                 * Changes to accomodate DSAME pdc support. Bug : 4670649
144:                 */
145:                // certificate enabled list should not be case sensitive
146:                /*
147:                 * this.doingPDC = srapGateway_certificateEnabledList.contains(rphost) &&
148:                 * ServiceIdentifier.isGateway() && _gwprotocol.equals("https");
149:                 */
150:                this .doingPDC = srapGateway_certificateEnabledList_lc
151:                        .contains(rphost.toLowerCase())
152:                        && ServiceIdentifier.isGateway()
153:                        && _gwprotocol.equals("https");
154:                // End of code change for bug : 4670649
155:                this .port = port;
156:                this ._gwport = Integer.toString(port);
157:            }
158:
159:            // EOC :: Lihue PRD : 4.5
160:
161:            /**
162:             * Get a request object
163:             */
164:            public Request getRequest() {
165:                // Lihue KeepAlive
166:                // see comment at new declaration of in
167:                // BufferedInputStream in=null;
168:                // End of Code : Lihue KeepAlive
169:                HTTPRequest req = null;
170:
171:                try {
172:                    // Lihue KeepAlive
173:                    // in=new BufferedInputStream(_theSocket.getInputStream());
174:                    // End of Code : Lihue KeepAlive
175:                    in.mark(MAXREQHEADSIZE);
176:                    boolean keepGoing = true;
177:                    StringBuffer sb = new StringBuffer();
178:                    int b;
179:                    // Lihue PRD : 4.5
180:                    // req = new HTTPRequest();
181:                    req = new HTTPRequest(_gwprotocol, port);
182:                    // EOC :: Lihue PRD : 4.5
183:
184:                    // Read until we see the end of the Request line, or we hit an
185:                    // exception
186:                    int totalRead = 0;
187:                    while (keepGoing) {
188:                        b = in.read();
189:                        if (b == -1) {
190:                            keepGoing = false;
191:                            throw new EOFException();
192:                        }
193:                        totalRead++;
194:                        sb.append((char) b);
195:
196:                        // After reading each line, check to see if header is complete,
197:                        // loop...
198:                        if (sb.length() > 1 && sb.charAt(sb.length() - 2) == 13
199:                                && sb.charAt(sb.length() - 1) == 10) {
200:                            // if (!sb.toString().startsWith("Referer")) {
201:                            req.addHeaderLine(sb.toString());
202:                            // }
203:                            keepGoing = !req.isHeaderComplete();
204:                            sb.setLength(0);
205:                        }
206:                    }
207:
208:                    // Lihue PRD : # 7.4.4.1
209:                    /*
210:                     * if (GWLogManager.loggingEnabled) { Object tmp =
211:                     * GWLogManager.logIdMap.remove(new Integer(_theSocket.getPort()));
212:                     * if (tmp != null) _logId = (Integer)tmp; }
213:                     */
214:                    // EOC :: Lihue PRD : # 7.4.4.1
215:                    _numBytesRead += totalRead;
216:                    req.addSize(totalRead);
217:
218:                    // Set the content stream, so if it has content we can read more...
219:                    req.setContentStream(in);
220:                    // Manage keep-alive of session...
221:                    // Lihue KeepAlive
222:                    // Handle the logic of lines below better
223:                    // if (req.getHTTPVersion().compareTo("HTTP/1.1") < 0 &&
224:                    // req.getRequestHeader("Connection: Keep-Alive")==null) {
225:                    // _moreElements=false;
226:                    // }
227:
228:                    boolean keepAlivePresent = false;
229:                    if (processKeepAliveConnections) {
230:                        String keepAliveHeader = req
231:                                .getRequestHeader("Connection");
232:                        if (keepAliveHeader != null) {
233:                            keepAliveHeader = keepAliveHeader.substring(
234:                                    keepAliveHeader.indexOf(':') + 1).trim()
235:                                    .toLowerCase();
236:                            if (!keepAliveHeader.equals("close")) {
237:                                keepAlivePresent = true;
238:                            }
239:                        } else if (this _req > 0) {
240:                            // Reused socket !!
241:                            // Sometimes if the browser sends request on a socket
242:                            // that it is reusing , it skips the header
243:                            // Not strictly according to RFC , but the browser assumes
244:                            // that
245:                            // since the server knows this is socket reuse , it will
246:                            // assume
247:                            // KeepAlive for this connection.
248:                            // - Mridul
249:                            keepAlivePresent = true;
250:                        }
251:                    }
252:
253:                    if (!processKeepAliveConnections
254:                            || (!keepAlivePresent && req.getHTTPVersion()
255:                                    .toUpperCase().compareTo("HTTP/1.1") < 0)) {
256:                        _moreElements = false;
257:                    }
258:                    // End of Code : Lihue KeepAlive
259:                } catch (EOFException ex) {
260:                    // Socket closed before we read everything we wanted
261:                    // Lihue KeepAlive
262:                    // _moreElements=false;
263:                    // In KeepAlive , this happens a bit too much 'cos waiting for
264:                    // client to
265:                    // reuse socket and so we dont want to fill the logs with this
266:                    // exception
267:                    // Actually this is seems to be the proper behaviour - Mridul
268:                    if (!this reqKeepAlive) {
269:                        _moreElements = false;
270:                        logger.warning("HTTPSession[" + _theSocket
271:                                + "]: EOF when reading request");
272:                    } else {
273:                        try {
274:                            // dunno whether this is actually required ??
275:                            // - Mridul
276:                            _theSocket.setSoTimeout(readTimeout);
277:                            in = new BufferedInputStream(_theSocket
278:                                    .getInputStream());
279:                        } catch (IOException ioex) {
280:                            // logger.log(Level.SEVERE, "EOFException in HTTPSession
281:                            // while reading request header", ioex);
282:                            logger.log(Level.SEVERE,
283:                                    "PSSRRPROXY_CSPRCONHNDLR098", ioex);
284:                            // ioex.printStackTrace();
285:                            // DEbu
286:                        }
287:                    }
288:                    // End of Code : Lihue KeepAlive
289:                    req = null;
290:                } catch (InterruptedIOException ex) {
291:                    // Socket timed out
292:                    _moreElements = false;
293:                    logger.warning("HTTPSession[" + _theSocket
294:                            + "]: Interrupted when reading request");
295:                    req = null;
296:                } catch (IOException ex1) {
297:                    try {
298:                        in.reset();
299:                        logger.warning("HTTPSession[" + _theSocket
300:                                + "]: IOException when reading request");
301:                        req = null;
302:                    } catch (Exception ex) {
303:                    }
304:                } catch (Throwable t) {
305:                    // logger.log(Level.SEVERE, "Error in HTTPSession::getRequest(): ",
306:                    // t);
307:                    Object[] params = { t };
308:                    logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCONHNDLR099",
309:                            params);
310:                    // t.printStackTrace();
311:                }
312:
313:                return req;
314:            }
315:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.