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


001:        package com.sun.portal.proxylet.client.applet;
002:
003:        import com.sun.portal.proxylet.client.common.server.Server;
004:        import com.sun.portal.proxylet.client.applet.PluginProxyInfo;
005:        import com.sun.portal.proxylet.client.common.Param;
006:        import com.sun.portal.proxylet.client.common.server.ssl.SSLProviderFactory;
007:        import com.sun.portal.proxylet.client.common.server.ssl.AbstractSSLProvider;
008:        import com.sun.portal.proxylet.client.common.Param;
009:        import com.sun.portal.proxylet.client.common.Log;
010:        import netscape.javascript.JSObject;
011:
012:        import java.applet.Applet;
013:        import java.awt.Color;
014:        import java.awt.Graphics;
015:        import java.net.InetAddress;
016:        import java.net.ServerSocket;
017:        import java.util.Enumeration;
018:        import java.io.IOException;
019:
020:        import javax.swing.JApplet;
021:        import javax.swing.JLabel;
022:
023:        /**
024:         * DownloadMgr
025:         *
026:         * This applet runs on a fixed port and downloads the actual proxylet applet
027:         * and the signed script.
028:         *
029:         * This was done as a workaround to a bug in Mozilla. 
030:         *
031:         * For more information on signed script, please refer 
032:         * http://www.mozilla.org/projects/security/components/signed-scripts.html 
033:         *
034:         * According to Mozilla security policy,  only a signed script has expanded privilges
035:         * like modifying browser proxy settings etc. Mozilla recognizes the signed script
036:         * if its placed inside a JAR and referred using a JAR URL 
037:         * ( for example, JAR:http://somesite/myjar.jar!/signed.html ). For some reason,
038:         * mozilla is not able to resolve https URL ( for example, JAR:https  does not work ).
039:         *
040:         * Since we cannot expect the gateway to run in a non-secure mode, we have a
041:         * small applet 'DownloadMgr' that gets downloaded and starts listening on particular port
042:         * ( non-secure mode ).
043:         * Now, the signed script and the applet gets downloaded through this applet.
044:         * The JAR URL in this case looks like JAR:http://localhost:port/portalserver/signedjar!/signed.html
045:         */
046:
047:        public class DownloadMgr extends JApplet {
048:            private static DownloadMgr applet;
049:            Server p;
050:
051:            public void init() {
052:                getContentPane().setBackground(Color.white);
053:                String temp = this .getParameter("DEBUGLEVEL");
054:                Log
055:                        .setloglevel_JavaConsole((temp != null && temp
056:                                .equals("1")) ? true : false);
057:
058:                synchronized (getClass()) {
059:                    if (applet == null)
060:                        applet = this ;
061:                }
062:
063:            }
064:
065:            public void start() {
066:
067:                try {
068:
069:                    String version = System.getProperty("java.version");
070:                    if (version.charAt(2) < '3'
071:                            || (version.charAt(2) <= '3' && (version.length() == 3 || version
072:                                    .charAt(4) < '1'))) {
073:                        call("loadJVM", 0);
074:                        return;
075:                    }
076:
077:                    Param.readParameters(this );
078:                    Param.setBindPort(Param.getDownloadMgrPort());
079:                    Param
080:                            .setBindIP(InetAddress.getLocalHost()
081:                                    .getHostAddress());
082:
083:                    Param.setSource("DownloadMgr");
084:
085:                    boolean openDownloadMgr = true;
086:
087:                    // If it's not direct connection then popup a dialog box for proxy setting values
088:                    if (!isDirectConnection()) {
089:                        PluginProxyInfo ppi = new PluginProxyInfo();
090:                        openDownloadMgr = ppi.isActionOk();
091:                        if (!openDownloadMgr) {
092:                            this 
093:                                    .getContentPane()
094:                                    .add(
095:                                            new JLabel(
096:                                                    Param
097:                                                            .getString(
098:                                                                    "pinfo.26",
099:                                                                    "Please enter valid proxy host and port values")));
100:                        }
101:                    }
102:
103:                    // If user clicks on Cancel button of proxy settings then don't create
104:                    // connection, which is anyway will fail, so postpone it to users next try
105:                    if (openDownloadMgr) {
106:                        p = new Server(Param.getBindPort());
107:                        //int localport = p.getLocalPort();
108:                        Thread t = new Thread(p);
109:                        t.start();
110:                        call("loadsignedscript", 0);
111:                        call("loadsignedapplet", 0);
112:                    }
113:                } catch (Exception e) {
114:                    e.printStackTrace();
115:                    System.out.println(e.getMessage());
116:                    return;
117:                }
118:
119:            }
120:
121:            public void stop() {
122:                try {
123:                    super .stop();
124:                } catch (Exception e) {
125:                    e.printStackTrace();
126:                }
127:            }
128:
129:            public void addItem(String newWord) {
130:                repaint();
131:            }
132:
133:            public void paint(Graphics g) {
134:                super .paint(g);
135:            }
136:
137:            /**
138:             * callJSFinish
139:             *               This function invokes a JS function in the downloadmgr page, that
140:             *               completes the downloadmgr loading.
141:             */
142:            private void call(String funcName, int localport) {
143:                JSObject win;
144:
145:                String hostname = null;
146:                try {
147:                    hostname = InetAddress.getLocalHost().getHostAddress();
148:                } catch (Exception ignore) {
149:                }
150:
151:                Object[] arg = { hostname, Integer.toString(localport) };
152:
153:                win = getWindow();
154:                win.call(funcName, arg);
155:
156:            }
157:
158:            public JSObject getWindow() {
159:                JSObject win = null;
160:                String vmversion = System.getProperty("java.version");
161:
162:                // get the applets represented by this applet context
163:                Enumeration applets = getAppletContext().getApplets();
164:
165:                Applet _applet = null;
166:                while (applets.hasMoreElements()) {
167:                    _applet = (Applet) applets.nextElement();
168:                }
169:
170:                //
171:                // This was required in Netscape for Java 1.3.0
172:                //
173:                if (vmversion.indexOf("1.3.0") != -1) {
174:                    System.out.println("calling jsobject for 1.3.0 versions");
175:                    win = JSObject.getWindow(getAppletContext().getApplet(
176:                            "downapp"));
177:                } else
178:                    win = JSObject.getWindow(this );
179:
180:                return win;
181:            }
182:
183:            private static int getfreeport() {
184:                ServerSocket s = null;
185:                int port = 0;
186:                try {
187:                    s = new ServerSocket(0);
188:                    port = s.getLocalPort();
189:
190:                } catch (IOException e) {
191:                    getfreeport();
192:                } finally {
193:                    if (s != null) {
194:                        try {
195:                            s.close();
196:                        } catch (IOException e) {
197:                            getfreeport();
198:                        }
199:                    }
200:                }
201:
202:                System.out.println("getfreeport " + port);
203:                return port;
204:            }
205:
206:            /**
207:             *  This function just checks whether browser proxy settings has direction connection
208:             *  or not by just creating dummy connection.
209:             * @return
210:             */
211:            private boolean isDirectConnection() {
212:                try {
213:                    AbstractSSLProvider gwConnection = SSLProviderFactory
214:                            .createFactory(Param.getSSLProvider());
215:                    gwConnection.connect(Param.getGatewayHost(), Param
216:                            .getGatewayPort(), null);
217:                    gwConnection.close();
218:                } catch (Exception e) {
219:                    return false;
220:                }
221:                return true;
222:            }
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.