Source Code Cross Referenced for HTTPData.java in  » Portal » Open-Portal » com » sun » portal » rproxy » rewriter » util » http » 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.rewriter.util.http 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.rproxy.rewriter.util.http;
006:
007:        import com.sun.portal.rewriter.util.Constants;
008:        import com.sun.portal.log.common.PortalLogger;
009:        import com.sun.portal.rewriter.util.uri.PageSpec;
010:        import com.sun.portal.rproxy.connectionhandler.HTTPResponse;
011:        import com.sun.portal.rproxy.connectionhandler.Response;
012:        import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
013:        import com.sun.portal.rproxy.monitoring.util.RProxyEvent;
014:
015:        import java.io.BufferedInputStream;
016:        import java.io.ByteArrayOutputStream;
017:        import java.io.IOException;
018:
019:        public class HTTPData {
020:            private static final String CONTENT_LENGTH_PATTERN = "Content-length";
021:
022:            private final Response response;
023:            private final PageSpec pageSpec;
024:            private final ContentInfo contentInfo;
025:
026:            private byte[] contentBytes;
027:            private String rawEncodedString;
028:            private String rawEncodedStringLowerCase;
029:
030:            private String pageContent;
031:
032:            public HTTPData(PageSpec aPageSpec, Response aResponse)
033:                    throws IOException {
034:                response = aResponse;
035:                pageSpec = aPageSpec;
036:                contentInfo = new ContentInfo();
037:                MIMEAndEncodingParser.parse(this );
038:            }//constructor
039:
040:            public String getContentType() {
041:                return response.getContentType();
042:            }//getContentType()
043:
044:            public ContentInfo getContentInfo() {
045:                return contentInfo;
046:            }//getConentInfo()
047:
048:            public boolean isStreamRead() {
049:                return (contentBytes != null) ? true : false;
050:            }//isStreamRead()
051:
052:            public byte[] getContentBytes() throws IOException {
053:                if (contentBytes == null) {
054:                    contentBytes = readFullContent(response);
055:                    MonitoringSubsystem.handleEvent(RProxyEvent.RESP_READ,
056:                            new Long(contentBytes.length));
057:                }
058:
059:                return contentBytes;
060:            }//getContentBytes()
061:
062:            public String getRawEncodedString() throws IOException {
063:                if (rawEncodedString == null && (getContentBytes() != null)) {
064:                    rawEncodedString = new String(getContentBytes());
065:                }
066:                return rawEncodedString;
067:            }//getRawEncodedString()
068:
069:            public String getRawEncodedStringLowerCase() throws IOException {
070:                if (rawEncodedStringLowerCase == null) {
071:                    rawEncodedStringLowerCase = getRawEncodedString()
072:                            .toLowerCase();
073:                }
074:
075:                return rawEncodedStringLowerCase;
076:            }//getRawEncodedStringLowerCase()
077:
078:            public PageSpec getPageSpec() {
079:                return pageSpec;
080:            }//getPageSpec()
081:
082:            //Note: Make sure this method is called only once that too after write encoding
083:            //as this var is intialized only once..
084:            public String getPageContent() throws IOException {
085:                String lEncoding = contentInfo.getEncoding();
086:
087:                if (lEncoding == null || lEncoding == Constants.SYSTEM_ENCODING) {
088:                    contentInfo.setEncoding(Constants.SYSTEM_ENCODING);
089:                    return getRawEncodedString();
090:                }
091:
092:                if (pageContent == null && getContentBytes() != null) {
093:                    pageContent = new String(getContentBytes(), contentInfo
094:                            .getEncoding());
095:                }
096:
097:                return pageContent;
098:            }//getPageContent()
099:
100:            private static byte[] readFullContent(Response resp)
101:                    throws IOException {
102:                String lContentLength = resp
103:                        .getResponseHeader(CONTENT_LENGTH_PATTERN);
104:                BufferedInputStream buffIn = resp.getContentStream();
105:                if (resp instanceof  HTTPResponse) {
106:                    HTTPResponse lHTTPResponse = (HTTPResponse) resp;
107:                    String te = lHTTPResponse
108:                            .getResponseHeader("Transfer-Encoding");
109:                    if (te != null) {
110:                        int idx = te.indexOf(':');
111:                        if (te.substring(idx + 1).trim().equalsIgnoreCase(
112:                                "chunked")) {
113:                            byte[] contentBuf = ChunkedContent
114:                                    .readChunkedContent(buffIn);
115:                            lHTTPResponse.removeHeader("Transfer-Encoding");//  Remove "chunked" from Transfer-Encoding
116:                            return contentBuf;
117:                        }
118:                    }
119:                }
120:
121:                if (buffIn == null) {
122:                    return null;
123:                }
124:
125:                if (lContentLength != null) {
126:                    int length = Integer.parseInt(lContentLength.substring(
127:                            lContentLength.indexOf(':') + 1).trim());
128:
129:                    byte[] byteContent = new byte[length];
130:                    int read = 0, totalRead = 0;
131:                    while (totalRead < length) {
132:                        read = buffIn.read(byteContent, totalRead, length
133:                                - totalRead);
134:                        if (read == -1) {
135:                            //BugNo:4880860
136:                            //if ( totalRead < length )
137:                            //{
138:                            //continue;
139:                            //}
140:
141:                            break;
142:                        } else {
143:                            totalRead += read;
144:                        }
145:                    }
146:
147:                    return byteContent;
148:                } else {
149:                    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
150:                    byte content[] = new byte[2048];
151:                    int numbytes;
152:
153:                    while (true) {
154:                        numbytes = buffIn.read(content);
155:                        if (numbytes == -1) {
156:                            break;
157:                        }
158:
159:                        bOut.write(content, 0, numbytes);
160:                    }//while loop
161:
162:                    return bOut.toByteArray();
163:                }//if/else
164:            }//readFullContent()
165:
166:        }//class HTTPData
w_w___w___.__j_a__v_a_2__s.__co_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.