Package org.jboss.arquillian.test.spi
Class ExceptionProxy
java.lang.Object
org.jboss.arquillian.test.spi.ExceptionProxy
- All Implemented Interfaces:
Externalizable,Serializable
Takes an exception class and creates a proxy that can be used to rebuild the
exception. The problem stems from problems serializing exceptions and
deserializing them in another application where the exception classes might
not exist, or they might exist in different version. This proxy also
propagates the stacktrace and the cause exception to create totally portable
exceptions. This class creates a serializable proxy of the exception and
when unserialized can be used to re-create the exception based on the
following rules :
- If the exception class exists on the client, the original exception is created
- If the exception class exists, but doesn't have a suitable constructor then another exception is thrown referencing the original exception
- If the exception class doesn't exist, one of its superclasses is used
- Author:
- Andy Gibson
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ThrowableBuild the original exception based on the exception class name.Constructs an instance of the proxied exception based on the class name, message, stack trace and if applicable, and the cause if the cause could be deserialized in the client.static ExceptionProxycreateForException(Throwable throwable) Static method to create an exception proxy for the passed inThrowableclass.createProxyException(String reason) getCause()Returns the cause of the exception represented by this proxyGet the exception hierarchy for the exception class being proxied.getTrace()booleanIndicates whether this proxy wraps an exceptionvoidCustom Serialization logic.toString()Override to provide the full details of the exception being proxiedvoid
-
Constructor Details
-
ExceptionProxy
public ExceptionProxy() -
ExceptionProxy
-
-
Method Details
-
createForException
Static method to create an exception proxy for the passed inThrowableclass. If null is passed in, null is returned as the exception proxy- Parameters:
throwable- Exception to proxy- Returns:
- An ExceptionProxy representing the exception passed in
-
hasException
public boolean hasException()Indicates whether this proxy wraps an exception- Returns:
- Flag indicating an exception is wrapped.
-
createException
Constructs an instance of the proxied exception based on the class name, message, stack trace and if applicable, and the cause if the cause could be deserialized in the client. Otherwise, this returns an ArquillianProxyException- Returns:
- The constructed
Throwableinstance if one exists, null otherwise
-
createProxyException
-
getCause
Returns the cause of the exception represented by this proxy- Returns:
- The cause of this exception
-
getClassName
-
getMessage
-
getTrace
-
getCauseProxy
-
getOriginal
-
getSerializationProcessException
-
getVersion
-
getExceptionHierarchy
-
toString
Override to provide the full details of the exception being proxied -
readExternal
Custom Serialization logic.If possible, we try to keep the original Exception form the Container side.
If we can't load the Exception on the client side, return a ArquillianProxyException that keeps the original stack trace etc.
We can't use in.readObject() on the Throwable cause, because if a ClassNotFoundException is thrown, the stream is marked with the exception and that stream is the same stream that is deserializing us, so we will fail outside of our control. Store the Throwable cause as a serialized byte array instead, so we can deserialize it outside of our own stream.
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
getExceptionHierarchy
Get the exception hierarchy for the exception class being proxied.- Returns:
- list of exception types in the hierarchy
-
buildOriginalException
Build the original exception based on the exception class name. This first tries to use a ctor with a message, then a default ctor.- Returns:
- the original exception
-