diff options
author | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-09 17:03:26 +0000 |
---|---|---|
committer | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-09 17:03:26 +0000 |
commit | 984309aa9c161d2ffa6c225b1920879bf987a661 (patch) | |
tree | fa3436d453e82ec39f73b7b70966322867ea2077 /sca-java-2.x/trunk/modules | |
parent | e38a71f2d547ec97a9f2456a042b00f1b979be60 (diff) |
Restructure the handling of callback destination in CallbackDestinationInterceptor to deal with Async service invocation as well as true Callback interfaces - as in TUSCANY-3809
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1044038 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
-rw-r--r-- | sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java | 83 |
1 files changed, 48 insertions, 35 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java index 0678f1edaa..290ce77e5d 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java @@ -36,6 +36,10 @@ import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +/** + * JMS Binding Interceptor class that deals with a callback destination address on the service side + * + */ public class CallbackDestinationInterceptor implements Interceptor { private Invoker next; private RuntimeComponentService service; @@ -59,51 +63,60 @@ public class CallbackDestinationInterceptor implements Interceptor { return next.invoke(invokeRequest(msg)); } + /** + * Handle an invocation request messaage + * @param msg the message + * @return the updated message + */ public Message invokeRequest(Message msg) { try { // get the jms context JMSBindingContext context = msg.getBindingContext(); - javax.jms.Message jmsMsg = context.getJmsMsg(); + javax.jms.Message jmsMsg = context.getJmsMsg(); + + // Extract the Callback destination name header, if present + String callbackdestName = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY); - - if (service.getInterfaceContract().getCallbackInterface() != null) { - - String callbackdestName = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY); - if (( callbackdestName == null) && ( jmsMsg.getJMSReplyTo() != null ) && msg.getOperation().isNonBlocking() ) { - Destination replyTo = jmsMsg.getJMSReplyTo(); - if (replyTo != null) { - callbackdestName = (replyTo instanceof Queue) ? ((Queue) replyTo).getQueueName() : ((Topic) replyTo).getTopicName(); - } + if (callbackdestName != null) { + // If present, strip any leading "jms:jndi:" string + if (!callbackdestName.startsWith("jms:jndi:")) { + throw new JMSBindingException("message property " + JMSBindingConstants.CALLBACK_Q_PROPERTY + " does not start with 'jms:jndi:' found: " + callbackdestName); } else { - if (callbackdestName != null) { - if (!callbackdestName.startsWith("jms:jndi:")) { - throw new JMSBindingException("message property " + JMSBindingConstants.CALLBACK_Q_PROPERTY + " does not start with 'jms:jndi:' found: " + callbackdestName); - } else { - callbackdestName = callbackdestName.substring(9); - } - } - } + callbackdestName = callbackdestName.substring(9); + } // end if + } else { + // If there is no Callback destination name header present, but the service is a callback, use the JMS ReplyTo header + if (service.getInterfaceContract().getCallbackInterface() != null) { + if ( ( jmsMsg.getJMSReplyTo() != null ) && msg.getOperation().isNonBlocking() ) { + Destination replyTo = jmsMsg.getJMSReplyTo(); + if (replyTo != null) { + callbackdestName = (replyTo instanceof Queue) ? ((Queue) replyTo).getQueueName() : ((Topic) replyTo).getTopicName(); + } + } // end if + } // end if + } // end if - if (callbackdestName != null) { - List<EndpointReference> refs = endpoint.getCallbackEndpointReferences(); - for (EndpointReference ref : refs ) { - if (ref.getBinding() instanceof JMSBinding ) { - JMSBinding callbackBinding = (JMSBinding) ref.getBinding(); - callbackBinding.setDestinationName(callbackdestName); - } - } - } + // Place the Callback destination name into the Callback EPRs for the service endpoint + if (callbackdestName != null) { + List<EndpointReference> refs = endpoint.getCallbackEndpointReferences(); + for (EndpointReference ref : refs ) { + if (ref.getBinding() instanceof JMSBinding ) { + JMSBinding callbackBinding = (JMSBinding) ref.getBinding(); + callbackBinding.setDestinationName(callbackdestName); + } // end if + } // end for + } // end if - String callbackID = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_ID_PROPERTY); - if (callbackID != null) { -// parameters.setCallbackID(callbackID); - } - } +// Callback ID not used at present +// String callbackID = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_ID_PROPERTY); +// if (callbackID != null) { +// parameters.setCallbackID(callbackID); +// } } catch (JMSException e) { throw new JMSBindingException(e); - } + } // end try return msg; - } -}
\ No newline at end of file + } // end method invokeRequest +} // end class
\ No newline at end of file |