You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ed...@apache.org on 2010/12/09 18:03:27 UTC
svn commit: r1044038 -
/tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java
Author: edwardsmj
Date: Thu Dec 9 17:03:26 2010
New Revision: 1044038
URL: http://svn.apache.org/viewvc?rev=1044038&view=rev
Log:
Restructure the handling of callback destination in CallbackDestinationInterceptor to deal with Async service invocation as well as true Callback interfaces - as in TUSCANY-3809
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java
Modified: tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java?rev=1044038&r1=1044037&r2=1044038&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/CallbackDestinationInterceptor.java Thu Dec 9 17:03:26 2010
@@ -36,6 +36,10 @@ import org.apache.tuscany.sca.invocation
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 CallbackDestinationIntercep
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);
- }
- }
- }
-
- String callbackID = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_ID_PROPERTY);
- if (callbackID != null) {
-// parameters.setCallbackID(callbackID);
- }
- }
+ // 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
+
+// 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