logger.fine("no response session to create fault message: " + String.valueOf(o));
return null;
}
try {
ObjectMessage message = session.createObjectMessage();
if (o instanceof RuntimeException || o instanceof Error) {
int recursionKlugeDetector = 20;
Throwable rootCause = o;
Throwable deepRootCause = rootCause.getCause();
do {
if (rootCause == deepRootCause) {
break;
} else if (deepRootCause != null) {
rootCause = deepRootCause;
}
if (recursionKlugeDetector-- <= 0) {
break;
}
} while (deepRootCause != null);
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
pw.print("Message = " + o.getMessage());
StackTraceElement[] stackElements = o.getStackTrace();
for (int i = 0; i < stackElements.length; i++) {
pw.print("\t>> \t at ");
pw.println(stackElements[i].toString());
}
pw.flush();
message.setObject(new RuntimeException( sw.toString() ));
} else {
message.setObject(o);
}
message.setBooleanProperty(JMSBindingConstants.FAULT_PROPERTY, true);
return message;
} catch (JMSException e) {
throw new JMSBindingException(e);
}