Source Code Cross Referenced for NetletProxyRouter.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:        /*
002:         * Reads the following properties from the Gateway profile - stored in DSAME
003:         *
004:         * 1. sunPortalNetletProxyHost
005:         *      List of netlet proxy instances that this gateway is configured to service
006:         *
007:         * 2. sunPortalGatewayServerRetryInterval
008:         *      Time interval - frequency at which the gateway should ping the netlet
009:         *      proxy to find whether the netlet proxy is available
010:         *
011:         *  Maintains two list list of available and unavailable netlet proxies and pings
012:         *  at the frequency as defined by the server retry interval. Creates a worker thread
013:         *  to continously carry out this activity
014:         *
015:         * TBD:
016:         *
017:         * 1. There is a similiar class like this in rproxy/connectionhandler called ServersList.java,
018:         * both these are to be combined into a single entity as there share most of functionality
019:         *
020:         * 2. Need a protocol representation for netlet, something like netlet://host:port and 
021:         *  corresponding URL Handlers
022:         * 
023:         * 3. Tunneling Netlet request to Netlet Proxy from GW via third party standard proxy.
024:         * 
025:         * @ author Rajesh T
026:         * @ date 29-7-2002
027:         */
028:
029:        package com.sun.portal.netlet.eproxy;
030:
031:        import java.io.IOException;
032:        import java.net.URL;
033:        import java.util.HashMap;
034:        import java.util.HashSet;
035:        import java.util.Iterator;
036:        import java.util.List;
037:        import java.util.Map;
038:        import java.util.Set;
039:        import java.util.logging.Level;
040:        import java.util.logging.Logger;
041:
042:        import com.sun.portal.log.common.PortalLogger;
043:        import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
044:        import com.sun.portal.util.HostAvailabilityEvent;
045:        import com.sun.portal.util.HostAvailabilityListener;
046:        import com.sun.portal.util.HostChecker;
047:
048:        public class NetletProxyRouter extends HostAvailabilityListener {
049:
050:            static Set netlet_proxies = new HashSet();
051:
052:            public static Map _unavailable_netlet_proxies = new HashMap();
053:
054:            private static int _retry;
055:
056:            private static Iterator iterator;
057:
058:            private static int noOfNetletProxies = 0;
059:
060:            private static String onlyOneNetletProxy = null;
061:
062:            private static final int PROXY_HTTP_PORT = 8080;
063:
064:            private static NetletProxyRouter instance;
065:
066:            // private static Logger logger =
067:            // Logger.getLogger("com.sun.portal.sra.netlet");
068:            private static Logger logger = PortalLogger
069:                    .getLogger(NetletProxyRouter.class);
070:
071:            static {
072:                instance = new NetletProxyRouter();
073:                _retry = GatewayProfile.getInt("ServerRetryInterval", 5);
074:                List allnetlet_proxies = GatewayProfile
075:                        .getStringList("NetletProxyHost");
076:                Iterator it = allnetlet_proxies.iterator();
077:                noOfNetletProxies = allnetlet_proxies.size();
078:
079:                /*
080:                 * Spoofing the third party proxy as Netlet Proxy for a HTTPS request so
081:                 * that the proxy just tunnels all request thinks its https.
082:                 */
083:
084:                if (noOfNetletProxies == 1) {
085:                    onlyOneNetletProxy = "https://" + it.next().toString();
086:                } else {
087:                    while (it.hasNext())
088:                        netlet_proxies.add("https://"
089:                                + it.next().toString().toLowerCase());
090:                    iterator = netlet_proxies.iterator();
091:                }
092:            }
093:
094:            private NetletProxyRouter() {
095:                addHostAvailabilityListener(this );
096:            }
097:
098:            public void hostAvailabilityChanged(HostAvailabilityEvent hae) {
099:                // TODO :: check for proper host type and host status
100:                if (hae.getHostType() == hae.NP_HOST) {
101:                    synchronized (_unavailable_netlet_proxies) {
102:                        if (hae.getHostStatus() == hae.HOST_AVAILABLE) {
103:                            _unavailable_netlet_proxies.remove(hae.getHost());
104:                        } else if (hae.getHostStatus() == hae.HOST_UNAVAILABLE) {
105:                            long time = System.currentTimeMillis();
106:                            _unavailable_netlet_proxies.put(hae.getHost(),
107:                                    (new Long(time)));
108:                        }
109:                    }
110:                }
111:            }
112:
113:            /*
114:             * @ returns true if the specified netlet proxy is present in the netlet
115:             * proxy host list
116:             */
117:
118:            public static boolean contains(String rwp) {
119:                if (rwp == null || rwp.trim().length() == 0) {
120:                    return false;
121:                }
122:                if (noOfNetletProxies == 1) {
123:                    return onlyOneNetletProxy.equalsIgnoreCase(rwp);
124:                } else {
125:                    return (netlet_proxies.contains(rwp.toLowerCase()));
126:                }
127:            }
128:
129:            /*
130:             * @returns the next available netlet proxy . A simple round-robin load
131:             * balancing algorithm implementation with iterators.
132:             */
133:
134:            public static synchronized String getServer() {
135:
136:                /*
137:                 * There is no need for load balancing as there is only one netlet proxy
138:                 * so return the only available netlet proxy
139:                 */
140:
141:                if (noOfNetletProxies < 2) {
142:                    return onlyOneNetletProxy;
143:                }
144:
145:                if (iterator.hasNext()) {
146:                    return iterator.next().toString();
147:                } else {
148:                    iterator = netlet_proxies.iterator();
149:                    return iterator.next().toString();
150:                }
151:            }
152:
153:            /*
154:             * @ returns true if the specified netlet proxy is alive Do not create
155:             * socket directly to the netlet proxy coz there may be a external proxy
156:             * server between the DMZ and intranet, typically specified as java vm
157:             * parameters -Djava.proxySet, -Djava.proxyHost, -Djava.proxyPort
158:             * 
159:             * URL factory implementation respects these parameter hence no extra
160:             * tunneling code.
161:             * 
162:             */
163:
164:            private static boolean isAlive(String nlp) {
165:                synchronized (_unavailable_netlet_proxies) {
166:                    if (!_unavailable_netlet_proxies.isEmpty()
167:                            && _unavailable_netlet_proxies.get(nlp) != null) {
168:                        return false; // do not use it!
169:                    }
170:                }
171:                try {
172:                    URL url = new URL(nlp);
173:
174:                    return HostChecker.isHostAvailable(url,
175:                            HostAvailabilityEvent.NP_HOST);
176:                } catch (IOException e) {
177:                    // logger.log(Level.SEVERE, "Proxy Authentication Failed", e);
178:                    logger.log(Level.SEVERE, "PSSRNTLT_CSPNEPROX049");
179:                }
180:                return false;
181:            }
182:
183:            /*
184:             * get a alive Netlet proxy and return
185:             */
186:
187:            static String getNetletProxyAlive() {
188:
189:                String nlp = null;
190:                boolean alive = false;
191:                if (noOfNetletProxies == 1) {
192:                    if (isAlive(onlyOneNetletProxy)) {
193:                        return onlyOneNetletProxy;
194:
195:                    } else {
196:                        return null;
197:                    }
198:                }
199:
200:                int alive_servers = netlet_proxies.size();
201:
202:                while (!alive && alive_servers > 0) {
203:                    nlp = getServer();
204:                    alive = isAlive(nlp);
205:                    alive_servers--;
206:                }
207:
208:                if (alive == false)
209:                    return null;
210:
211:                return nlp;
212:            }
213:
214:            static boolean isNetletProxyAlive(String nlp) {
215:                return isAlive(nlp);
216:            }
217:
218:            /*
219:             * If the requested netlet proxy is alive return it else return any other
220:             * live netlet proxy
221:             */
222:
223:            static String getNetletProxyAlive(String nlp) {
224:                if (isAlive(nlp)) {
225:                    return nlp;
226:                }
227:
228:                return (getNetletProxyAlive());
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.