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


001:        // @(#)RWGroupCrypt.java 1.13     "@(#)RWGroupCrypt.java	1.13 99/09/23 Sun Microsystems"
002:
003:        package com.sun.portal.netlet.eproxy;
004:
005:        import java.io.DataOutputStream;
006:        import java.io.IOException;
007:        import java.net.InetAddress;
008:        import java.net.ServerSocket;
009:        import java.net.Socket;
010:        import java.util.StringTokenizer;
011:        import java.util.logging.Level;
012:        import java.util.logging.Logger;
013:
014:        import com.sun.portal.log.common.PortalLogger;
015:        import com.sun.portal.netlet.econnection.ReaderWriter;
016:        import com.sun.portal.netlet.econnection.ReaderWriterDecrypt;
017:        import com.sun.portal.netlet.econnection.ReaderWriterEncrypt;
018:        import com.sun.portal.netlet.econnection.ReaderWriterLock;
019:        import com.sun.portal.rproxy.configservlet.client.NetletProfile;
020:        import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
021:        import com.sun.portal.util.GWThreadPool;
022:        import com.sun.portal.util.SystemProperties;
023:        import com.sun.portal.util.SRAEvent;
024:
025:        public class RWGroupFtp extends ReaderWriterLock {
026:
027:            public boolean done = false;
028:
029:            private Socket fromClient;
030:
031:            private Socket toServer;
032:
033:            private ReaderWriterDecrypt src_to_dst;
034:
035:            private ReaderWriterEncrypt dst_to_src;
036:
037:            private SessionAuthenticator sessionAuth;
038:
039:            private SessionRequest sessionReq;
040:
041:            private static int ip_part1, ip_part2, ip_part3, ip_part4;
042:
043:            private long startTime;
044:
045:            // private static Logger logger =
046:            // Logger.getLogger("com.sun.portal.sra.netlet");
047:            private static Logger logger = PortalLogger
048:                    .getLogger(RWGroupFtp.class);
049:
050:            static {
051:                String tmpip = SystemProperties.get("gateway.external.ip");
052:                /*
053:                 * added to support active FTP connections with netlet proxy.
054:                 */
055:
056:                /*
057:                 * Commented to support hostName instead of IP for NetletProxy in
058:                 * Gateway profile. NetletProxy's IP address should be taken from
059:                 * platform.conf with "gateway.external.ip" as key.
060:                 */
061:                /*
062:                 * useNetletproxy=GatewayProfile.getBoolean("UseNetletProxy", false);
063:                 * 
064:                 * if(useNetletproxy){ // if netletProxy enabled then get ip of netlet
065:                 * proxy. tmpip= GatewayProfile.getString("NetletProxyHost",tmpip); }
066:                 */
067:
068:                StringTokenizer stnm = new StringTokenizer(tmpip, ".");
069:                String part1 = stnm.nextToken();
070:                String part2 = stnm.nextToken();
071:                String part3 = stnm.nextToken();
072:                String part4 = stnm.nextToken();
073:                try {
074:                    ip_part1 = Integer.parseInt(part1);
075:                    ip_part2 = Integer.parseInt(part2);
076:                    ip_part3 = Integer.parseInt(part3);
077:                    ip_part4 = Integer.parseInt(part4);
078:                } catch (NumberFormatException n) {
079:                    // logger.severe("RWGroupFtp: invalid ip in platform.conf");
080:                    logger.severe("PSSRNTLT_CSPNEPROX087");
081:                }
082:
083:            }
084:
085:            public RWGroupFtp(Socket in, SessionAuthenticator sa,
086:                    SessionRequest rq) {
087:                fromClient = in;
088:                sessionAuth = sa;
089:                sessionReq = rq;
090:
091:                ServerSocket ss = null;
092:
093:                try {
094:                    ss = new ServerSocket(0);
095:                    MonitoringSubsystem
096:                            .handleEvent(SRAEvent.SERVER_SOCKET_CREATED);
097:                } catch (IOException ex) {
098:                    // logger.severe("RWGroupFtp: unable to create server socket for
099:                    // ftp." + ex);
100:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX088", ex);
101:                    return;
102:                }
103:
104:                String ipaddr = null;
105:                try {
106:                    ipaddr = InetAddress.getLocalHost().getHostAddress()
107:                            .replace('.', ',');
108:                } catch (Exception ex) {
109:                    // logger.severe("RWGroupFtp: Unable to get IP address");
110:                    logger.severe("PSSRNTLT_CSPNEPROX089");
111:                    return;
112:                }
113:
114:                int listenPort = ss.getLocalPort();
115:                String reply = ipaddr + "," + (listenPort / 256) + ","
116:                        + (listenPort % 256);
117:                System.out.println("Reply " + reply);
118:
119:                try {
120:                    DataOutputStream dos = new DataOutputStream(in
121:                            .getOutputStream());
122:                    dos.writeInt(ip_part1);
123:                    dos.writeInt(ip_part2);
124:                    dos.writeInt(ip_part3);
125:                    dos.writeInt(ip_part4);
126:                    dos.writeInt(listenPort / 256);
127:                    dos.writeInt(listenPort % 256);
128:                    dos.flush();
129:                } catch (Exception ex) {
130:                    return;
131:                }
132:
133:                boolean isHTTPS = ss instanceof  org.mozilla.jss.ssl.SSLServerSocket;
134:
135:                try {
136:                    ss.setSoTimeout(15000);
137:                    toServer = ss.accept();
138:                    if (isHTTPS) {
139:                        MonitoringSubsystem
140:                                .handleEvent(SRAEvent.SSL_SOCKET_CREATED);
141:                    } else {
142:                        MonitoringSubsystem
143:                                .handleEvent(SRAEvent.PLAIN_SOCKET_CREATED);
144:                    }
145:                } catch (Exception ex) {
146:                    // logger.severe("RWGroupCrypt: ftp data server socket can't accept.
147:                    // " + ex);
148:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX090", ex);
149:                    try {
150:                        ss.close();
151:                        fromClient.close();
152:                    } catch (Exception e) {
153:                        logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX113");
154:                    }
155:                }
156:                try {
157:                    src_to_dst = new ReaderWriterDecrypt(this , fromClient
158:                            .getInputStream(), toServer.getOutputStream());
159:                    dst_to_src = new ReaderWriterEncrypt(this , toServer
160:                            .getInputStream(), fromClient.getOutputStream(),
161:                            getNetletKeepAliveInterval(rq));
162:                } catch (Exception ex) {
163:                    System.out
164:                            .println("Unable to create ReaderWriter threads.");
165:                    ex.printStackTrace();
166:                }
167:
168:                // no keepalive here
169:                // kp = null;
170:
171:                try {
172:                    GWThreadPool.run(src_to_dst);
173:                    GWThreadPool.run(dst_to_src);
174:                } catch (InterruptedException e) {
175:                    // logger.log(Level.SEVERE, "Could not start ReaderWriterClear
176:                    // tasks", e);
177:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX091");
178:                }
179:                startTime = System.currentTimeMillis();
180:            }
181:
182:            public synchronized void notifyFinished(ReaderWriter obj) {
183:                if (obj == src_to_dst) {
184:                    if (dst_to_src != null) {
185:                        dst_to_src.stop();
186:                    }
187:                } else if (obj == dst_to_src) {
188:                    if (src_to_dst != null) {
189:                        src_to_dst.stop();
190:                    }
191:                }
192:                cleanup();
193:            }
194:
195:            public synchronized void stopAll() {
196:                if (!done) {
197:                    if (dst_to_src != null) {
198:                        dst_to_src.stop();
199:                    }
200:                    if (src_to_dst != null) {
201:                        src_to_dst.stop();
202:                    }
203:                    cleanup();
204:                }
205:            }
206:
207:            public void cleanup() {
208:                try {
209:                    /*
210:                     * if (kp != null) { try { kp.stop(); // send one more to extend
211:                     * session from last action kp.sendRequest(); } catch (Exception e) { }
212:                     * finally { kp = null; } }
213:                     */if (fromClient != null) {
214:                        try {
215:                            fromClient.close();
216:                            if (fromClient instanceof  org.mozilla.jss.ssl.SSLSocket) {
217:                                MonitoringSubsystem
218:                                        .handleEvent(SRAEvent.SSL_SOCKET_DESTROYED);
219:                            } else {
220:                                MonitoringSubsystem
221:                                        .handleEvent(SRAEvent.PLAIN_SOCKET_DESTROYED);
222:                            }
223:                        } catch (Exception e) {
224:                        } finally {
225:                            fromClient = null;
226:                        }
227:                    }
228:                    if (toServer != null) {
229:                        try {
230:                            toServer.close();
231:                            if (toServer instanceof  org.mozilla.jss.ssl.SSLSocket) {
232:                                MonitoringSubsystem
233:                                        .handleEvent(SRAEvent.SSL_SOCKET_DESTROYED);
234:                            } else {
235:                                MonitoringSubsystem
236:                                        .handleEvent(SRAEvent.PLAIN_SOCKET_DESTROYED);
237:                            }
238:                        } catch (Exception e) {
239:                        } finally {
240:                            toServer = null;
241:                        }
242:                    }
243:                } finally {
244:                    src_to_dst = null;
245:                    dst_to_src = null;
246:                    done = true;
247:                }
248:            }
249:
250:            public boolean isDone() {
251:                return (done);
252:            }
253:
254:            /*
255:             * Added for RFE 4492648
256:             */
257:            public long getLastActivityTime() {
258:
259:                if (src_to_dst.getLastActivityTime() > dst_to_src
260:                        .getLastActivityTime())
261:                    return src_to_dst.getLastActivityTime();
262:                else
263:                    return dst_to_src.getLastActivityTime();
264:
265:            }
266:
267:            public long getStartTime() {
268:                return startTime;
269:            }
270:
271:            public int getAppletSrcPort() {
272:                return -1;
273:            }
274:
275:            private int getNetletKeepAliveInterval(SessionRequest rq) {
276:                try {
277:                    String sid = rq.getSessionID();
278:                    NetletProfile profile = new NetletProfile(sid);
279:                    return profile.getInt("KeepAliveInterval", 0);
280:                } catch (Exception e) {
281:                    return 0;
282:                }
283:            }
284:
285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.