diff options
author | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-20 19:36:27 +0000 |
---|---|---|
committer | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-20 19:36:27 +0000 |
commit | 1f91615143cc34ad7eeffc7d91b6ffec9d7d0271 (patch) | |
tree | 1b32deaa200d9c9d1ede5d5451c9ed33d3d74a20 /sca-java-2.x/trunk/modules/binding-jms-runtime/src | |
parent | d7ebda787739f6e362f958250887961946a92f02 (diff) |
Extending binding-jms-runtime to provide native async service invocation with separate forward request messages and back response messages - as described in TUSCANY-3809
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1051255 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-jms-runtime/src')
28 files changed, 1150 insertions, 103 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java index ad07655730..87c6ddd08b 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderReferenceInterceptor.java @@ -18,9 +18,7 @@ */ package org.apache.tuscany.sca.binding.jms.headers; - - - +import java.util.List; import java.util.Map; import java.util.UUID; @@ -38,6 +36,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessor; import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -49,31 +48,30 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; * * @version $Rev$ $Date$ */ -public class HeaderReferenceInterceptor implements Interceptor { +public class HeaderReferenceInterceptor extends InterceptorAsyncImpl { - private Invoker next; private RuntimeEndpointReference runtimeWire; private JMSBinding jmsBinding; private JMSMessageProcessor requestMessageProcessor; + private List<Operation> operations; - public HeaderReferenceInterceptor(ExtensionPointRegistry extensions, JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference runtimeWire) { + public HeaderReferenceInterceptor(ExtensionPointRegistry extensions, JMSBinding jmsBinding, + JMSResourceFactory jmsResourceFactory, RuntimeEndpointReference runtimeWire) { super(); this.jmsBinding = jmsBinding; this.runtimeWire = runtimeWire; - this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(extensions, jmsBinding); - - } + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(extensions, jmsBinding); + this.operations = runtimeWire.getReference().getInterfaceContract().getInterface().getOperations(); + } // end constructor public Message invoke(Message msg) { - return next.invoke(invokeRequest(msg)); - - } + } // end method invoke public Message invokeRequest(Message tuscanyMsg) { try { - // get the jms context + // Get the JMS context JMSBindingContext context = tuscanyMsg.getBindingContext(); javax.jms.Message jmsMsg = tuscanyMsg.getBody(); @@ -81,12 +79,10 @@ public class HeaderReferenceInterceptor implements Interceptor { String operationName = operation.getName(); RuntimeEndpointReference reference = runtimeWire; - // I think the OASIS spec suggests we do not need to do anything with + // OASIS spec suggests we do not need to do anything with // @nativeOperation here on the reference side. requestMessageProcessor.setOperationName(operationName, jmsMsg); - - - + if (jmsBinding.getEffectiveJMSDeliveryMode(operationName) != null) { if (jmsBinding.getEffectiveJMSDeliveryMode(operationName)) { jmsMsg.setJMSDeliveryMode(DeliveryMode.PERSISTENT); @@ -157,8 +153,7 @@ public class HeaderReferenceInterceptor implements Interceptor { } catch (NamingException e) { throw new JMSBindingException(e); } - } - + } // end method invokeRequest protected String getCallbackDestinationName(RuntimeEndpointReference reference) { RuntimeEndpoint endpoint = (RuntimeEndpoint) reference.getCallbackEndpoint(); @@ -169,14 +164,35 @@ public class HeaderReferenceInterceptor implements Interceptor { return null; } + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest - public Invoker getNext() { - return next; - } - - public void setNext(Invoker next) { - this.next = next; - } + public Message processResponse(Message msg) { + // When the response message arrives, there may be information about the + // operation and the related request message ID in the headers - extract it into the + // Tuscany message + + javax.jms.Message responseMsg = msg.getBody(); + try { + // Operation name... + String operationName = responseMsg.getStringProperty("scaOperationName"); + for( Operation op : operations ) { + if( operationName.equals(op.getName())) { + msg.setOperation(op); + break; + } // end if + } // end for + + // Relates to header... + String relatesTo = responseMsg.getStringProperty("RELATES_TO"); + if( relatesTo != null ) { + msg.getHeaders().put("RELATES_TO", relatesTo); + } // end if + } catch (JMSException e) { + // TODO Auto-generated catch block + } // end try + return msg; + } // end method processResponse - } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java index e899448760..6dac182d9a 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/headers/HeaderServiceInterceptor.java @@ -24,12 +24,13 @@ import javax.jms.JMSException; import org.apache.tuscany.sca.binding.jms.JMSBinding; import org.apache.tuscany.sca.binding.jms.JMSBindingException; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; -public class HeaderServiceInterceptor implements Interceptor { +public class HeaderServiceInterceptor extends InterceptorAsyncImpl { private Invoker next; private JMSBinding jmsBinding; @@ -75,30 +76,43 @@ public class HeaderServiceInterceptor implements Interceptor { for (String propName : jmsBinding.getPropertyNames()) { Object value = jmsBinding.getProperty(propName); jmsMsg.setObjectProperty(propName, value); - } + } // end for Map<String, Object> operationProperties = jmsBinding.getOperationProperties(operationName); if (operationProperties != null) { for (String propName : operationProperties.keySet()) { Object value = operationProperties.get(propName); jmsMsg.setObjectProperty(propName, value); - } - } + } // end for + } // end if + + // Put a "RELATES_TO" property into the response message + String relatesTo = (String)tuscanyMsg.getHeaders().get("RELATES_TO"); + if( relatesTo != null ) { + jmsMsg.setStringProperty("RELATES_TO", relatesTo); + } // end if return tuscanyMsg; } catch (JMSException e) { throw new JMSBindingException(e); - } - } + } // end try + } // end method invokeResponse public Invoker getNext() { return next; - } + } // end method getNext public void setNext(Invoker next) { this.next = next; } - - -} + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + +} // end class diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java new file mode 100644 index 0000000000..1aa316f81b --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/AsyncResponseJMSServiceListener.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.host; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.Topic; +import javax.naming.NamingException; +import javax.resource.spi.ActivationSpec; + +import org.apache.tuscany.sca.binding.jms.JMSBinding; +import org.apache.tuscany.sca.binding.jms.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * Implementation of a JMS response queue handler for async responses + * + * @version $Rev$ $Date$ + */ +public class AsyncResponseJMSServiceListener implements JMSServiceListener { + private static final Logger logger = Logger.getLogger(AsyncResponseJMSServiceListener.class.getName()); + + private MessageListener listener; + private String serviceName; + private JMSBinding jmsBinding; + private WorkScheduler workScheduler; + + private JMSResourceFactory jmsResourceFactory; + private MessageConsumer consumer; + private boolean running; + + private Destination destination; + + public AsyncResponseJMSServiceListener(MessageListener listener, String serviceName, + JMSBinding jmsBinding, WorkScheduler workScheduler, JMSResourceFactory rf) { + this.listener = listener; + this.serviceName = serviceName; + this.jmsBinding = jmsBinding; + this.workScheduler = workScheduler; + this.jmsResourceFactory = rf; + } + + public void start() { + this.running = true; + + try { + registerListener(); + } catch (Exception e) { + if (e instanceof JMSBindingException) throw (JMSBindingException)e; + throw new JMSBindingException("Error starting JMSAsyncResponse endpoint", e); + } + } // end start + + public void stop() { + this.running = false; + try { + consumer.close(); + jmsResourceFactory.closeConnection(); + jmsResourceFactory.closeResponseConnection(); + } catch (Exception e) { + // if using an embedded broker then when shutting down Tuscany the broker may get closed + // before this stop method is called. I can't see how to detect that so for now just + // ignore the exception if the message is that the transport is already disposed + if ((e.getMessage() == null) || !e.getMessage().contains("disposed")) { + throw new JMSBindingException("Error stopping JMSServiceBinding", e); + } + } + } // end stop + + private void registerListener() throws NamingException, JMSException { + + Session session = jmsResourceFactory.createSession(); + lookupActivationSpec(); + destination = lookupQueue( jmsBinding.getResponseDestinationName() ); + if (destination == null) { + throw new JMSBindingException("Unable to create Async Response queue"); + } // end if + + if (jmsBinding.getJMSSelector() != null) { + consumer = session.createConsumer(destination, jmsBinding.getJMSSelector()); + } else { + consumer = session.createConsumer(destination); + } // end if + + try { + + consumer.setMessageListener(listener); + jmsResourceFactory.startConnection(); + + } catch (javax.jms.JMSException e) { + + // setMessageListener not allowed in JEE container so use Tuscany threads + + jmsResourceFactory.startConnection(); + workScheduler.scheduleWork(new Runnable() { + public void run() { + try { + while (running) { + final Message msg = consumer.receive(); + workScheduler.scheduleWork(new Runnable() { + public void run() { + try { + listener.onMessage(msg); + } catch (Exception e) { + e.printStackTrace(); + } // end try + } // end method run + }); + } // end while + } catch (Exception e) { + e.printStackTrace(); + } // end try + } // end method run + }); + } // end try + logger.log(Level.INFO, "JMS AsyncResponse handler '" + + serviceName + + "' listening on destination " + + ((destination instanceof Queue) ? ((Queue)destination).getQueueName() : ((Topic)destination).getTopicName())); + } // end method registerListener + + // Stub code for ActivationSpec support that throws appropriate errors + private void lookupActivationSpec() { + if ( jmsBinding.getActivationSpecName() != null ) { + String createMode = jmsBinding.getActivationSpecCreate(); + if ( JMSBindingConstants.CREATE_ALWAYS.equals(createMode) ) { + ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName()); + if ( spec != null ) { + throw new JMSBindingException("ActivationSpec specifies create mode of \"always\" but resource already exists."); + } + throw new JMSBindingException("Can not create ActivationSpec"); + } else if ( JMSBindingConstants.CREATE_IF_NOT_EXIST.equals(createMode)) { + ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName()); + if ( spec == null ) { + throw new JMSBindingException("Can not create ActivationSpec"); + } + } else if ( JMSBindingConstants.CREATE_NEVER.equals(createMode)) { + ActivationSpec spec = jmsResourceFactory.lookupActivationSpec(jmsBinding.getActivationSpecName()); + if ( spec == null ) + throw new JMSBindingException("ActivationSpec specifies create mode of \"never\" but resource does not exist at jndiName " + jmsBinding.getActivationSpecName()); + + } // end if + } // end if + } // end method lookupActivationSpec + + /** + * Looks up the Async Response Queue for the JMS Binding. + * <p> + * What happens in the look up will depend on the create mode specified for the JMS Binding: + * <ul> + * <li>always - the JMS queue is always created. It is an error if the queue already exists + * <li>ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists + * <li>never - the JMS queue is never created. It is an error if the queue does not exist + * </ul> + * See the SCA JMS Binding specification for more information. + * <p> + * @param queueName - the name of the Async Response queue + * @return The Async Response queue. + * @throws NamingException Failed to lookup JMS queue + * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause is that the JMS queue's current existence/non-existence is not + * compatible with the create mode specified on the binding + */ + private Destination lookupQueue(String queueName ) throws NamingException, JMSBindingException { + + Destination destination = jmsResourceFactory.lookupDestination(queueName); + + String qCreateMode = jmsBinding.getDestinationCreate(); + if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) { + // In this mode, the queue must not already exist as we are creating it + if (destination != null) { + throw new JMSBindingException("JMS Destination " + queueName + + " already exists but has create mode of \"" + + qCreateMode + + "\" while registering service " + + serviceName + + " listener"); + } // end if + + // Create the queue + destination = jmsResourceFactory.createDestination(queueName); + + } else if (qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) { + // In this mode, the queue may nor may not exist. It will be created if it does not exist + // but don't create when using jms:jndi uri format + if (destination == null && !"jndi".equals(jmsBinding.getDestinationType())) { + destination = jmsResourceFactory.createDestination(queueName); + } // end if + + } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) { + // In this mode, the queue must have already been created. + if (destination == null) { + throw new JMSBindingException("JMS Destination " + queueName + + " not found but create mode of \"" + + qCreateMode + + "\" while registering service " + + serviceName + + " listener"); + } // end if + } // end if + + // Make sure we ended up with a queue + if (destination == null) { + throw new JMSBindingException("JMS Destination " + queueName + + " not found with create mode of \"" + + qCreateMode + + "\" while registering service " + + serviceName + + " listener"); + } // end if + + // Make sure its the expected type (queue or topic) + String type = (destination instanceof Queue) ? JMSBindingConstants.DESTINATION_TYPE_QUEUE : JMSBindingConstants.DESTINATION_TYPE_TOPIC; + if ("jndi".equals(jmsBinding.getDestinationType())) { + jmsBinding.setDestinationType(type); + } else { + if (!type.equals(jmsBinding.getDestinationType())) { + throw new JMSBindingException("JMS Destination " + queueName + + " expecting type of " + + jmsBinding.getDestinationType() + + " but found " + + type + + " while registering service " + + serviceName + + " listener"); + } // end if + } // end if + + return destination; + } // end method lookupDestinationQueue(String) + + public String getDestinationName() { + try { + if (destination instanceof Queue) { + return ((Queue)destination).getQueueName(); + } else if (destination instanceof Topic) { + return ((Topic)destination).getTopicName(); + } else { + return null; + } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } // end method getDestinationName + +} // end class AsyncResponseJMSServiceListener diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java index 9f3062f065..566284fda6 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/DefaultServiceInvoker.java @@ -90,9 +90,15 @@ public class DefaultServiceInvoker implements MessageListener { // call the runtime wire - the response is handled by the // transport interceptor - getEndpoint(targetBinding).invoke(tuscanyMsg); + //getEndpoint(targetBinding).invoke(tuscanyMsg); + RuntimeEndpoint endpoint = getEndpoint(targetBinding); + if( endpoint.isAsyncInvocation() ) { + endpoint.invokeAsync(tuscanyMsg); + } else { + endpoint.invoke(tuscanyMsg); + } // end if - } + } // end method invokeService private RuntimeEndpoint getEndpoint(Binding targetBinding) { for(Endpoint ep: service.getEndpoints()) { diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java new file mode 100644 index 0000000000..386cb54700 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/host/JMSAsyncResponseInvoker.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.host; + +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.naming.NamingException; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.binding.jms.JMSBinding; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +/** + * TODO RRB experiement + * Listener for the JMSBinding. + * + * @version $Rev$ $Date$ + */ +public class JMSAsyncResponseInvoker implements MessageListener { + + private static final Logger logger = Logger.getLogger(JMSAsyncResponseInvoker.class.getName()); + + private RuntimeEndpointReference endpointReference; + private JMSBinding jmsBinding; + private JMSResourceFactory jmsResourceFactory; + private RuntimeComponentReference reference; + private MessageFactory messageFactory; + + public JMSAsyncResponseInvoker(RuntimeEndpointReference endpointReference, + MessageFactory messageFactory, + JMSResourceFactory rf) throws NamingException { + this.endpointReference = endpointReference; + this.jmsBinding = (JMSBinding) endpointReference.getBinding(); + this.jmsResourceFactory = rf; + this.reference = (RuntimeComponentReference) endpointReference.getReference(); + this.messageFactory = messageFactory; + } + + public void onMessage(Message requestJMSMsg) { + logger.log(Level.FINE, "JMS reference '" + reference.getName() + "' received message " + requestJMSMsg); + try { + invokeReference(requestJMSMsg); + } catch (Throwable e) { + logger.log(Level.SEVERE, "Exception send fault response '" + reference.getName(), e); + } + } // end method onMessage + + protected void invokeReference(Message requestJMSMsg) throws JMSException, InvocationTargetException { + + // create the Tuscany message + org.apache.tuscany.sca.invocation.Message tuscanyMsg = messageFactory.createMessage(); + + // populate the message context with JMS binding information + JMSBindingContext context = new JMSBindingContext(); + tuscanyMsg.setBindingContext(context); + + context.setJmsMsg(requestJMSMsg); + context.setJmsResourceFactory(jmsResourceFactory); + context.setReplyToDestination(requestJMSMsg.getJMSReplyTo()); + + + + // set the message body + tuscanyMsg.setBody(requestJMSMsg); + + // call the runtime wire - the response is handled by the + // transport interceptor + endpointReference.invokeAsyncResponse(tuscanyMsg); + + } // end method invokeReference + +} // end class AsyncResponseInvoker diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java index aae81fbac1..b9c4166233 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsdefault/runtime/OperationSelectorJMSDefaultServiceInterceptor.java @@ -35,6 +35,7 @@ import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML; import org.apache.tuscany.sca.common.xml.dom.DOMHelper; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -50,7 +51,7 @@ import org.xml.sax.SAXException; * * @version $Rev$ $Date$ */ -public class OperationSelectorJMSDefaultServiceInterceptor implements Interceptor { +public class OperationSelectorJMSDefaultServiceInterceptor extends InterceptorAsyncImpl { private static final String ON_MESSAGE_METHOD_NAME = "onMessage"; @@ -193,6 +194,13 @@ public class OperationSelectorJMSDefaultServiceInterceptor implements Intercepto public void setNext(Invoker next) { this.next = next; - } - + } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return msg; + } // end method processResponse } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java index 343aa8d52a..52a7c58027 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/jmsuserprop/runtime/OperationSelectorJMSUserPropServiceInterceptor.java @@ -26,6 +26,7 @@ import org.apache.tuscany.sca.binding.jms.JMSBinding; import org.apache.tuscany.sca.binding.jms.JMSBindingException; import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; import org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserProp; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -39,7 +40,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpoint; * <operationSelector.jmsUser propertName="MyHeaderProperty"/> * */ -public class OperationSelectorJMSUserPropServiceInterceptor implements Interceptor { +public class OperationSelectorJMSUserPropServiceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpoint endpoint; @@ -104,4 +105,11 @@ public class OperationSelectorJMSUserPropServiceInterceptor implements Intercept this.next = next; } + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return msg; + } // end method processResponse } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java new file mode 100644 index 0000000000..f07e9de29f --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingAsyncResponseInvoker.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jms.provider; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.invocation.InvokerAsyncResponse; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +/** + * @version $Rev$ $Date$ + */ +public class JMSBindingAsyncResponseInvoker implements InvokerAsyncResponse { + + RuntimeEndpoint endpoint; + + public JMSBindingAsyncResponseInvoker(ExtensionPointRegistry extensionPoints, + RuntimeEndpoint endpoint) { + this.endpoint = endpoint; + } // end constructor + + public void invokeAsyncResponse(Message msg) { + // TODO + } // end method invokeAsyncResponse +} // end class JMSBindingAsyncResponseInvoker
\ No newline at end of file diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java index 4ee0719707..3471e68d6f 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java @@ -20,37 +20,45 @@ package org.apache.tuscany.sca.binding.jms.provider; import javax.jms.JMSException; +import javax.jms.MessageListener; +import javax.naming.NamingException; import org.apache.tuscany.sca.binding.jms.JMSBinding; import org.apache.tuscany.sca.binding.jms.JMSBindingException; import org.apache.tuscany.sca.binding.jms.headers.HeaderReferenceInterceptor; +import org.apache.tuscany.sca.binding.jms.host.AsyncResponseJMSServiceListener; +import org.apache.tuscany.sca.binding.jms.host.JMSAsyncResponseInvoker; import org.apache.tuscany.sca.binding.jms.transport.TransportReferenceInterceptor; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.invocation.Phase; -import org.apache.tuscany.sca.provider.EndpointReferenceProvider; +import org.apache.tuscany.sca.provider.EndpointReferenceAsyncProvider; import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; import org.apache.tuscany.sca.provider.WireFormatProvider; import org.apache.tuscany.sca.provider.WireFormatProviderFactory; -import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.apache.tuscany.sca.work.WorkScheduler; /** * Implementation of the JMS reference binding provider. * + * This version supports native async service invocations + * * @version $Rev$ $Date$ */ -public class JMSBindingReferenceBindingProvider implements EndpointReferenceProvider { +public class JMSBindingReferenceBindingProvider implements EndpointReferenceAsyncProvider { private RuntimeEndpointReference endpointReference; private RuntimeComponentReference reference; private JMSBinding jmsBinding; private JMSResourceFactory jmsResourceFactory; - private RuntimeComponent component; private InterfaceContract interfaceContract; private ExtensionPointRegistry extensions; @@ -61,13 +69,14 @@ public class JMSBindingReferenceBindingProvider implements EndpointReferenceProv private WireFormatProviderFactory responseWireFormatProviderFactory; private WireFormatProvider responseWireFormatProvider; + + private AsyncResponseJMSServiceListener responseQueue = null; public JMSBindingReferenceBindingProvider(RuntimeEndpointReference endpointReference, ExtensionPointRegistry extensions, JMSResourceFactory jmsResourceFactory) { this.endpointReference = endpointReference; this.reference = (RuntimeComponentReference) endpointReference.getReference(); this.jmsBinding = (JMSBinding) endpointReference.getBinding(); this.extensions = extensions; - this.component = (RuntimeComponent) endpointReference.getComponent(); this.jmsResourceFactory = jmsResourceFactory; // Get the factories/providers for operation selection @@ -95,16 +104,21 @@ public class JMSBindingReferenceBindingProvider implements EndpointReferenceProv responseWireFormatProvider.configureWireFormatInterfaceContract(interfaceContract); } catch (CloneNotSupportedException ex){ interfaceContract = reference.getInterfaceContract(); - } - } + } // end try + + // If the service is asyncInvocation, then create a fixed response location + if( endpointReference.isAsyncInvocation() ) { + String asyncCallbackName = endpointReference.getReference().getName() + "_asyncResponse"; + jmsBinding.setResponseDestinationName(asyncCallbackName); + } // end if + + } // end constructor public Invoker createInvoker(Operation operation) { if (jmsBinding.getDestinationName() == null) { -// if (!reference.isCallback()) { // TODO: 2.x migration, is this check needed? throw new JMSBindingException("No destination specified for reference " + reference.getName()); -// } - } + } // end if if ( jmsBinding.getActivationSpecName() != null ) { throw new JMSBindingException("Activation spec can not be specified on an SCA reference binding."); @@ -113,7 +127,7 @@ public class JMSBindingReferenceBindingProvider implements EndpointReferenceProv invoker = new RRBJMSBindingInvoker(operation, jmsResourceFactory, endpointReference); return invoker; - } + } // end method createInvoker public boolean supportsOneWayInvocation() { return true; @@ -124,17 +138,43 @@ public class JMSBindingReferenceBindingProvider implements EndpointReferenceProv } public void start() { + // If the reference is async invocation, then a response queue handler and associated JMS listener must be created + // and started + if (endpointReference.isAsyncInvocation()) { + // Create the JMS listener + FactoryExtensionPoint modelFactories = extensions.getExtensionPoint(FactoryExtensionPoint.class); + MessageFactory messageFactory = modelFactories.getFactory(MessageFactory.class); + MessageListener listener; + try { + listener = new JMSAsyncResponseInvoker(endpointReference, messageFactory, jmsResourceFactory); + } catch (NamingException e) { + throw new JMSBindingException("Unable to create JMSResponseInvoker", e); + } // end try + + // Create the response queue handler + UtilityExtensionPoint utilities = extensions.getExtensionPoint(UtilityExtensionPoint.class); + WorkScheduler workScheduler = utilities.getUtility(WorkScheduler.class); + + responseQueue = new AsyncResponseJMSServiceListener(listener, + jmsBinding.getResponseDestinationName(), + jmsBinding, workScheduler, jmsResourceFactory); + responseQueue.start(); + } // end if - } + } // end method start public void stop() { try { + if( responseQueue != null ) { + responseQueue.stop(); + } // end if + jmsResourceFactory.closeConnection(); jmsResourceFactory.closeResponseConnection(); } catch (JMSException e) { throw new JMSBindingException(e); } - } + } // end method stop /* * set up the reference binding wire with the right set of jms reference @@ -167,6 +207,13 @@ public class JMSBindingReferenceBindingProvider implements EndpointReferenceProv jmsBinding, jmsResourceFactory, endpointReference) ); - } + } + + /** + * Indicates that this binding supports async invocations natively + */ + public boolean supportsNativeAsync() { + return true; + } // end method supportsNativeAsync -} +} // end class diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java index 8428a45c6e..b96376eb15 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java @@ -29,14 +29,18 @@ import org.apache.tuscany.sca.binding.jms.host.JMSServiceListener; import org.apache.tuscany.sca.binding.jms.host.JMSServiceListenerDetails; import org.apache.tuscany.sca.binding.jms.host.JMSServiceListenerFactory; import org.apache.tuscany.sca.binding.jms.transport.TransportServiceInterceptor; +import org.apache.tuscany.sca.binding.jms.wire.AsyncResponseDestinationInterceptor; import org.apache.tuscany.sca.binding.jms.wire.CallbackDestinationInterceptor; import org.apache.tuscany.sca.binding.jms.wire.OperationPropertiesInterceptor; +import org.apache.tuscany.sca.binding.sca.provider.SCABindingAsyncResponseInvoker; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.InvokerAsyncResponse; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.EndpointAsyncProvider; import org.apache.tuscany.sca.provider.EndpointProvider; import org.apache.tuscany.sca.provider.OperationSelectorProvider; import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory; @@ -52,7 +56,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpoint; * * @version $Rev$ $Date$ */ -public class JMSBindingServiceBindingProvider implements EndpointProvider, JMSServiceListenerDetails { +public class JMSBindingServiceBindingProvider implements EndpointAsyncProvider, JMSServiceListenerDetails { private static final Logger logger = Logger.getLogger(JMSBindingServiceBindingProvider.class.getName()); private ExtensionPointRegistry registry; @@ -202,7 +206,11 @@ public class JMSBindingServiceBindingProvider implements EndpointProvider, JMSSe new CallbackDestinationInterceptor(endpoint)); bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT, new HeaderServiceInterceptor(jmsBinding)); - + + // add async response interceptor after header interceptor + bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT, + new AsyncResponseDestinationInterceptor(endpoint)); + // add request wire format bindingChain.addInterceptor(requestWireFormatProvider.getPhase(), requestWireFormatProvider.createInterceptor()); @@ -243,4 +251,15 @@ public class JMSBindingServiceBindingProvider implements EndpointProvider, JMSSe return endpoint; } + /** + * Indicates that this service binding does support native async service invocations + */ + public boolean supportsNativeAsync() { + return true; + } // end method supportsNativeAsync + + public InvokerAsyncResponse createAsyncResponseInvoker() { + return new JMSBindingAsyncResponseInvoker(null, endpoint); + } // end method createAsyncResponseInvoker + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java index 098bdde3ae..0e88b283dc 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/RRBJMSBindingInvoker.java @@ -29,9 +29,11 @@ import org.apache.tuscany.sca.binding.jms.JMSBinding; import org.apache.tuscany.sca.binding.jms.JMSBindingConstants; import org.apache.tuscany.sca.binding.jms.JMSBindingException; import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.util.FaultException; import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; import org.oasisopen.sca.ServiceRuntimeException; @@ -40,7 +42,7 @@ import org.oasisopen.sca.ServiceRuntimeException; * * @version $Rev$ $Date$ */ -public class RRBJMSBindingInvoker implements Invoker { +public class RRBJMSBindingInvoker extends InterceptorAsyncImpl { protected Operation operation; protected String operationName; @@ -65,14 +67,12 @@ public class RRBJMSBindingInvoker implements Invoker { // properties of the inbound service request. We should not look for or require a // statically-configured destination unless a message is received that does not have // the necessary properties. -// if (!reference.isCallback()) { // TODO: 2.x migration, is this check needed? - bindingRequestDest = lookupDestination(); -// } + bindingRequestDest = lookupDestination(); bindingReplyDest = lookupResponseDestination(); } catch (NamingException e) { throw new JMSBindingException(e); - } - } + } // end try + } // end constructor /** * Looks up the Destination Queue for the JMS Binding @@ -136,7 +136,7 @@ public class RRBJMSBindingInvoker implements Invoker { qCreateMode = jmsBinding.getDestinationCreate(); } - // FIXME: [rfeng] A hack to remove jms:jndi: prefix + // Remove jms:jndi: prefix if present if (queueName.startsWith("jms:jndi:")) { queueName = queueName.substring("jms:jndi:".length()); } @@ -186,7 +186,15 @@ public class RRBJMSBindingInvoker implements Invoker { } return dest; - } + } // end method lookupDestinationQueue + + /** + * Get the next in the chain from the binding invocation chain + */ + public Invoker getNext() { + return (Invoker)endpointReference.getBindingInvocationChain().getHeadInvoker(); + } // end method getNext + public org.apache.tuscany.sca.invocation.Message invoke(org.apache.tuscany.sca.invocation.Message tuscanyMsg) { try { @@ -264,6 +272,86 @@ public class RRBJMSBindingInvoker implements Invoker { } } return replyToDest; - } + } + + /** + * Process forward request message + * @param tuscanyMsg - the request message + * @return the processed version of the request message + */ + public Message processRequest(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)); + + return tuscanyMsg; + } catch (Exception e) { + throw new JMSBindingException(e); + } // end try + } // end method processRequest + + /** + * Post processing for a request message where an error occurred + * @param tuscanyMsg + * @return the post processed message + */ + public Message postProcessRequest(Message tuscanyMsg, Throwable e) { + // Exception handling + if ( e instanceof ServiceRuntimeException ) { + if (e.getCause() instanceof InvocationTargetException) { + if ((e.getCause().getCause() instanceof RuntimeException)) { + tuscanyMsg.setFaultBody(e.getCause()); + } else { + tuscanyMsg.setFaultBody(((InvocationTargetException)e.getCause()).getTargetException()); + } // end if + } else if (e.getCause() instanceof FaultException) { + tuscanyMsg.setFaultBody(e.getCause()); + } else { + tuscanyMsg.setFaultBody(e); + } // end if + } else { + tuscanyMsg.setFaultBody(e); + } // end if + + return postProcessRequest( tuscanyMsg ); + } // end method postProcessRequest + + /** + * General post processing for a request message + * - close out the JMS session & connection + * @param tuscanyMsg + * @return the post processed message + */ + public Message postProcessRequest(Message tuscanyMsg) { + // Close of JMS session + try { + JMSBindingContext context = tuscanyMsg.getBindingContext(); + context.closeJmsSession(); + if (jmsResourceFactory.isConnectionClosedAfterUse()) { + jmsResourceFactory.closeConnection(); + } // end if + } catch (JMSException ex) { + throw new JMSBindingException(ex); + } // end try + return tuscanyMsg; + } // end method postProcessRequest + + /** + * Process response message + * @param tuscanyMsg - the response message + * @return the processed version of the response message + */ + public Message processResponse(Message tuscanyMsg) { + // For async handling, there is nothing to do here + return tuscanyMsg; + } } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java index 3ed8021107..cba6022fb1 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportReferenceInterceptor.java @@ -30,6 +30,7 @@ import org.apache.tuscany.sca.binding.jms.JMSBindingConstants; import org.apache.tuscany.sca.binding.jms.JMSBindingException; import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -41,7 +42,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; * * @version $Rev$ $Date$ */ -public class TransportReferenceInterceptor implements Interceptor { +public class TransportReferenceInterceptor extends InterceptorAsyncImpl { private Invoker next; private JMSResourceFactory jmsResourceFactory; @@ -91,8 +92,7 @@ public class TransportReferenceInterceptor implements Interceptor { Boolean deliveryModePersistent = jmsBinding.getEffectiveJMSDeliveryMode(opName); if (deliveryModePersistent != null) { producer.setDeliveryMode( deliveryModePersistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); - } - + } try { producer.send((javax.jms.Message)msg.getBody()); @@ -102,8 +102,8 @@ public class TransportReferenceInterceptor implements Interceptor { return msg; } catch (JMSException e) { throw new JMSBindingException(e); - } - } + } // end try + } // end method invokeRequest public Message invokeResponse(Message msg) { JMSBindingContext context = msg.getBindingContext(); @@ -165,4 +165,23 @@ public class TransportReferenceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + /** + * Process forward request message + * @param tuscanyMsg - the request message + * @return the processed version of the request message + */ + public Message processRequest(Message tuscanyMsg) { + return invokeRequest(tuscanyMsg); + } // end method processRequest + + /** + * Process response message + * @param tuscanyMsg - the response message + * @return the processed version of the response message + */ + public Message processResponse(Message tuscanyMsg) { + // TODO Auto-generated method stub + return tuscanyMsg; + } // end method processResponse } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java index d371bbba86..df8f33bac3 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java @@ -40,6 +40,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -51,7 +52,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpoint; * * @version $Rev$ $Date$ */ -public class TransportServiceInterceptor implements Interceptor { +public class TransportServiceInterceptor extends InterceptorAsyncImpl { private static final Logger logger = Logger.getLogger(TransportServiceInterceptor.class.getName()); private Invoker next; @@ -96,7 +97,6 @@ public class TransportServiceInterceptor implements Interceptor { } public Message invokeRequest(Message msg) { -// try { EndpointReference from = assemblyFactory.createEndpointReference(); Endpoint fromEndpoint = assemblyFactory.createEndpoint(); @@ -109,10 +109,8 @@ public class TransportServiceInterceptor implements Interceptor { from.setCallbackEndpoint(callbackEndpoint); return msg; -// } catch (JMSException e) { -// throw new JMSBindingException(e); -// } - } + + } // end method invokeRequest public Message invokeResponse(Message msg) { JMSBindingContext context = msg.getBindingContext(); @@ -202,6 +200,85 @@ public class TransportServiceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; - } + } + + public Message processRequest(Message msg) { + return invokeRequest( msg ); + } // end method processRequest + + public Message processResponse(Message msg) { + JMSBindingContext context = msg.getBindingContext(); + try { + Session session = context.getJmsResponseSession(); + javax.jms.Message requestJMSMsg = context.getJmsMsg(); + javax.jms.Message responseJMSMsg = msg.getBody(); + + Destination replyDest = requestJMSMsg.getJMSReplyTo(); + if (replyDest == null) { + if (jmsBinding.getResponseDestinationName() != null) { + try { + replyDest = jmsResourceFactory.lookupDestination(jmsBinding.getResponseDestinationName()); + } catch (NamingException e) { + throw new JMSBindingException("Exception lookingup response destination", e); + } + } + } // end if + + if (replyDest == null) { + // assume no reply is expected + if (msg.getBody() != null) { + logger.log(Level.FINE, "JMS service '" + service.getName() + "' dropped response as request has no replyTo"); + } + return msg; + } // end if + + if ((msg.getOperation() != null)) { + String operationName = msg.getOperation().getName(); + if (jmsBinding.getEffectiveJMSPriority(operationName) != null) { + responseJMSMsg.setJMSPriority(jmsBinding.getEffectiveJMSPriority(operationName)); + } + + if ( jmsBinding.getEffectiveJMSType(operationName) != null) { + responseJMSMsg.setJMSType(jmsBinding.getEffectiveJMSType(operationName)); + } + + if ((jmsBinding.getEffectiveJMSDeliveryMode(operationName) != null)) { + responseJMSMsg.setJMSDeliveryMode(jmsBinding.getEffectiveJMSDeliveryMode(operationName) ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); + } + + if ((jmsBinding.getEffectiveJMSTimeToLive(operationName) != null)) { + responseJMSMsg.setJMSExpiration(jmsBinding.getEffectiveJMSTimeToLive(operationName).longValue()); + } + } + + if (correlationScheme == null || + JMSBindingConstants.CORRELATE_MSG_ID.equalsIgnoreCase(correlationScheme)) { + responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSMessageID()); + } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equalsIgnoreCase(correlationScheme)) { + responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSCorrelationID()); + } + + MessageProducer producer = session.createProducer(replyDest); + + // Set jms header attributes in producer, not message. + int deliveryMode = requestJMSMsg.getJMSDeliveryMode(); + producer.setDeliveryMode(deliveryMode); + int deliveryPriority = requestJMSMsg.getJMSPriority(); + producer.setPriority(deliveryPriority); + long timeToLive = requestJMSMsg.getJMSExpiration(); + producer.setTimeToLive(timeToLive); + + producer.send((javax.jms.Message)msg.getBody()); + + producer.close(); + + return msg; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } finally { + context.closeJmsResponseSession(); + } // end try + } // end method processResponse } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java new file mode 100644 index 0000000000..7bb91f3081 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/AsyncResponseDestinationInterceptor.java @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wire; + +import java.util.Iterator; +import java.util.List; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Topic; +import javax.naming.NamingException; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.binding.jms.JMSBinding; +import org.apache.tuscany.sca.binding.jms.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.JMSBindingException; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; +import org.apache.tuscany.sca.core.invocation.AsyncResponseInvoker; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +/** + * JMS Binding Interceptor class that deals with destination address & ID for an async response on the service side + * + */ +public class AsyncResponseDestinationInterceptor extends InterceptorAsyncImpl { + private Invoker next; + private RuntimeComponentService service; + private RuntimeEndpoint endpoint; + + public AsyncResponseDestinationInterceptor(RuntimeEndpoint endpoint) { + super(); + this.service = (RuntimeComponentService) endpoint.getService(); + this.endpoint = endpoint; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Message invoke(Message msg) { + 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(); + + // Extract the Callback destination name header, if present + String asyncRespAddr = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY); + + if (asyncRespAddr != null) { + asyncRespAddr = stripJMSPrefix( asyncRespAddr ); + } else { + // If there is no Callback destination name header present, but the service is async, use the JMS ReplyTo header + if ( isAsync(service) ) { + if ( ( jmsMsg.getJMSReplyTo() != null ) ) { + Destination replyTo = jmsMsg.getJMSReplyTo(); + if (replyTo != null) { + asyncRespAddr = (replyTo instanceof Queue) ? ((Queue) replyTo).getQueueName() : ((Topic) replyTo).getTopicName(); + } + } // end if + } // end if + } // end if + + // If there is no response address, we're done + if( asyncRespAddr == null ) return msg; + + // Get the message ID - assume that the interceptor for obtaining the message ID is earlier in the chain + // than this interceptor + String msgID = (String)msg.getHeaders().get("MESSAGE_ID"); + + // Create a response invoker and add it to the message headers + AsyncResponseInvoker respInvoker = new AsyncResponseInvoker(endpoint, null, asyncRespAddr, msgID); + msg.getHeaders().put("ASYNC_RESPONSE_INVOKER", respInvoker); + + } catch (JMSException e) { + throw new JMSBindingException(e); + } // end try + + return msg; + } // end method invokeRequest + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + /** + * Process a response message + * - if it is an async response, there will be a header "ASYNC_RESPONSE_INVOKER" which contains + * the address of the JMS queue to reply to plus a message ID of the original message + * These values are used to create the Destination for the JMS message and to add a "RELATES_TO" + * header which is sent with the response message to allow the client to correlate the response + * to the original request + * @param msg - the Tuscany message + * @returns - the updated Tuscany message + */ + public Message processResponse(Message msg) { + AsyncResponseInvoker respInvoker = (AsyncResponseInvoker)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER"); + if ( respInvoker == null ) return msg; + + String responseAddress = respInvoker.getResponseTargetAddress(); + String relatedMsg = respInvoker.getRelatesToMsgID(); + + // Get the JMS context + JMSBindingContext context = msg.getBindingContext(); + JMSResourceFactory jmsResourceFactory = context.getJmsResourceFactory(); + Destination dest; + try { + dest = jmsResourceFactory.lookupDestination(responseAddress); + if( dest == null ) { + dest = jmsResourceFactory.createDestination(responseAddress); + } // end if + } catch (NamingException e) { + throw new JMSBindingException(e); + } + context.setReplyToDestination(dest); + msg.getHeaders().put("RELATES_TO", relatedMsg); + + return msg; + } // end method processResponse + + /** + * Utility that strips the leading "jms:jndi:" prefix from a JMS address + * @param asyncRespAddr - the JMS address + * @return - the JMS address with the prefix removed + * @throws JMSBindingException if the JMS address does not have a prefix + */ + private String stripJMSPrefix(String asyncRespAddr) { + // If present, strip any leading "jms:jndi:" string + if (!asyncRespAddr.startsWith("jms:jndi:")) { + throw new JMSBindingException("message property " + JMSBindingConstants.CALLBACK_Q_PROPERTY + " does not start with 'jms:jndi:' found: " + asyncRespAddr); + } else { + return asyncRespAddr.substring(9); + } // end if + } // end method stripJMSPrefix + + /** + * Determines if a service has an interface that is async invocation + * @param service - the service + * @return true if the service is async, false otherwise + */ + private boolean isAsync( RuntimeComponentService service ) { + service.getInterfaceContract().getInterface(); + + Iterator<Intent> intents = service.getRequiredIntents().iterator(); + while ( intents.hasNext() ) { + Intent intent = intents.next(); + if ( intent.getName().getLocalPart().equals("asyncInvocation") ) return true; + } // end while + + intents = service.getInterfaceContract().getInterface().getRequiredIntents().iterator(); + while ( intents.hasNext() ) { + Intent intent = intents.next(); + if ( intent.getName().getLocalPart().equals("asyncInvocation") ) return true; + } // end while + return false; + } // end method isAsync +} // end class
\ No newline at end of file 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 290ce77e5d..9e14ad0b1a 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 @@ -30,6 +30,7 @@ import org.apache.tuscany.sca.binding.jms.JMSBinding; import org.apache.tuscany.sca.binding.jms.JMSBindingConstants; import org.apache.tuscany.sca.binding.jms.JMSBindingException; import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -40,7 +41,7 @@ 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 { +public class CallbackDestinationInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeComponentService service; private RuntimeEndpoint endpoint; @@ -119,4 +120,12 @@ public class CallbackDestinationInterceptor implements Interceptor { return msg; } // end method invokeRequest + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return msg; + } // end method processResponse } // end class
\ No newline at end of file diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java index bf046b473e..682c9ee48c 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wire/OperationPropertiesInterceptor.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.binding.jms.wire; import java.util.List; import org.apache.tuscany.sca.binding.jms.JMSBinding; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -28,7 +29,7 @@ import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; -public class OperationPropertiesInterceptor implements Interceptor { +public class OperationPropertiesInterceptor extends InterceptorAsyncImpl { private Invoker next; private JMSBinding jmsBinding; private RuntimeComponentService service; @@ -65,5 +66,12 @@ public class OperationPropertiesInterceptor implements Interceptor { } return msg; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + public Message processResponse(Message msg) { + return msg; + } // end method processResponse } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java index 4620063076..0b2bcbd7b3 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesReferenceInterceptor.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -41,7 +42,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; * * @version $Rev$ $Date$ */ -public class WireFormatJMSBytesReferenceInterceptor implements Interceptor { +public class WireFormatJMSBytesReferenceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpointReference endpointReference; @@ -120,4 +121,13 @@ public class WireFormatJMSBytesReferenceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java index 506d47f8a3..835734f45e 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/runtime/WireFormatJMSBytesServiceInterceptor.java @@ -27,6 +27,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -39,7 +40,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpoint; * * @version $Rev$ $Date$ */ -public class WireFormatJMSBytesServiceInterceptor implements Interceptor { +public class WireFormatJMSBytesServiceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpoint endpoint; private JMSResourceFactory jmsResourceFactory; @@ -112,4 +113,13 @@ public class WireFormatJMSBytesServiceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java index e453940d30..6a32344f94 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLReferenceInterceptor.java @@ -31,6 +31,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.util.FaultException; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -39,7 +40,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; import org.w3c.dom.Node; -public class WireFormatJMSBytesXMLReferenceInterceptor implements Interceptor { +public class WireFormatJMSBytesXMLReferenceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpointReference endpointReference; @@ -120,4 +121,13 @@ public class WireFormatJMSBytesXMLReferenceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java index c1e97a93d0..6ff27d4660 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytesxml/runtime/WireFormatJMSBytesXMLServiceInterceptor.java @@ -27,13 +27,14 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; -public class WireFormatJMSBytesXMLServiceInterceptor implements Interceptor { +public class WireFormatJMSBytesXMLServiceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpoint endpoint; private JMSResourceFactory jmsResourceFactory; @@ -106,4 +107,13 @@ public class WireFormatJMSBytesXMLServiceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java index 87d99a014e..33e73a69ef 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultReferenceInterceptor.java @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.util.FaultException; @@ -46,7 +47,7 @@ import org.w3c.dom.Node; * * @version $Rev$ $Date$ */ -public class WireFormatJMSDefaultReferenceInterceptor implements Interceptor { +public class WireFormatJMSDefaultReferenceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpointReference endpointReference; @@ -172,4 +173,12 @@ public class WireFormatJMSDefaultReferenceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java index da6f283ff9..b66dd0154f 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/runtime/WireFormatJMSDefaultServiceInterceptor.java @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; @@ -46,8 +47,7 @@ import org.w3c.dom.Node; * * @version $Rev$ $Date$ */ -public class WireFormatJMSDefaultServiceInterceptor implements Interceptor { - private Invoker next; +public class WireFormatJMSDefaultServiceInterceptor extends InterceptorAsyncImpl { private RuntimeEndpoint endpoint; private JMSResourceFactory jmsResourceFactory; private JMSBinding jmsBinding; @@ -137,6 +137,11 @@ public class WireFormatJMSDefaultServiceInterceptor implements Interceptor { // get the jms context JMSBindingContext context = msg.getBindingContext(); + // The Binding Context may be null on an asynchronous response - in which case, create a new one + if(context == null) { + context = createBindingContext(); + msg.setBindingContext(context); + } // end if Session session = context.getJmsResponseSession(); javax.jms.Message responseJMSMsg; @@ -177,11 +182,19 @@ public class WireFormatJMSDefaultServiceInterceptor implements Interceptor { return msg; } - public Invoker getNext() { - return next; - } + private JMSBindingContext createBindingContext() { + JMSBindingContext context = new JMSBindingContext(); + context.setJmsResourceFactory(jmsResourceFactory); - public void setNext(Invoker next) { - this.next = next; - } + return context; + } // end method createBindingContext + + public Message processRequest(Message msg) { + return invokeRequest( msg ); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse( msg ); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java index ec110ea0d2..842bb791d6 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectReferenceInterceptor.java @@ -34,6 +34,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -43,7 +44,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; * * @version $Rev$ $Date$ */ -public class WireFormatJMSObjectReferenceInterceptor implements Interceptor { +public class WireFormatJMSObjectReferenceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpointReference endpointReference; @@ -139,4 +140,13 @@ public class WireFormatJMSObjectReferenceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java index 19baddd9da..e04501e8b7 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsobject/runtime/WireFormatJMSObjectServiceInterceptor.java @@ -30,6 +30,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -42,7 +43,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpoint; * * @version $Rev$ $Date$ */ -public class WireFormatJMSObjectServiceInterceptor implements Interceptor { +public class WireFormatJMSObjectServiceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpoint endpoint; private JMSResourceFactory jmsResourceFactory; @@ -136,4 +137,13 @@ public class WireFormatJMSObjectServiceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java index fd512f7d27..c2b6881c91 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextReferenceInterceptor.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -41,7 +42,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; * * @version $Rev$ $Date$ */ -public class WireFormatJMSTextReferenceInterceptor implements Interceptor { +public class WireFormatJMSTextReferenceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpointReference endpointReference; @@ -121,4 +122,13 @@ public class WireFormatJMSTextReferenceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java index c3f3660211..1ba0744593 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstext/runtime/WireFormatJMSTextServiceInterceptor.java @@ -27,6 +27,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -39,7 +40,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpoint; * * @version $Rev$ $Date$ */ -public class WireFormatJMSTextServiceInterceptor implements Interceptor { +public class WireFormatJMSTextServiceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpoint endpoint; private JMSResourceFactory jmsResourceFactory; @@ -112,4 +113,13 @@ public class WireFormatJMSTextServiceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java index 4d62022196..25e476f837 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLReferenceInterceptor.java @@ -34,6 +34,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.util.FaultException; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -45,7 +46,7 @@ import org.w3c.dom.Node; * * @version $Rev$ $Date$ */ -public class WireFormatJMSTextXMLReferenceInterceptor implements Interceptor { +public class WireFormatJMSTextXMLReferenceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpointReference endpointReference; @@ -125,5 +126,14 @@ public class WireFormatJMSTextXMLReferenceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; - } + } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java index 8e4f8fb90b..d914bd9e2e 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmstextxml/runtime/WireFormatJMSTextXMLServiceInterceptor.java @@ -27,6 +27,7 @@ import org.apache.tuscany.sca.binding.jms.provider.JMSMessageProcessorUtil; import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory; import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; @@ -39,7 +40,7 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpoint; * * @version $Rev$ $Date$ */ -public class WireFormatJMSTextXMLServiceInterceptor implements Interceptor { +public class WireFormatJMSTextXMLServiceInterceptor extends InterceptorAsyncImpl { private Invoker next; private RuntimeEndpoint endpoint; private JMSResourceFactory jmsResourceFactory; @@ -113,4 +114,13 @@ public class WireFormatJMSTextXMLServiceInterceptor implements Interceptor { public void setNext(Invoker next) { this.next = next; } + + public Message processRequest(Message msg) { + return invokeRequest(msg); + } // end method processRequest + + public Message processResponse(Message msg) { + return invokeResponse(msg); + } // end method processResponse + } |