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


001:        /*
002:         * CachedSocketFactory.java
003:         *
004:         * $Author: ss150821 $
005:         *
006:         * $Date: 2005/09/21 11:28:55 $ $Revision: 1.10 $
007:         *
008:         * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
009:         *
010:         * Developed by SunPS and SunIR
011:         */
012:
013:        package com.sun.portal.rproxy.connectionhandler;
014:
015:        import java.net.Socket;
016:        import java.util.logging.Level;
017:        import java.util.logging.Logger;
018:
019:        import javax.net.ssl.SSLSocket;
020:        import javax.net.ssl.SSLSocketFactory;
021:
022:        import com.sun.portal.log.common.PortalLogger;
023:        import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
024:        import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
025:        import com.sun.portal.util.GWLocale;
026:        import com.sun.portal.util.GWLogManager;
027:        import com.sun.portal.util.SRAEvent;
028:
029:        /**
030:         * This class defines a factory used to create CachedSockets. The types of
031:         * Sockets that it can create are defined in a configuration file called
032:         * CachedSocketFactory.config.
033:         *
034:         * @author Kevin Hartig
035:         */
036:
037:        public class SSLCachedSSLSocketFactory {
038:
039:            private static SocketCache _cache;
040:
041:            private static final String BLOCKED_SOCKET_TIMEOUT = "BlockedSocketTimeout";
042:
043:            private static final int DEFAULT_SOCKET_TIMEOUT = 200;
044:
045:            private static int _timeout;
046:
047:            // private static Logger logger =
048:            // Logger.getLogger("com.sun.portal.sra.rproxy");
049:            private static Logger logger = PortalLogger
050:                    .getLogger(SSLCachedSSLSocketFactory.class);
051:
052:            static {
053:                _timeout = GatewayProfile.getInt(BLOCKED_SOCKET_TIMEOUT,
054:                        DEFAULT_SOCKET_TIMEOUT) * 1000;
055:                _cache = new SocketCache();
056:            }
057:
058:            /**
059:             * Create a new socket.
060:             *
061:             * @param host
062:             *            the host address the client socket attaches to (d%.d%.d%.d%
063:             *            format)
064:             * @param port
065:             *            the port number to bind to the Socket
066:             * @param socketType
067:             *            the type of socket to create inside the CachedSocket
068:             * @return a CachedSocket bound to the designated host:port and containing a
069:             *         Socket of the requested type. This value is null if socket
070:             *         creation failed.
071:             */
072:            private static CachedSocket createSocket(String host, int port,
073:                    String socketType, Integer logId) {
074:                CachedSocket cachedSocket = null;
075:                SSLSocket sslSocket = null;
076:                Socket socket = null; // the delegate socket used by the returned
077:                // CachedSocket
078:
079:                // Construct the socket desired and pass it to a newly constructed
080:                // CachedSocket.
081:                try {
082:                    socket = SSLSocketFactory.getDefault().createSocket(host,
083:                            port);
084:                    MonitoringSubsystem
085:                            .handleEvent(SRAEvent.SSL_SOCKET_CREATED);
086:                    if (GWLogManager.loggingEnabled)
087:                        GWLogManager.write("RProxy", GWLocale.getPFString(
088:                                "csslsf1", new Object[] { logId,
089:                                        socket.getInetAddress().toString(),
090:                                        new Integer(socket.getPort()) }));
091:
092:                    sslSocket = (SSLSocket) socket;
093:                    sslSocket.setUseClientMode(true);
094:                    socket.setSoTimeout(_timeout);
095:
096:                    cachedSocket = new CachedSocket(socket);
097:                    cachedSocket.setType(socketType);
098:                    cachedSocket.setActive();
099:                    cachedSocket.setSocketCache(_cache);
100:                    _cache.putSocket(cachedSocket);
101:                } catch (Exception e) {
102:                    // logger.log(Level.SEVERE, "SSLCachedSSLSocketFactory cannot open
103:                    // connection to " + host + ":" + port, e);
104:                    Object[] params = { host, port + "", e };
105:                    logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCONHNDLR116",
106:                            params);
107:                }
108:
109:                return cachedSocket;
110:            }
111:
112:            public static CachedSocket createSocket(SSLSocket sslSocket) {
113:                CachedSocket cachedSocket = null;
114:
115:                try {
116:                    sslSocket.setUseClientMode(true);
117:                    sslSocket.setSoTimeout(_timeout);
118:
119:                    cachedSocket = new CachedSocket(sslSocket);
120:                    cachedSocket.setType(new String("ssl"));
121:                    cachedSocket.setActive();
122:                    cachedSocket.setSocketCache(_cache);
123:                    _cache.putSocket(cachedSocket);
124:                } catch (Exception e) {
125:                    // logger.log(Level.SEVERE, "SSLCachedSSLSocketFactory cannot create
126:                    // socket", e);
127:                    logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCONHNDLR117", e);
128:                    // e.printStackTrace();
129:                }
130:
131:                return cachedSocket;
132:            }
133:
134:            /**
135:             * Get a CachedSocket with a Socket of appropriate type. The CachedSocket
136:             * returned could be a newly created one or one already in the socket cache
137:             * ready for reuse.
138:             *
139:             * @param host
140:             *            the host address the client socket attaches to (d%.d%.d%.d%
141:             *            format)
142:             * @param port
143:             *            the port number to bind to the Socket
144:             * @param socketType
145:             *            the type of socket to create inside the CachedSocket
146:             * @return a CachedSocket bound to the designated host:port and containing a
147:             *         Socket of the requested type. This value is null if socket
148:             *         creation failed.
149:             *
150:             */
151:            public static CachedSocket getCachedSocket(String host, int port,
152:                    String socketType, Integer logId) {
153:                CachedSocket cachedSocket = null;
154:
155:                // Try to get a socket already in the cache
156:
157:                // There are problems with InetAddress.getByName().getHostAddress()
158:                // -- sometimes hangs for a period of time.
159:
160:                // cachedSocket = _cache.getSocket(host, port, socketType);
161:
162:                // If cachedSocket is null, no cached socket was found.
163:                // Create a new socket and put it in the cache
164:                if (cachedSocket == null) {
165:                    cachedSocket = createSocket(host, port, socketType, logId);
166:                }
167:
168:                return cachedSocket;
169:            }
170:
171:            /**
172:             * Get a CachedSocket with a Socket of appropriate type. The CachedSocket
173:             * returned could be a newly created one or one already in the socket cache
174:             * ready for reuse.
175:             *
176:             * @param host
177:             *            the host address the client socket attaches to (d%.d%.d%.d%
178:             *            format)
179:             * @param port
180:             *            the port number to bind to the Socket
181:             * @param socketType
182:             *            the type of socket to create inside the CachedSocket
183:             * @return a CachedSocket bound to the designated host:port and containing a
184:             *         Socket of the requested type. This value is null if socket
185:             *         creation failed.
186:             *
187:             */
188:            public static CachedSocket getNewCachedSocket(String host,
189:                    int port, String socketType, Integer logId) {
190:                // get a newly created socket that was just put in the cache
191:                return createSocket(host, port, socketType, logId);
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.