Source Code Cross Referenced for RWGroupCrypt.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.net.Socket;
006:        import java.util.logging.Level;
007:        import java.util.logging.Logger;
008:
009:        import com.sun.portal.log.common.PortalLogger;
010:        import com.sun.portal.netlet.econnection.ReaderWriter;
011:        import com.sun.portal.netlet.econnection.ReaderWriterDecrypt;
012:        import com.sun.portal.netlet.econnection.ReaderWriterEncrypt;
013:        import com.sun.portal.netlet.econnection.ReaderWriterLock;
014:        import com.sun.portal.rproxy.configservlet.client.NetletProfile;
015:        import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
016:        import com.sun.portal.util.GWLocale;
017:        import com.sun.portal.util.GWThreadPool;
018:        import com.sun.portal.util.NetletLogMgr;
019:        import com.sun.portal.util.SRAEvent;
020:
021:        public class RWGroupCrypt extends ReaderWriterLock {
022:
023:            public boolean done = false;
024:            private int srcPort;
025:
026:            private String destPort;
027:
028:            private String destHost;
029:
030:            private Socket fromClient;
031:
032:            private Socket toServer;
033:
034:            private ReaderWriterDecrypt src_to_dst;
035:
036:            private ReaderWriterEncrypt dst_to_src;
037:
038:            private SessionAuthenticator sessionAuth;
039:
040:            private SessionRequest sessionReq;
041:
042:            private Integer netletLogId;
043:
044:            private long startTime;
045:
046:            private boolean stopLogged = false;
047:
048:            private static Logger logger = PortalLogger
049:                    .getLogger(RWGroupCrypt.class);
050:
051:            public ReaderWriterDecrypt getReaderWriterDecrypt() {
052:                return src_to_dst;
053:            }
054:
055:            public ReaderWriterEncrypt getReaderWriterEncrypt() {
056:                return dst_to_src;
057:            }
058:
059:            public String getDestPort() {
060:                return destPort;
061:            }
062:
063:            public String getDestHost() {
064:                return destHost;
065:            }
066:
067:            public RWGroupCrypt(Socket in, int sport, String dport,
068:                    String dhost, SessionAuthenticator sa, SessionRequest rq) {
069:                fromClient = in;
070:                srcPort = sport;
071:                destPort = new String(dport);
072:                destHost = new String(dhost);
073:                sessionAuth = sa;
074:                sessionReq = rq;
075:
076:                // do the connect in here to see if we can "save" the connect obj
077:                // open connection to remote for this client
078:                toServer = SConn.connect(destPort, destHost);
079:
080:                if (toServer == null) {
081:                    // logger.severe("RWGroupCrypt: unable to make server connection!");
082:                    logger.severe("PSSRNTLT_CSPNEPROX075");
083:                    cleanup();
084:                    return;
085:                }
086:
087:                try {
088:                    toServer.setKeepAlive(true);
089:                    fromClient.setKeepAlive(true);
090:                } catch (Exception ex) {
091:                    // logger.log(Level.SEVERE, "RWGroupCrypt: failed to set KeepAlive
092:                    // for socket " , ex);
093:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX076");
094:                }
095:
096:                // Added for Netlet PRD 5.1 for Lihue
097:                if (NetletLogMgr.loggingEnabled) {
098:                    try {
099:                        netletLogId = new Integer(NetletLogMgr.getLogId());
100:                        NetletLogMgr.write("Netlet", GWLocale.getPFString(
101:                                "en1", new Object[] {
102:                                        netletLogId,
103:                                        new String(NetletLogMgr
104:                                                .getUserId(sessionReq
105:                                                        .getSessionID())),
106:                                        "START",
107:                                        fromClient.getInetAddress().toString(),
108:                                        new Integer(srcPort),
109:                                        toServer.getInetAddress().toString(),
110:                                        new Integer(toServer.getPort()) }));
111:                    } catch (Exception e) {
112:                    } // May cause null pointer exception
113:                }
114:
115:                if (getNetletKeepAliveInterval(rq) > 0) {
116:                    try {
117:                        toServer
118:                                .setSoTimeout(getNetletKeepAliveInterval(rq) * 1000);
119:                    } catch (Exception se) {
120:                        System.out.println("Unable to set socket time out.."
121:                                + se);
122:                    }
123:                }
124:
125:                try {
126:                    src_to_dst = new ReaderWriterDecrypt(this , fromClient
127:                            .getInputStream(), toServer.getOutputStream());
128:                    dst_to_src = new ReaderWriterEncrypt(this , toServer
129:                            .getInputStream(), fromClient.getOutputStream(),
130:                            getNetletKeepAliveInterval(rq));
131:                } catch (Exception ex) {
132:                    // logger.log(Level.SEVERE, "RWGroupCrypt: Unable to create reader
133:                    // writers.", ex);
134:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX077");
135:                }
136:
137:                // start keep alive timer here, to make sure it starts
138:                // before RW threads, so that KP is not left running amok!
139:                /*
140:                 * if (ServiceIdentifier.isGateway() && !getNetletRunUponLogout(rq)) {
141:                 * kp = new KeepAlive(sessionAuth, sessionReq, this, src_to_dst,
142:                 * dst_to_src); try { GWThreadPool.run(kp); } catch
143:                 * (InterruptedException e) { // logger.log(Level.SEVERE, "Could not
144:                 * start KeepAlive", e);
145:                 * logger.log(Level.SEVERE,"PSSRNTLT_CSPNEPROX078"); } } else { kp =
146:                 * null; }
147:                 */
148:                try {
149:                    GWThreadPool.run(src_to_dst);
150:                    GWThreadPool.run(dst_to_src);
151:                } catch (InterruptedException e) {
152:                    // logger.log(Level.SEVERE, "Could not start ReaderWriterClear
153:                    // tasks", e);
154:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX079");
155:                }
156:                // System.out.println("Ran ReaderWriter....");
157:                startTime = System.currentTimeMillis();
158:            }
159:
160:            public synchronized void notifyFinished(ReaderWriter obj) {
161:                if (!stopLogged && NetletLogMgr.loggingEnabled) {
162:                    try {
163:                        netletLogId = new Integer(NetletLogMgr.getLogId());
164:                        NetletLogMgr.write("Netlet", GWLocale.getPFString(
165:                                "en1", new Object[] {
166:                                        netletLogId,
167:                                        new String(NetletLogMgr
168:                                                .getUserId(sessionReq
169:                                                        .getSessionID())),
170:                                        new String("STOP"),
171:                                        fromClient.getInetAddress().toString(),
172:                                        new Integer(srcPort),
173:                                        toServer.getInetAddress().toString(),
174:                                        new Integer(toServer.getPort()) }));
175:                        stopLogged = true;
176:                    } catch (Exception e) {
177:                    } // May cause Null pointer exception
178:                }
179:                if (obj == src_to_dst) {
180:                    if (dst_to_src != null) {
181:                        dst_to_src.stop();
182:                    }
183:                } else if (obj == dst_to_src) {
184:                    if (src_to_dst != null) {
185:                        src_to_dst.stop();
186:                    }
187:                }
188:                cleanup();
189:            }
190:
191:            public synchronized void stopAll() {
192:
193:                if (!done) {
194:                    if (dst_to_src != null) {
195:                        dst_to_src.stop();
196:                    }
197:                    if (src_to_dst != null) {
198:                        src_to_dst.stop();
199:                    }
200:                    cleanup();
201:                }
202:            }
203:
204:            public void cleanup() {
205:                try {
206:                    /*
207:                     * if (kp != null) { try { kp.stop(); // send one more to extend
208:                     * session from last action kp.sendRequest(); } catch (Exception e) { }
209:                     * finally { kp = null; } }
210:                     */if (fromClient != null) {
211:                        try {
212:                            fromClient.close();
213:                        } catch (Exception e) {
214:                        } finally {
215:                            MonitoringSubsystem
216:                                    .handleEvent(SRAEvent.PLAIN_SOCKET_DESTROYED);
217:                            fromClient = null;
218:                        }
219:                    }
220:                    if (toServer != null) {
221:                        try {
222:                            toServer.close();
223:                        } catch (Exception e) {
224:                        } finally {
225:                            MonitoringSubsystem
226:                                    .handleEvent(SRAEvent.PLAIN_SOCKET_DESTROYED);
227:                            toServer = null;
228:                        }
229:                    }
230:                } finally {
231:                    src_to_dst = null;
232:                    dst_to_src = null;
233:                    done = true;
234:                }
235:            }
236:
237:            public boolean isDone() {
238:                return (done);
239:            }
240:
241:            /*
242:             * Added for RFE 4492648
243:             */
244:
245:            public long getLastActivityTime() {
246:
247:                if (src_to_dst.getLastActivityTime() > dst_to_src
248:                        .getLastActivityTime())
249:                    return src_to_dst.getLastActivityTime();
250:                else
251:                    return dst_to_src.getLastActivityTime();
252:
253:            }
254:
255:            /*
256:             * Added for RFE - 4645457 returns boolean which determines whether the
257:             * netlet should continue upon logout or not @ returns false on error
258:             */
259:            /*
260:             * private boolean getNetletRunUponLogout(SessionRequest rq) { try { String
261:             * sid = rq.getSessionID(); NetletProfile profile = new NetletProfile(sid);
262:             * return !(profile.getBoolean("TerminateAtLogout", true)); }
263:             * catch(Exception e){ return false; } }
264:             */
265:
266:            private int getNetletKeepAliveInterval(SessionRequest rq) {
267:                try {
268:                    String sid = rq.getSessionID();
269:                    NetletProfile profile = new NetletProfile(sid);
270:                    // logger.info("RWGroupCrypt: Netlet keep alive interval -> " +
271:                    // profile.getInt("KeepAliveInterval", 0));
272:                    Object[] params5 = { new Integer(profile.getInt(
273:                            "KeepAliveInterval", 0)) };
274:                    logger.log(Level.INFO, "PSSRNTLT_CSPNEPROX080", params5);
275:                    return profile.getInt("KeepAliveInterval", 0);
276:                } catch (Exception e) {
277:                    return 0;
278:                }
279:            }
280:
281:            public long getStartTime() {
282:                return startTime;
283:            }
284:
285:            public int getAppletSrcPort() {
286:                return srcPort;
287:            }
288:
289:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.