try {
Throwable wrapper = null;
if (!(t instanceof UimaEEServiceException)) {
// Strip off AsyncAEException and replace with UimaEEServiceException
if (t instanceof AsynchAEException && t.getCause() != null) {
wrapper = new UimaEEServiceException(t.getCause());
} else {
wrapper = new UimaEEServiceException(t);
}
}
if (aborting) {
return;
}
anEndpoint.setReplyEndpoint(true);
JmsEndpointConnection_impl endpointConnection = getEndpointConnection(anEndpoint);
// Create Message that will contain serialized Exception with stack
ObjectMessage om = endpointConnection.produceObjectMessage();
// Now try to catch non-serializable exception. The Throwable passed into this method may
// not be serializable. Catch the exception, and create a wrapper containing stringified
// stack trace.
try {
// serialize the Throwable
if (wrapper == null) {
om.setObject(t);
} else {
om.setObject(wrapper);
}
} catch( RuntimeException e) {
// Check if we failed due to non-serializable object in the Throwable
if ( e.getCause() != null && e.getCause() instanceof NotSerializableException ) {
// stringify the stack trace
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
wrapper = new UimaEEServiceException(sw.toString());
// serialize the new wrapper
om.setObject(wrapper);
} else {
throw e; // rethrow
}