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


001:        // %Z%%M% %I%     "%W% %E% Sun Microsystems"
002:
003:        package com.sun.portal.netlet.client.common;
004:
005:        import com.sun.portal.netlet.econnection.Base64;
006:        import java.awt.*;
007:        import java.awt.event.ActionEvent;
008:        import java.awt.event.ActionListener;
009:        import java.io.*;
010:        import java.util.StringTokenizer;
011:
012:        public class ProxySConn extends Connection implements  ActionListener {
013:
014:            private DataInputStream in_b;
015:            private DataOutputStream out_b;
016:
017:            private String dhost;
018:            private int dport;
019:
020:            private ProxyAuthDialog pad;
021:            private String puser;
022:            private String ppass;
023:
024:            /**
025:             * Create plain socket only for connecting applet to local user's FTP client.
026:             * Do not use this constructor for any other purpose.
027:             */
028:            public ProxySConn(int pp, String ph, boolean toClient) {
029:                super (pp, ph);
030:            }
031:
032:            public ProxySConn(int pp, String ph, String cipherName) {
033:                super (pp, ph);
034:                NetletSocketFactory nsf = NetletSocketFactory
035:                        .getNetletSocketFactory(ClientConfig.getDestProtocol(),
036:                                ClientConfig.isJSSEEnabled(), ClientConfig
037:                                        .isPDCEnabled());
038:
039:                if (cipherName != null) {
040:                    conn = nsf.getSocket(conn, ph, pp,
041:                            parseCipherList(cipherName));
042:                } else {
043:                    conn = nsf.getSocket(conn, ph, pp, null);
044:                }
045:
046:            }
047:
048:            public ProxySConn(int pp, String ph, int dp, String dh,
049:                    String cipherName) throws ProxyAuthNeededException,
050:                    ProxyAuthFailedException {
051:                this (pp, ph, dp, dh, false, cipherName);
052:            }
053:
054:            public ProxySConn(int pp, String ph, int dp, String dh,
055:                    boolean doauth, String cipherName)
056:                    throws ProxyAuthNeededException, ProxyAuthFailedException {
057:
058:                super (pp, ph);
059:                dhost = dh;
060:                dport = dp;
061:                if (conn != null) {
062:                    try {
063:                        in_b = new DataInputStream(conn.getInputStream());
064:                        out_b = new DataOutputStream(conn.getOutputStream());
065:                    } catch (IOException e) {
066:                        System.out.println("ProxySConn setup IOE: " + e);
067:                        try {
068:                            conn.close();
069:                        } catch (IOException ie) {
070:                        }
071:                        conn = null;
072:                        return;
073:                    }
074:                    if (doProxyConnect(doauth) != 0) {
075:                        try {
076:                            conn.close();
077:                        } catch (IOException ie) {
078:                        }
079:                        conn = null;
080:                    }
081:
082:                    NetletSocketFactory nsf = NetletSocketFactory
083:                            .getNetletSocketFactory(ClientConfig
084:                                    .getDestProtocol(), ClientConfig
085:                                    .isJSSEEnabled(), ClientConfig
086:                                    .isPDCEnabled());
087:
088:                    if (cipherName != null) {
089:                        conn = nsf.getSocket(conn, dh, dp,
090:                                parseCipherList(cipherName));
091:                    } else {
092:                        conn = nsf.getSocket(conn, dh, dp, null);
093:                    }
094:                }
095:            }
096:
097:            /*
098:             * connect to web proxy server. deal with proxy-auth if we can
099:             * @param doauth put of proxy auth dialog and do proxy auth
100:             */
101:            public int doProxyConnect(boolean doauth)
102:                    throws ProxyAuthNeededException, ProxyAuthFailedException {
103:                int rc = 0;
104:
105:                String header = "CONNECT " + dhost + ":" + dport
106:                        + " HTTP/1.0\r\n";
107:
108:                try {
109:                    // either force it, or check to see if it's been done already
110:                    if (doauth || (ClientConfig.getProxyAuth())) {
111:                        // check for pre-entered info
112:                        puser = ClientConfig.getProxyAuthUsername();
113:                        ppass = ClientConfig.getProxyAuthPassword();
114:
115:                        if (puser == null || ppass == null) {
116:                            pad = new ProxyAuthDialog((new Frame()), this );
117:                            System.out
118:                                    .println("Netlet showing proxy authentication dialog");
119:                            pad.showWarning();
120:                            pad.waitForAction();
121:                        }
122:
123:                        // if either are null, user cancelled
124:                        // disallow hi-byte chars for now, we won't be able to test this, so we can't support it
125:                        if (puser == null || ppass == null) {
126:                            throw new ProxyAuthFailedException(
127:                                    ResourceProperties.getString("psconn.1"));
128:                            // Proxy authentication no username/password
129:                        }
130:
131:                        header += "Proxy-Authorization: Basic "
132:                                + Base64.encode(puser + ":" + ppass)
133:                                + "\r\n\r\n";
134:                    } else {
135:                        header += "\r\n";
136:                    }
137:
138:                    out_b.write(header.getBytes(), 0, header.length());
139:
140:                    BufferedReader br = new BufferedReader(
141:                            new InputStreamReader(in_b));
142:                    String line = "";
143:                    while (true) {
144:                        line = br.readLine();
145:                        if (line == null || line.length() < 3)
146:                            break;
147:                        // looking for: HTTP/1.0 407 Proxy-Authentication Required
148:                        if (line.startsWith("HTTP/1")) {
149:                            int s = line.indexOf(" ");
150:                            String num = line.substring(s + 1);
151:                            if (num.startsWith("407")) {
152:                                // jump out of here if we need to do auth (not shown in dialog)
153:                                throw new ProxyAuthNeededException(
154:                                        "Proxy Authentication Required");
155:                            } else if (num.startsWith("401")) {
156:                                throw new ProxyAuthFailedException(
157:                                        ResourceProperties
158:                                                .getString("psconn.3"));
159:                                // Proxy Digest Authentication Not Supported
160:                            }
161:                        }
162:                    }
163:                } catch (StringIndexOutOfBoundsException e) {
164:                    System.out.println("ProxySConn SIOBE connecting to proxy: "
165:                            + e);
166:                    rc = -1;
167:                } catch (IOException e) {
168:                    System.out.println("ProxySConn IOE connecting to proxy: "
169:                            + e);
170:                    rc = -1;
171:                }
172:
173:                return (rc);
174:            }
175:
176:            /*
177:             * deal with events from ProxyAuthDialog
178:             */
179:            public void actionPerformed(ActionEvent evt) {
180:                // return in password field to submit has 'cancel' from setActionCommand(),
181:                // so ignore 'cancel' since it's only event we don't want
182:                if (!"cancel".equals(evt.getActionCommand())) {
183:                    puser = ClientUtil.rfc1522(pad.getUsername());
184:                    ppass = ClientUtil.rfc1522(pad.getPassword());
185:                    ClientConfig.setProxyAuthUsername(puser);
186:                    ClientConfig.setProxyAuthPassword(ppass);
187:                }
188:                // cancel falls through
189:                pad.notifyAction();
190:                pad.setVisible(false);
191:                pad.dispose();
192:            }
193:
194:            private String[] parseCipherList(String cipherList) {
195:                StringTokenizer stz = new StringTokenizer(cipherList, "|");
196:                String[] cipherArray = new String[stz.countTokens()];
197:                int i = 0;
198:                while (stz.hasMoreElements()) {
199:                    cipherArray[i] = stz.nextElement().toString();
200:                }
201:                return cipherArray;
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.