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


001:        /*
002:         * HostChecker.java
003:         *
004:         * Created on November 20, 2003, 3:36 PM
005:         */
006:
007:        package com.sun.portal.util;
008:
009:        import java.io.IOException;
010:        import java.net.MalformedURLException;
011:        import java.net.URL;
012:        import java.util.logging.Level;
013:        import java.util.logging.Logger;
014:
015:        import sun.misc.BASE64Decoder;
016:
017:        import com.sun.portal.log.common.PortalLogger;
018:        import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
019:
020:        /**
021:         * 
022:         * @author Mridul Muralidharan
023:         */
024:        public class HostChecker {
025:
026:            private static int _retry;
027:
028:            private static final int PROXY_HTTP_PORT = 8080;
029:
030:            // static Logger logger = Logger.getLogger("com.sun.portal.sra.rproxy");
031:            private static Logger logger = PortalLogger
032:                    .getLogger(HostChecker.class);
033:
034:            static {
035:                _retry = GatewayProfile.getInt("ServerRetryInterval", 5);
036:            }
037:
038:            public static boolean isHostAvailable(URL host, int hostType) {
039:
040:                try {
041:
042:                    String proxy = DomainWebProxyConfig.getWebProxy(host
043:                            .getProtocol(), host.getHost());
044:                    String proxyAuth = null;
045:                    if (proxy != null) {
046:                        String proxyHost = null;
047:                        int portIndex = proxy.indexOf(':');
048:
049:                        if (portIndex == -1) {
050:                            proxyHost = proxy;
051:                        } else {
052:                            proxyHost = proxy.substring(0, proxy.indexOf(':'));
053:                        }
054:                        proxyAuth = DomainWebProxyConfig
055:                                .getProxyPassword(proxyHost);
056:                    }
057:
058:                    String proxyHost = null;
059:                    int proxyPort = -1;
060:
061:                    String proxyUser = null;
062:                    PingServiceRequest psr = null;
063:                    String proxyPassword = null;
064:
065:                    if (proxy == null) {
066:                        psr = new PingServiceRequest(host);
067:                    } else {
068:                        int portIndex = proxy.indexOf(':');
069:
070:                        if (portIndex == -1) {
071:                            proxyPort = PROXY_HTTP_PORT;
072:                            proxyHost = proxy;
073:                        } else {
074:                            proxyHost = proxy.substring(0, proxy.indexOf(':'));
075:                            proxyPort = Integer.parseInt(proxy.substring(proxy
076:                                    .indexOf(':') + 1));
077:                        }
078:
079:                        BASE64Decoder decoder = new BASE64Decoder();
080:                        if (proxyAuth != null) {
081:                            try {
082:                                proxyAuth = new String(decoder
083:                                        .decodeBuffer(proxyAuth));
084:                            } catch (IOException ioe) {
085:                                // logger.log(Level.SEVERE, "Password decode failed:",
086:                                // ioe);
087:                                logger.log(Level.SEVERE, "PSSR_CSPU071", ioe);
088:                            }
089:                        }
090:
091:                        if (proxyAuth == null) {
092:                            psr = new PingServiceRequest(host, proxyHost,
093:                                    proxyPort);
094:                        } else {
095:                            proxyUser = proxyAuth.substring(0,
096:                                    proxyAuth.indexOf(':')).trim();
097:                            proxyPassword = proxyAuth.substring(
098:                                    proxyAuth.indexOf(':') + 1).trim();
099:                            psr = new PingServiceRequest(host, proxyHost,
100:                                    proxyPort, proxyUser, proxyPassword);
101:                        }
102:                    }
103:
104:                    boolean isAlive = psr.isServiceAlive();
105:                    if (!isAlive) {
106:                        HostAvailabilityEventImpl event = new HostAvailabilityEventImpl();
107:                        // event.setHost(host.getHost());
108:                        event.setHost(host.toString());
109:                        event.setHostStatus(event.HOST_UNAVAILABLE);
110:                        event.setHostType(hostType);
111:                        HostAvailabilityMediator.getHostAvailabilityMediator()
112:                                .notifyListeners(event);
113:                        watch_unavailable wus = new watch_unavailable(host
114:                                .toString(), _retry, proxyHost, proxyPort,
115:                                proxyUser, proxyPassword, hostType);
116:                        wus.start();
117:                    }
118:                    return isAlive;
119:                } catch (NumberFormatException e) {
120:                    // logger.log(Level.SEVERE, "Bad Proxy Port", e);
121:
122:                    logger.log(Level.SEVERE, "PSSR_CSPU072", e);
123:                } catch (ProxyUnreachableException e) {
124:                    // logger.log(Level.SEVERE, "Proxy used for reaching Portal Server
125:                    // Proxy is down:", e);
126:                    logger.log(Level.SEVERE, "PSSR_CSPU073", e);
127:                } catch (ProxyAuthNeededException e) {
128:                    // logger.log(Level.SEVERE, "Proxy password not found for
129:                    // authentication", e);
130:                    logger.log(Level.SEVERE, "PSSR_CSPU074", e);
131:                } catch (ProxyAuthFailedException e) {
132:                    // logger.log(Level.SEVERE, "Proxy Authentication Failed", e);
133:                    logger.log(Level.SEVERE, "PSSR_CSPU075", e);
134:                }
135:                return false;
136:            }
137:        }
138:
139:        /*
140:         * Watch dog thread, Pings the server to find whether the server is back online
141:         */
142:
143:        class watch_unavailable extends Thread {
144:
145:            private String wu_server;
146:
147:            private int wu_retry;
148:
149:            private URL wu_url;
150:
151:            private String proxyHost;
152:
153:            private int proxyPort;
154:
155:            private String proxyPassword;
156:
157:            private String proxyUser;
158:
159:            private int hostType;
160:
161:            // static Logger logger = Logger.getLogger("com.sun.portal.sra.rproxy");
162:            private static Logger logger = PortalLogger
163:                    .getLogger(watch_unavailable.class);
164:
165:            public watch_unavailable(String server, int rt, String proxyHost,
166:                    int proxyPort, String proxyUser, String proxyPasswd,
167:                    int hostType) {
168:                try {
169:                    wu_url = new URL(server);
170:                    wu_server = wu_url.getHost();// server;
171:                    wu_retry = rt;
172:                    this .proxyHost = proxyHost;
173:                    this .proxyPort = proxyPort;
174:                    this .hostType = hostType;
175:                } catch (MalformedURLException e) {
176:                    // logger.severe("watch_unavailable exception: " + e);
177:                    logger.log(Level.SEVERE, "PSSR_CSPU076", e);
178:                }
179:            }
180:
181:            public void run() {
182:
183:                boolean server_not_working = true;
184:
185:                while (server_not_working) {
186:                    try {
187:                        sleep(wu_retry * 1000); // try again wu_retry seconds later
188:                    } catch (InterruptedException exception) {
189:                    }
190:
191:                    try {
192:                        PingServiceRequest psr = null;
193:
194:                        if (proxyHost == null) {
195:                            psr = new PingServiceRequest(wu_url);
196:                        } else {
197:                            if (proxyPassword == null) {
198:                                psr = new PingServiceRequest(wu_url, proxyHost,
199:                                        proxyPort);
200:                            } else {
201:                                psr = new PingServiceRequest(wu_url, proxyHost,
202:                                        proxyPort, proxyUser, proxyPassword);
203:                            }
204:                        }
205:                        boolean isAlive = psr.isServiceAlive();
206:                        if (isAlive) {
207:                            HostAvailabilityEventImpl event = new HostAvailabilityEventImpl();
208:                            event.setHost(wu_url.toString());
209:                            event
210:                                    .setHostStatus(HostAvailabilityEvent.HOST_AVAILABLE);
211:                            event.setHostType(hostType);
212:                            HostAvailabilityMediator
213:                                    .getHostAvailabilityMediator()
214:                                    .notifyListeners(event);
215:                            server_not_working = false; // quit watching
216:                        }
217:                    } catch (Exception e) {
218:                        // Should not reach here as only hosts with valid proxy are
219:                        // being watched
220:                        // logger.log(Level.SEVERE, "Service Watch dog error", e);
221:                        logger.log(Level.SEVERE, "PSSR_CSPU077", e);
222:                    }
223:                }
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.