public org.apache.tuscany.sca.invocation.Message invoke(org.apache.tuscany.sca.invocation.Message tuscanyMsg) {
try {
// populate the message context with JMS binding information
JMSBindingContext context = new JMSBindingContext();
context.setJmsResourceFactory(jmsResourceFactory);
tuscanyMsg.setBindingContext(context);
// get a jms session to cover the creation and sending of the message
Session session = context.getJmsSession();
context.setRequestDestination(getRequestDestination(tuscanyMsg, session));
context.setReplyToDestination(getReplyToDestination(session));
try {
tuscanyMsg = endpointReference.getBindingInvocationChain().getHeadInvoker().invoke(tuscanyMsg);
} catch (ServiceRuntimeException e) {
if (e.getCause() instanceof InvocationTargetException) {
if ((e.getCause().getCause() instanceof RuntimeException)) {
tuscanyMsg.setFaultBody(e.getCause());
} else {
tuscanyMsg.setFaultBody(((InvocationTargetException)e.getCause()).getTargetException());
}
} else if (e.getCause() instanceof FaultException) {
tuscanyMsg.setFaultBody(e.getCause());
} else {
tuscanyMsg.setFaultBody(e);
}
} catch (IllegalStateException e) {
tuscanyMsg.setFaultBody(e);
} catch (Throwable e) {
tuscanyMsg.setFaultBody(e);
} finally {
context.closeJmsSession();
if (jmsResourceFactory.isConnectionClosedAfterUse()) {
jmsResourceFactory.closeConnection();
}
}