提交 69c76227 编写于 作者: S smarks

8019224: add exception chaining to RMI CGIHandler

Reviewed-by: darcy
上级 897358ee
...@@ -38,6 +38,10 @@ class CGIClientException extends Exception { ...@@ -38,6 +38,10 @@ class CGIClientException extends Exception {
public CGIClientException(String s) { public CGIClientException(String s) {
super(s); super(s);
} }
public CGIClientException(String s, Throwable cause) {
super(s, cause);
}
} }
/** /**
...@@ -50,6 +54,10 @@ class CGIServerException extends Exception { ...@@ -50,6 +54,10 @@ class CGIServerException extends Exception {
public CGIServerException(String s) { public CGIServerException(String s) {
super(s); super(s);
} }
public CGIServerException(String s, Throwable cause) {
super(s, cause);
}
} }
/** /**
...@@ -148,13 +156,16 @@ public final class CGIHandler { ...@@ -148,13 +156,16 @@ public final class CGIHandler {
try { try {
handler.execute(param); handler.execute(param);
} catch (CGIClientException e) { } catch (CGIClientException e) {
e.printStackTrace();
returnClientError(e.getMessage()); returnClientError(e.getMessage());
} catch (CGIServerException e) { } catch (CGIServerException e) {
e.printStackTrace();
returnServerError(e.getMessage()); returnServerError(e.getMessage());
} }
else else
returnClientError("invalid command."); returnClientError("invalid command.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
returnServerError("internal error: " + e.getMessage()); returnServerError("internal error: " + e.getMessage());
} }
System.exit(0); System.exit(0);
...@@ -225,7 +236,7 @@ final class CGIForwardCommand implements CGICommandHandler { ...@@ -225,7 +236,7 @@ final class CGIForwardCommand implements CGICommandHandler {
try { try {
port = Integer.parseInt(param); port = Integer.parseInt(param);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new CGIClientException("invalid port number."); throw new CGIClientException("invalid port number.", e);
} }
if (port <= 0 || port > 0xFFFF) if (port <= 0 || port > 0xFFFF)
throw new CGIClientException("invalid port: " + port); throw new CGIClientException("invalid port: " + port);
...@@ -238,7 +249,7 @@ final class CGIForwardCommand implements CGICommandHandler { ...@@ -238,7 +249,7 @@ final class CGIForwardCommand implements CGICommandHandler {
try { try {
socket = new Socket(InetAddress.getLocalHost(), port); socket = new Socket(InetAddress.getLocalHost(), port);
} catch (IOException e) { } 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 @@ final class CGIForwardCommand implements CGICommandHandler { ...@@ -249,9 +260,9 @@ final class CGIForwardCommand implements CGICommandHandler {
try { try {
clientIn.readFully(buffer); clientIn.readFully(buffer);
} catch (EOFException e) { } catch (EOFException e) {
throw new CGIClientException("unexpected EOF reading request body"); throw new CGIClientException("unexpected EOF reading request body", e);
} catch (IOException e) { } catch (IOException e) {
throw new CGIClientException("error reading request body"); throw new CGIClientException("error reading request body", e);
} }
/* /*
...@@ -266,7 +277,7 @@ final class CGIForwardCommand implements CGICommandHandler { ...@@ -266,7 +277,7 @@ final class CGIForwardCommand implements CGICommandHandler {
socketOut.write(buffer); socketOut.write(buffer);
socketOut.flush(); socketOut.flush();
} catch (IOException e) { } catch (IOException e) {
throw new CGIServerException("error writing to server"); throw new CGIServerException("error writing to server", e);
} }
/* /*
...@@ -276,7 +287,7 @@ final class CGIForwardCommand implements CGICommandHandler { ...@@ -276,7 +287,7 @@ final class CGIForwardCommand implements CGICommandHandler {
try { try {
socketIn = new DataInputStream(socket.getInputStream()); socketIn = new DataInputStream(socket.getInputStream());
} catch (IOException e) { } catch (IOException e) {
throw new CGIServerException("error reading from server"); throw new CGIServerException("error reading from server", e);
} }
String key = "Content-length:".toLowerCase(); String key = "Content-length:".toLowerCase();
boolean contentLengthFound = false; boolean contentLengthFound = false;
...@@ -286,7 +297,7 @@ final class CGIForwardCommand implements CGICommandHandler { ...@@ -286,7 +297,7 @@ final class CGIForwardCommand implements CGICommandHandler {
try { try {
line = getLine(socketIn); line = getLine(socketIn);
} catch (IOException e) { } catch (IOException e) {
throw new CGIServerException("error reading from server"); throw new CGIServerException("error reading from server", e);
} }
if (line == null) if (line == null)
throw new CGIServerException( throw new CGIServerException(
...@@ -313,9 +324,9 @@ final class CGIForwardCommand implements CGICommandHandler { ...@@ -313,9 +324,9 @@ final class CGIForwardCommand implements CGICommandHandler {
socketIn.readFully(buffer); socketIn.readFully(buffer);
} catch (EOFException e) { } catch (EOFException e) {
throw new CGIServerException( throw new CGIServerException(
"unexpected EOF reading server response"); "unexpected EOF reading server response", e);
} catch (IOException e) { } catch (IOException e) {
throw new CGIServerException("error reading from server"); throw new CGIServerException("error reading from server", e);
} }
/* /*
...@@ -327,7 +338,7 @@ final class CGIForwardCommand implements CGICommandHandler { ...@@ -327,7 +338,7 @@ final class CGIForwardCommand implements CGICommandHandler {
try { try {
System.out.write(buffer); System.out.write(buffer);
} catch (IOException e) { } catch (IOException e) {
throw new CGIServerException("error writing response"); throw new CGIServerException("error writing response", e);
} }
System.out.flush(); System.out.flush();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册