001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.util.ejb;
023:
024: import java.io.PrintStream;
025: import java.io.PrintWriter;
026: import java.io.StringWriter;
027:
028: /**
029: * RemoteTestException is the client-side view of a throwable on the server.
030: *
031: * All throwables caught on the server are wrapped with a RemoteTestException
032: * and rethrown. On the client side the exception is caught, and if the
033: * server side exception is an instance of AssertionFailedError, it is
034: * wrapped with a RemoteAssertionFailedError and rethrown. That makes the
035: * exception an instance of AssertionFailedError so it is reconized as
036: * a failure and not an Error.
037: *
038: * @author <a href="mailto:dain@daingroup.com">Dain Sundstrom</a>
039: * @version $Revision: 57211 $
040: */
041: public class RemoteTestException extends Exception {
042: private Throwable remoteThrowable;
043: private String remoteStackTrace;
044:
045: /**
046: * Constructs a remote test exception that wrapps the the specified
047: * throwable.
048: * @param e the Throwable that was thrown on the server side
049: */
050: public RemoteTestException(Throwable e) {
051: remoteThrowable = e;
052:
053: StringWriter stringWriter = new StringWriter();
054: PrintWriter writer = new PrintWriter(stringWriter);
055: e.printStackTrace(writer);
056: StringBuffer buffer = stringWriter.getBuffer();
057: remoteStackTrace = buffer.toString();
058: }
059:
060: /**
061: * Gets the message exactly as it appeared on server side.
062: * @return the message exactly as it appeared on server side
063: */
064: public String getMessage() {
065: return remoteThrowable.getMessage();
066: }
067:
068: /**
069: * Prints the stack trace exactly as it appeared on the server side.
070: * @param ps the PrintStream on which the stack trace is printed
071: */
072: public void printStackTrace(java.io.PrintStream ps) {
073: ps.print(remoteStackTrace);
074: }
075:
076: /**
077: * Prints the stack trace exactly as it appeared on the server side.
078: */
079: public void printStackTrace() {
080: printStackTrace(System.err);
081: }
082:
083: /**
084: * Prints the stack trace exactly as it appeared on the server side.
085: * @param pw the PrintWriter on which the stack trace is printed
086: */
087: public void printStackTrace(java.io.PrintWriter pw) {
088: pw.print(remoteStackTrace);
089: }
090:
091: /**
092: * Gets the throwable object from the server side.
093: * Note: the stack trace of this object is not available because
094: * exceptions don't seralize the stack trace. Use
095: * getRemoteStackTrace to get the stack trace as it appeared
096: * on the server.
097: * @return the Throwable object from the server side.
098: */
099: public Throwable getRemoteThrowable() {
100: return remoteThrowable;
101: }
102:
103: /**
104: * Gets the stack trace exactly as it appeared on the server side.
105: * @return the stack trace exactly as it appeared on the server side
106: */
107: public String getRemoteStackTrace() {
108: return remoteStackTrace;
109: }
110: }
|