admin@glassfish.java.net

code-review ...

From: Kedar Mhaswade <Kedar.Mhaswade_at_Sun.COM>
Date: Fri, 22 Dec 2006 14:07:31 -0800

When asadmin fails to connect to admin server, it
does not clearly indicate in the message what server
and port it tried to connect. This confuses the users.

Attached code changes attempt to display a little
better message.

Can someone review? Timeout: 4.00 PM PDT - Friday, 22 Dec. 2006.

Thanks,
Kedar

(Please judge with respect to current state of the code).


Index: ServletConnection.java
===================================================================
RCS file: /cvs/glassfish/jmx-remote/rjmx-impl/src/java/com/sun/enterprise/admin/jmx/remote/comm/ServletConnection.java,v
retrieving revision 1.4
diff -u -r1.4 ServletConnection.java
--- ServletConnection.java 25 Dec 2005 04:26:31 -0000 1.4
+++ ServletConnection.java 22 Dec 2006 22:00:48 -0000
@@ -63,13 +63,13 @@
 
 class ServletConnection implements IConnection, Runnable {
         static final String UNKNOWN_HOST = "Unknown host : ";
- static final String INVALID_HOST_PORT = "Unable to connect to admin-server. Please check if the server is up and running and that the host and port provided are correct.";
         static final String UNAUTHORIZED_ACCESS =
         "Invalid user or password";
         
         private URLConnection mConnection = null;
         private ObjectOutputStream mObjectOutStream = null;
         private ObjectInputStream mObjectInStream = null;
+ private HttpConnectorAddress hca;
         
 /* BEGIN -- S1WS_MOD */
     private static final Logger logger = Logger.getLogger(
@@ -90,6 +90,7 @@
                 uri = DefaultConfiguration.DEFAULT_SERVLET_CONTEXT_ROOT;
                         mConnection = a.openConnection(uri);
 /* END -- S1WS_MOD */
+ this.hca = a;
                 }
                 catch (IOException ioe){
                         handleException(ioe);
@@ -212,7 +213,7 @@
                         e.getMessage());
                 }
                 else if (e instanceof java.net.ConnectException) {
- exception = new java.net.ConnectException(INVALID_HOST_PORT);
+ exception = new java.net.ConnectException(createConnectExceptionMessage());
                 }
                 else {
                         int responseCode =
@@ -226,4 +227,15 @@
                 }
                 throw exception;
         }
+
+ private String createConnectExceptionMessage() {
+ /* this is not internationalized yet -- this is because there is a
+ separate delivery of this code that cannot depend on other parts
+ of application server
+ */
+ final String h = hca.getHost();
+ final int p = hca.getPort();
+ final String msg = "Unable to connect to admin-server at given host: " + h + " and port: " + p + ".\nPlease check if this server is up and running and that the host and port provided are correct.";
+ return ( msg );
+ }
 }