8019224: add exception chaining to RMI CGIHandler
authorsmarks
Thu, 27 Jun 2013 13:35:01 -0700
changeset 18566 6a998d63b405
parent 18565 5025d43d3731
child 18567 35b36d452864
8019224: add exception chaining to RMI CGIHandler Reviewed-by: darcy
jdk/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java
--- a/jdk/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java	Thu Jun 27 12:24:26 2013 -0700
+++ b/jdk/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java	Thu Jun 27 13:35:01 2013 -0700
@@ -38,6 +38,10 @@
     public CGIClientException(String s) {
         super(s);
     }
+
+    public CGIClientException(String s, Throwable cause) {
+        super(s, cause);
+    }
 }
 
 /**
@@ -50,6 +54,10 @@
     public CGIServerException(String s) {
         super(s);
     }
+
+    public CGIServerException(String s, Throwable cause) {
+        super(s, cause);
+    }
 }
 
 /**
@@ -148,13 +156,16 @@
                 try {
                     handler.execute(param);
                 } catch (CGIClientException e) {
+                    e.printStackTrace();
                     returnClientError(e.getMessage());
                 } catch (CGIServerException e) {
+                    e.printStackTrace();
                     returnServerError(e.getMessage());
                 }
             else
                 returnClientError("invalid command.");
         } catch (Exception e) {
+            e.printStackTrace();
             returnServerError("internal error: " + e.getMessage());
         }
         System.exit(0);
@@ -225,7 +236,7 @@
         try {
             port = Integer.parseInt(param);
         } catch (NumberFormatException e) {
-            throw new CGIClientException("invalid port number.");
+            throw new CGIClientException("invalid port number.", e);
         }
         if (port <= 0 || port > 0xFFFF)
             throw new CGIClientException("invalid port: " + port);
@@ -238,7 +249,7 @@
         try {
             socket = new Socket(InetAddress.getLocalHost(), port);
         } catch (IOException e) {
-            throw new CGIServerException("could not connect to local port");
+            throw new CGIServerException("could not connect to local port", e);
         }
 
         /*
@@ -249,9 +260,9 @@
         try {
             clientIn.readFully(buffer);
         } catch (EOFException e) {
-            throw new CGIClientException("unexpected EOF reading request body");
+            throw new CGIClientException("unexpected EOF reading request body", e);
         } catch (IOException e) {
-            throw new CGIClientException("error reading request body");
+            throw new CGIClientException("error reading request body", e);
         }
 
         /*
@@ -266,7 +277,7 @@
             socketOut.write(buffer);
             socketOut.flush();
         } catch (IOException e) {
-            throw new CGIServerException("error writing to server");
+            throw new CGIServerException("error writing to server", e);
         }
 
         /*
@@ -276,7 +287,7 @@
         try {
             socketIn = new DataInputStream(socket.getInputStream());
         } catch (IOException e) {
-            throw new CGIServerException("error reading from server");
+            throw new CGIServerException("error reading from server", e);
         }
         String key = "Content-length:".toLowerCase();
         boolean contentLengthFound = false;
@@ -286,7 +297,7 @@
             try {
                 line = getLine(socketIn);
             } catch (IOException e) {
-                throw new CGIServerException("error reading from server");
+                throw new CGIServerException("error reading from server", e);
             }
             if (line == null)
                 throw new CGIServerException(
@@ -313,9 +324,9 @@
             socketIn.readFully(buffer);
         } catch (EOFException e) {
             throw new CGIServerException(
-                "unexpected EOF reading server response");
+                "unexpected EOF reading server response", e);
         } catch (IOException e) {
-            throw new CGIServerException("error reading from server");
+            throw new CGIServerException("error reading from server", e);
         }
 
         /*
@@ -327,7 +338,7 @@
         try {
             System.out.write(buffer);
         } catch (IOException e) {
-            throw new CGIServerException("error writing response");
+            throw new CGIServerException("error writing response", e);
         }
         System.out.flush();
     }