Source Code Cross Referenced for ConnectionHandler.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 com.sun.portal.netlet.client.jnlp.ClientManager;
004:        import com.sun.portal.log.common.PortalLogger;
005:
006:        import java.net.*;
007:        import java.io.*;
008:
009:        /*
010:         * ConnectionHandler
011:         * - Handles HTTP by forwarding requests to gateway
012:         * - Proxy chains with client proxy if one exists
013:         * - Provides a secure channel for HTTP requests.
014:         * - Tunnels SSL requests to end-server through gateway.
015:         *
016:         * For every client connection received, a new transferhandler thread gets created. This thread takes care
017:         * of processing the incoming request based on the HTTP scheme, and sends the response back to the client.
018:         */
019:
020:        public class ConnectionHandler {
021:            private ClientListener parent = null;
022:            private Socket connection = null;
023:
024:            public ConnectionHandler(Socket clntSocket, ClientListener parent) {
025:                this .connection = clntSocket;
026:                this .parent = parent;
027:
028:                handleConnection();
029:            }
030:
031:            /**
032:             * This function hands over the request to the appropriate handler based on the scheme
033:             */
034:            private void handleConnection() {
035:                try {
036:                    //
037:                    // Determine the type of request
038:                    //
039:                    HTTPRequestStream clientIn = new HTTPRequestStream(
040:                            connection.getInputStream());
041:                    OutputStream clientOut = connection.getOutputStream();
042:                    HTTPFields reqFields = new HTTPFields();
043:                    reqFields.read(clientIn);
044:
045:                    //
046:                    // Handle special cases here
047:                    // Determine if request is for PAC file 
048:                    //
049:                    String firstLine = reqFields.getFirstLine();
050:                    System.out.println("ConnectionHandler firstLine "
051:                            + firstLine);
052:                    int index = firstLine.lastIndexOf(" ");
053:                    reqFields.setHttpVersion(firstLine.substring(index,
054:                            firstLine.length()).trim());
055:                    if (firstLine.indexOf("/startNetlet") != -1) {
056:                        handleNetletRequest(reqFields, clientOut);
057:                        clientIn.close();
058:                        clientOut.close();
059:                        return;
060:                    } else if (firstLine.indexOf("/startProxylet") != -1) {
061:                        //TODO : BY PROXYLET
062:                        handleProxyletRequest(reqFields, clientOut);
063:                        clientIn.close();
064:                        clientOut.close();
065:                        return;
066:                    }
067:                    //
068:                    // Close the applet window, if user has opted to Logout
069:                    //
070:                    else if (firstLine.indexOf("/UI/Logout") != -1) {
071:                        /*
072:                        Log.message("Logout Message. Close the applet ");
073:
074:                        JSObject win = ((ProxyletApplet)grandParent).getWindow();
075:                        win.call("resetProxysetting", null);
076:
077:                        Thread.sleep(2000);
078:                        sendRedirectResponse(reqFields, clientOut);
079:                        clientIn.close();
080:                        clientOut.close();
081:
082:                        parent.close();
083:                        grandParent.stop();
084:                        win.call("closeAppletWindow", null);
085:                        grandParent.destroy();
086:                        if (GlobalConfigMgr.getBrowserType().equals(BrowserType.IE) &&
087:                           (!System.getProperty("java.version").startsWith("1.3"))) {
088:                           PluginProxyManager.reset();
089:                        }
090:                         */
091:
092:                        return;
093:                    }
094:
095:                    //
096:                    //  Parse the incoming request
097:                    //
098:                    //reqFields.parseRequest();
099:                    //
100:                    // Hand over the request to appropriate handler
101:                    //
102:                    //ProtocolHandlerI handler = ConnectionFactory.getHandler(reqFields.getScheme(), reqFields.getHttpVersion());
103:                    //handler.handleRequest(reqFields, clientIn, clientOut);
104:
105:                } catch (MalformedURLException me) {
106:                    //Log.error( "Malformed Exception ME001" + me.getMessage());
107:                } catch (IOException e) {
108:                    e.printStackTrace();
109:                } catch (Exception ignore) {
110:                } finally {
111:                    try {
112:                        connection.close();
113:                    } catch (Exception e) {
114:                    }
115:
116:                }
117:            } // run method
118:
119:            private void handleNetletRequest(HTTPFields reqFields,
120:                    OutputStream clientOut) throws IOException {
121:                ClientManager.getNetletHandler().startClient();
122:                sendRedirectResponse(reqFields, clientOut);
123:            }
124:
125:            private void handleProxyletRequest(HTTPFields reqFields,
126:                    OutputStream clientOut) throws IOException {
127:                byte[] header = getHeader(0, reqFields.getHttpVersion());
128:                clientOut.write(header);
129:                clientOut.flush();
130:            }
131:
132:            private byte[] getHeader(int contentLength, String httpVersion) {
133:                String dummyHeader = httpVersion + Constants.SP + 200
134:                        + Constants.SP + "OK" + "\n"
135:                        + "Content-Type: text/html" + "\n"
136:                        + "Connection: close" + "\n" + "Content-Length: "
137:                        + contentLength + "\n\r\n\r";
138:                return dummyHeader.getBytes();
139:            }
140:
141:            private void sendRedirectResponse(HTTPFields reqFields,
142:                    OutputStream clientOut) throws IOException {
143:                String redirectURL = reqFields.getRedirectURL();
144:                redirectURL = URLDecoder.decode(redirectURL);
145:                System.out.println("redirectURL " + redirectURL);
146:
147:                String gwURL = ClientManager.getParam("gwURL");
148:                System.out.println("GWURL " + gwURL);
149:
150:                if (redirectURL.startsWith("/")) {
151:                    String codebaseURL = ClientManager.getCodeBaseUrl();
152:                    if (codebaseURL != null && codebaseURL.length() > 0) {
153:                        int hostIndex = codebaseURL.indexOf("/");
154:                        int portIndex = codebaseURL.indexOf("/", hostIndex + 2);
155:                        redirectURL = gwURL
156:                                + codebaseURL.substring(0, portIndex)
157:                                + redirectURL;
158:                    }
159:                }
160:                System.out
161:                        .println("ConnectionHandler.sendRedirectResponse redirectURL "
162:                                + redirectURL);
163:                String content = "File Moved temporarily";
164:                String respHeader_302 = reqFields.getHttpVersion()
165:                        + Constants.SP + 302 + Constants.SP
166:                        + "Moved Temporarily" + "\n"
167:                        + "Content-Type: text/html; charset=UTF-8" + "\n"
168:                        + "Location: " + redirectURL + "\n"
169:                        + "Connection: close" + "\n" + "Content-Length: "
170:                        + content.length() + "\n\r\n\r";
171:                clientOut.write(respHeader_302.getBytes());
172:                clientOut.write(content.getBytes());
173:                clientOut.flush();
174:            }
175:        }
w__w___w__.__j_a_v__a2s___.___com___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.