1
|
|
/* Generated by AspectJ version 1.0.5 */
|
2
|
|
package org.apache.cactus.client;
|
3
|
|
import java.io.PrintStream;
|
4
|
|
import java.io.PrintWriter;
|
5
|
|
|
6
|
|
/**
|
7
|
|
* Wrapper around a <code>Throwable</code> object. Whenever an exception occurs
|
8
|
|
* in a test case executed on the server side, the text of this exception
|
9
|
|
* along with the stack trace as a String are sent back in the HTTP response.
|
10
|
|
* This is because some exceptions are not serializable and because the stack
|
11
|
|
* trace is implemented as a <code>transient</code> variable by the JDK so it
|
12
|
|
* cannot be transported in the response. However, we need to send a real
|
13
|
|
* exception object to JUnit so that the exception stack trace will be printed
|
14
|
|
* in the JUnit console. This class does this by being a <code>Throwable</code>
|
15
|
|
* and overloading the <code>printStackTrace()</code> methods to print a
|
16
|
|
* text stack trace.
|
17
|
|
*
|
18
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
19
|
|
*
|
20
|
|
* @version $Id: ServletExceptionWrapper.java,v 1.1 2002/03/01 00:43:46 vmassol Exp $
|
21
|
|
*/
|
22
|
|
public class ServletExceptionWrapper extends Throwable {
|
23
|
|
/**
|
24
|
|
* The stack trace that was sent back from the servlet redirector as a
|
25
|
|
* string.
|
26
|
|
*/
|
27
|
|
private String stackTrace;
|
28
|
|
/**
|
29
|
|
* The class name of the exception that was raised on the server side.
|
30
|
|
*/
|
31
|
|
private String className;
|
32
|
|
/**
|
33
|
|
* Standard throwable constructor.
|
34
|
|
*
|
35
|
|
* @param theMessage the exception message
|
36
|
|
*/
|
37
|
0
|
public ServletExceptionWrapper(String theMessage) {
|
38
|
0
|
super(theMessage);
|
39
|
|
;
|
40
|
|
}
|
41
|
|
/**
|
42
|
|
* Standard throwable constructor.
|
43
|
|
*/
|
44
|
0
|
public ServletExceptionWrapper() {
|
45
|
0
|
super();
|
46
|
|
;
|
47
|
|
}
|
48
|
|
/**
|
49
|
|
* The constructor to use to simulate a real exception.
|
50
|
|
*
|
51
|
|
* @param theMessage the server exception message
|
52
|
|
* @param theClassName the server exception class name
|
53
|
|
* @param theStackTrace the server exception stack trace
|
54
|
|
*/
|
55
|
6
|
public ServletExceptionWrapper(String theMessage, String theClassName, String theStackTrace) {
|
56
|
6
|
super(theMessage);
|
57
|
|
;
|
58
|
6
|
this.className = theClassName;
|
59
|
6
|
this.stackTrace = theStackTrace;
|
60
|
|
}
|
61
|
|
/**
|
62
|
|
* Simulates a printing of a stack trace by printing the string stack trace
|
63
|
|
*
|
64
|
|
* @param thePs the stream to which to output the stack trace
|
65
|
|
*/
|
66
|
0
|
public void printStackTrace(PrintStream thePs) {
|
67
|
0
|
if (this.stackTrace == null) {
|
68
|
0
|
thePs.print(this.getMessage());
|
69
|
|
} else {
|
70
|
0
|
thePs.print(this.stackTrace);
|
71
|
|
}
|
72
|
|
}
|
73
|
|
|
74
|
|
/**
|
75
|
|
* Simulates a printing of a stack trace by printing the string stack trace
|
76
|
|
*
|
77
|
|
* @param thePw the writer to which to output the stack trace
|
78
|
|
*/
|
79
|
0
|
public void printStackTrace(PrintWriter thePw) {
|
80
|
0
|
if (this.stackTrace == null) {
|
81
|
0
|
thePw.print(this.getMessage());
|
82
|
|
} else {
|
83
|
0
|
thePw.print(this.stackTrace);
|
84
|
|
}
|
85
|
|
}
|
86
|
|
|
87
|
|
/**
|
88
|
|
* As all the server exceptions are wrapped into this
|
89
|
|
* <code>ServletExceptionWrapper</code> class, we need to be able to
|
90
|
|
* know the original server exception class.
|
91
|
|
*
|
92
|
|
* @param theClass the class to compare with the server exception class
|
93
|
|
* @return true if the class passed as parameter is an instance of
|
94
|
|
* <code>ServletExceptionWrapper</code> (this class)
|
95
|
|
*/
|
96
|
6
|
public boolean instanceOf(Class theClass) {
|
97
|
6
|
if (this.className == null) {
|
98
|
0
|
return false;
|
99
|
|
}
|
100
|
6
|
return theClass.getName().equals(this.className);
|
101
|
|
}
|
102
|
|
|
103
|
|
}
|