01: /**
02: * $Id: CheckPort.java,v 1.12 2005/11/30 11:26:32 ss150821 Exp $
03: * Copyright 2002 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.netfile.servlet.java1;
14:
15: import java.net.*;
16: import com.sun.portal.log.common.PortalLogger;
17: import java.util.logging.*;
18:
19: class CheckPort {
20:
21: private static Logger logger = PortalLogger
22: .getLogger(CheckPort.class);
23:
24: CheckPort() {
25: }
26:
27: int checkTcpPort(String host, int port) {
28: Socket sock = null;
29:
30: try {
31: //Connect to hostname,port
32: sock = new Socket(host, port);
33: sock.close();
34: sock = null;
35: } catch (java.net.ConnectException ce) {
36: // logger.severe("Could not connect to " + host + " on port " + port);
37: Object[] params0 = { host, " on port ", new Integer(port) };
38: logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1052", params0);
39: return 0;
40: } catch (java.net.NoRouteToHostException nre) {
41: // logger.severe("Could not route to " + host + " and port " + port);
42: Object[] params1 = { host, " and port ", new Integer(port) };
43: logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1053", params1);
44: return 0;
45: } catch (Exception e) {
46: // logger.log(Level.SEVERE, "Exception in connecting to " + host + " on port " + port, e);
47: Object[] params2 = { host, " on port ", new Integer(port),
48: e };
49: logger.log(Level.SEVERE, "PSSRNF_CSPNSJ1054", params2);
50: return -1;
51: } finally {
52: try {
53: if (sock != null) {
54: sock.close();
55: sock = null;
56: }
57: } catch (Exception ee) {
58: }
59: }
60:
61: return 1;
62: }
63: }
|