Source Code Cross Referenced for HTTP_1_0_Handler.java in  » Portal » Open-Portal » com » sun » portal » netlet » client » jnlp » connect » 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.netlet.client.jnlp.connect 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.netlet.client.jnlp.connect;
002:
003:        import java.io.*;
004:        import com.sun.portal.log.common.PortalLogger;
005:        import java.util.Vector;
006:        import java.net.Socket;
007:
008:        public class HTTP_1_0_Handler implements  ProtocolHandlerI {
009:            public void handleRequest(HTTPFields reqFields,
010:                    HTTPRequestStream clientIn, OutputStream clientOut)
011:                    throws IOException {
012:                HTTPRequestStream gatewayIn = null;
013:                HTTPResponseStream gatewayOut = null;
014:                Socket tunnelSocket = null;
015:
016:                try {
017:                    //
018:                    // Set the header line
019:                    //
020:                    setFirstLine(reqFields);
021:
022:                    //reqFields.appendField("Cookie",
023:                    //                     GlobalConfigMgr.getCookie().getName() + "=" +
024:                    //                    GlobalConfigMgr.getCookie().getValue() );
025:
026:                    //
027:                    // Remove Proxy specific headers
028:                    //
029:                    reqFields.removeField("Proxy-Connection");
030:                    reqFields.removeField("Connection");
031:                    //
032:                    // Read rest of the content
033:                    //
034:                    int contentLength = reqFields.getIntField("Content-Length");
035:                    byte requestData[] = new byte[contentLength];
036:                    int i;
037:                    for (int read = 0; read < contentLength; read += i) {
038:                        i = clientIn.read(requestData, read, contentLength
039:                                - read);
040:                        if (i == -1)
041:                            break;
042:                    }
043:                    //
044:                    // Add custom header to indicate that request is getting routed 
045:                    // through proxylet
046:                    //
047:                    reqFields.addField("PS-Proxylet", "RT-Proxylet=true");
048:
049:                    //
050:                    // Write header and data to end server
051:                    //
052:                    reqFields.write(gatewayOut);
053:                    gatewayOut.write(requestData, 0, requestData.length);
054:                    gatewayOut.flush();
055:                    //
056:                    // Read response header from end server
057:                    //
058:                    HTTPFields responseFields = new HTTPFields();
059:                    responseFields.read(gatewayIn);
060:
061:                    //
062:                    // Parse Set-Cookie header for iPlanetDirectoryPro
063:                    //
064:                    Vector setCookieHeaderList = responseFields
065:                            .getFieldValues("Set-cookie");
066:                    if (setCookieHeaderList != null
067:                            && !setCookieHeaderList.isEmpty()) {
068:                        Cookie iplanetPro = Cookie.getCookieByName(
069:                                "iPlanetDirectoryPro", setCookieHeaderList);
070:                        //if( iplanetPro != null )
071:                        //GlobalConfigMgr.setCookie(iplanetPro);
072:                    }
073:
074:                    //
075:                    // Read response body from server
076:                    //
077:                    byte buf[] = new byte[8192];
078:                    int read = 0;
079:                    ByteArrayOutputStream respbody = new ByteArrayOutputStream();
080:                    while ((read = gatewayIn.read(buf, 0, 8192)) != -1) {
081:                        respbody.write(buf, 0, read);
082:                    }
083:                    //
084:                    //Write response back to browser client
085:                    //
086:                    ByteArrayOutputStream bytearrayheader = new ByteArrayOutputStream();
087:                    responseFields
088:                            .write(new HTTPResponseStream(bytearrayheader));
089:                    try {
090:                        clientOut.write(bytearrayheader.toByteArray(), 0,
091:                                bytearrayheader.size());
092:                        clientOut.write(respbody.toByteArray(), 0, respbody
093:                                .size());
094:                        clientOut.flush();
095:                    } catch (Exception e) {
096:                        //Log.message(reqFields.toString());
097:                        //Log.message(e.getMessage());
098:                        throw new IOException(e.getMessage());
099:                    }
100:
101:                } catch (IOException ie) {
102:                    throw ie;
103:                } finally {
104:                    try {
105:                        clientIn.close();
106:                        clientOut.close();
107:                        gatewayIn.close();
108:                        gatewayOut.close();
109:                        if (tunnelSocket != null)
110:                            tunnelSocket.close();
111:                    } catch (Exception e) {
112:                    }
113:
114:                }
115:
116:            }
117:
118:            private void setFirstLine(HTTPFields reqFields) {
119:                //String gwURL = "http://" + GlobalConfigMgr.getGatewayHost() + ":" + GlobalConfigMgr.getGatewayPort() ;
120:                String url = "http://"
121:                        + reqFields.getHost()
122:                        + ":"
123:                        + (reqFields.getPort() == -1 ? 80 : reqFields.getPort());
124:
125:                /**
126:                 * If gateway is running in non-secure mode and the client has proxy then you need to append the
127:                 * gateway URL. In other cases you would just be tunneling the data through.
128:                 * Don't have to append the gateway URL in that case.
129:                 */
130:                /*
131:                if (GlobalConfigMgr.getUseClientProxy() && !GlobalConfigMgr.getGatewayMode().equalsIgnoreCase("secure")) {
132:                    reqFields.setFirstLine(reqFields.getScheme() +
133:                                           " " +
134:                                           gwURL +
135:                                           "/" +
136:                                           url +
137:                                           reqFields.getFile() +
138:                                           " "  +
139:                                           reqFields.getHttpVersion());
140:                 } else {
141:                 */
142:                reqFields.setFirstLine(reqFields.getScheme() + " " + "/" + url
143:                        + reqFields.getFile() + " "
144:                        + reqFields.getHttpVersion());
145:                //}
146:            }
147:
148:            /*
149:            private Socket createTunnelSocket()
150:                    throws IOException
151:            {
152:                Socket tunnel = null ;
153:
154:                try{
155:                    tunnel = new Socket(GlobalConfigMgr.getClientProxyHost(), GlobalConfigMgr.getClientProxyPort());
156:                }catch(Exception e){
157:                    throw new IOException("Could not establish a connection with proxy");
158:                }
159:
160:                OutputStream out = tunnel.getOutputStream();
161:                String msg = "CONNECT " + GlobalConfigMgr.getGatewayHost() + ":" + GlobalConfigMgr.getGatewayPort() + " HTTP/1.0\n"
162:                        + "User-Agent: "
163:                        + sun.net.www.protocol.http.HttpURLConnection.userAgent
164:                        + "\r\n\r\n";
165:
166:
167:                byte b[];
168:                try {
169:                    /*
170:             * We really do want ASCII7 -- the http protocol doesn't change
171:             * with locale.
172:             */
173:            /*
174:                    b = msg.getBytes("ASCII7");
175:                } catch (UnsupportedEncodingException ignored) {
176:                    /*
177:             * If ASCII7 isn't there, something serious is wrong, but
178:             * Paranoia Is Good (tm)
179:             */
180:            /*
181:                    b = msg.getBytes();
182:                }
183:                out.write(b);
184:                out.flush();
185:
186:                byte		reply[] = new byte[200];
187:                int		    replyLen = 0;
188:                int		    newlinesSeen = 0;
189:                boolean		headerDone = false;	/* Done on first newline */
190:            /*
191:                boolean		error = false;
192:                InputStream	in = tunnel.getInputStream();
193:                while (newlinesSeen < 2) {
194:                    int i = in.read();
195:                    if (i < 0) {
196:                        throw new IOException("Unexpected EOF from proxy");
197:                    }
198:                    if (i == '\n') {
199:                        headerDone = true;
200:                        ++newlinesSeen;
201:                    } else if (i != '\r') {
202:                        newlinesSeen = 0;
203:                        if (!headerDone && replyLen < reply.length) {
204:                            reply[replyLen++] = (byte) i;
205:                        }
206:                    }
207:                }
208:
209:                /*
210:             * Converting the byte array to a string is slightly wasteful
211:             * in the case where the connection was successful, but it's
212:             * insignificant compared to the network overhead.
213:             */
214:            /*
215:                String replyStr;
216:                try {
217:                    replyStr = new String(reply, 0, replyLen, "ASCII7");
218:                } catch (UnsupportedEncodingException ignored) {
219:                    replyStr = new String(reply, 0, replyLen);
220:                }
221:
222:                /* Look for 200 connection established */
223:            /*
224:                if(replyStr.toLowerCase().indexOf("200 connection established") == -1){
225:                    throw new IOException("Unable to tunnel through "
226:                            + GlobalConfigMgr.getClientProxyHost()+ ":" + GlobalConfigMgr.getClientProxyPort()
227:                            + ".  Proxy returns \"" + replyStr + "\"");
228:                }
229:
230:                return tunnel;
231:
232:            }
233:
234:             */
235:
236:        }
ww___w__.__ja_v___a___2s.__c__om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.