Author: dblevins
Date: Tue Jul 10 12:18:15 2007
New Revision: 555049
URL: http://svn.apache.org/viewvc?view=rev&rev=555049
Log:
Majorly cleaned up exception handling around server that cannot be contacted
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java?view=diff&rev=555049&r1=555048&r2=555049
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
(original)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
Tue Jul 10 12:18:15 2007
@@ -59,9 +59,13 @@
try {
conn = ConnectionManager.getConnection(uri);
} catch (IOException e) {
- logger.log(Level.WARNING, "Cannot access server(s): " +
uri.getHost() + ":" + uri.getPort() + " Exception: ", e);
+ if (uris.length == 1){
+ throw new RemoteException("Cannot connect to server
'"+uri+'"', e);
+ } else {
+ logger.log(Level.WARNING, "Cannot connect to
server(s): " + uri.getHost() + ":" + uri.getPort() + " Exception: ", e);
+ }
} catch (Throwable e) {
- throw new RemoteException("Cannot access server: " +
uri.getHost() + ":" + uri.getPort() + " due to an unkown exception in the
OpenEJB client: ", e);
+ throw new RemoteException("Cannot connect to server: " +
uri.getHost() + ":" + uri.getPort() + " due to an unkown exception in the
OpenEJB client: ", e);
}
}
@@ -72,7 +76,7 @@
URI uri = uris[i];
buffer.append((i != 0 ? ", " : "") + "Server #" + i + ": "
+ uri);
}
- throw new RemoteException("Cannot access servers: " +
buffer.toString());
+ throw new RemoteException("Cannot connect to any servers: " +
buffer.toString());
}
/*----------------------------------*/
@@ -165,6 +169,8 @@
throw new RemoteException("Error reading response from server:
", e);
}
+ } catch (RemoteException e) {
+ throw e;
} catch (Throwable error) {
throw new RemoteException("Error while communicating with server:
", error);
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java?view=diff&rev=555049&r1=555048&r2=555049
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
(original)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
Tue Jul 10 12:18:15 2007
@@ -21,6 +21,7 @@
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.ConnectException;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Properties;
@@ -35,6 +36,7 @@
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.OperationNotSupportedException;
+import javax.naming.ServiceUnavailableException;
import javax.naming.spi.InitialContextFactory;
import javax.sql.DataSource;
@@ -194,7 +196,11 @@
try {
res = request(req);
} catch (Exception e) {
- throw (NamingException) new NamingException("Cannot lookup " +
name + ": Received error: " + e.getMessage()).initCause(e);
+ if (e instanceof RemoteException && e.getCause() instanceof
ConnectException) {
+ e = (Exception) e.getCause();
+ throw (ServiceUnavailableException) new
ServiceUnavailableException("Cannot lookup '" + name + "'.").initCause(e);
+ }
+ throw (NamingException) new NamingException("Cannot lookup '" +
name + "'.").initCause(e);
}
switch (res.getResponseCode()) {
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java?view=diff&rev=555049&r1=555048&r2=555049
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
(original)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java
Tue Jul 10 12:18:15 2007
@@ -22,6 +22,7 @@
import java.io.StreamCorruptedException;
import java.net.Socket;
import java.net.URI;
+import java.net.ConnectException;
import java.util.Properties;
public class SocketConnectionFactory implements ConnectionFactory {
@@ -50,14 +51,17 @@
try {
socket = new Socket(uri.getHost(), uri.getPort());
socket.setTcpNoDelay(true);
+ } catch (ConnectException e) {
+ throw new ConnectException("Cannot connect to server
'"+uri.toString()+"'. Check that the server is started and that the specified
serverURL is correct.");
+
} catch (IOException e) {
- throw new IOException("Cannot access server: " + uri.getHost()
+ ":" + uri.getPort() + " Exception: " + e.getClass().getName() + " : " +
e.getMessage());
+ throw new IOException("Cannot connect to server:
'"+uri.toString()+"'. Exception: " + e.getClass().getName() + " : " +
e.getMessage());
} catch (SecurityException e) {
- throw new IOException("Cannot access server: " + uri.getHost()
+ ":" + uri.getPort() + " due to security restrictions in the current VM: " +
e.getClass().getName() + " : " + e.getMessage());
+ throw new IOException("Cannot access server:
'"+uri.toString()+"' due to security restrictions in the current VM: " +
e.getClass().getName() + " : " + e.getMessage());
} catch (Throwable e) {
- throw new IOException("Cannot access server: " + uri.getHost()
+ ":" + uri.getPort() + " due to an unkown exception in the OpenEJB client: " +
e.getClass().getName() + " : " + e.getMessage());
+ throw new IOException("Cannot connect to server:
'"+uri.toString()+"' due to an unkown exception in the OpenEJB client: " +
e.getClass().getName() + " : " + e.getMessage());
}
}