diff options
Diffstat (limited to 'java/sca')
18 files changed, 247 insertions, 37 deletions
diff --git a/java/sca/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsbytes/helloworld/HelloWorldReferenceImpl.java b/java/sca/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsbytes/helloworld/HelloWorldReferenceImpl.java index d9ca674e58..c42f71d838 100644 --- a/java/sca/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsbytes/helloworld/HelloWorldReferenceImpl.java +++ b/java/sca/itest/jms-format/src/main/java/org/apache/tuscany/sca/binding/jms/format/jmsbytes/helloworld/HelloWorldReferenceImpl.java @@ -24,10 +24,10 @@ import org.osoa.sca.annotations.Reference; public class HelloWorldReferenceImpl implements HelloWorldReference { @Reference - protected HelloWorldService helloWorldService; + protected HelloWorldService helloWorldService1; public String getGreetings(String name){ - helloWorldService.setGreetings(name.getBytes()); + helloWorldService1.setGreetings(name.getBytes()); try { Thread.sleep(2000); diff --git a/java/sca/itest/jms-format/src/main/resources/jmsbytes/helloworld.composite b/java/sca/itest/jms-format/src/main/resources/jmsbytes/helloworld.composite index c8b2562d7d..ef66c5583c 100644 --- a/java/sca/itest/jms-format/src/main/resources/jmsbytes/helloworld.composite +++ b/java/sca/itest/jms-format/src/main/resources/jmsbytes/helloworld.composite @@ -19,25 +19,26 @@ --> <composite xmlns="http://www.osoa.org/xmlns/sca/1.0" targetNamespace="http://helloworld" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0" xmlns:hw="http://helloworld" name="helloworld"> <component name="HelloWorldReferenceComponent"> - <implementation.java class="org.apache.tuscany.sca.binding.jms.format.jmsmessage.helloworld.HelloWorldReferenceImpl" /> + <implementation.java class="org.apache.tuscany.sca.binding.jms.format.jmsbytes.helloworld.HelloWorldReferenceImpl" /> <reference name="helloWorldService1" > <binding.jms> <destination name="HelloWorldService1"/> - <!-- wireFormat.bytes/--> + <t:wireFormat.jmsBytes/> </binding.jms> </reference> </component> <component name="HelloWorldServiceComponent1"> - <implementation.java class="org.apache.tuscany.sca.binding.jms.format.jmsmessage.helloworld.HelloWorldServiceImpl" /> + <implementation.java class="org.apache.tuscany.sca.binding.jms.format.jmsbytes.helloworld.HelloWorldServiceImpl" /> <service name="HelloWorldService"> <binding.jms> <destination name="HelloWorldService1"/> - <!-- wireFormat.bytes/--> + <t:wireFormat.jmsBytes/> </binding.jms> </service> </component> diff --git a/java/sca/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSDelimitedTestCase.java b/java/sca/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSDelimitedTestCase.java index 55a4c1ab72..90b74146e5 100644 --- a/java/sca/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSDelimitedTestCase.java +++ b/java/sca/itest/jms-format/src/test/java/org/apache/tuscany/sca/binding/jms/format/FormatJMSDelimitedTestCase.java @@ -27,6 +27,7 @@ import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.node.SCANodeFactory; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; @@ -47,6 +48,7 @@ public class FormatJMSDelimitedTestCase { } @Test + @Ignore public void testHelloWorldCreate() throws Exception { HelloWorldReference helloWorldService = ((SCAClient)node).getService(HelloWorldReference.class, "HelloWorldReferenceComponent"); diff --git a/java/sca/itest/pom.xml b/java/sca/itest/pom.xml index dfd02cec45..90a0ae3780 100644 --- a/java/sca/itest/pom.xml +++ b/java/sca/itest/pom.xml @@ -96,6 +96,7 @@ <module>jms-args</module> <module>jms-callbacks</module> <module>jms-definitions</module> + <module>jms-format</module> <module>jms-selectors</module> <module>large-sdo-ws</module> <module>late-reference-resolution</module> diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java new file mode 100644 index 0000000000..b6e7c6b1b2 --- /dev/null +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java @@ -0,0 +1,79 @@ +/* + * 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 javax.jms.BytesMessage; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; + +/** + * MessageProcessor for sending/receiving javax.jms.BytesMessage with the JMSBinding. + * + * @version $Rev$ $Date$ + */ +public class BytesMessageProcessor extends AbstractMessageProcessor { + + public BytesMessageProcessor(JMSBinding jmsBinding) { + super(jmsBinding); + } + + @Override + protected Object[] extractPayload(Message msg) { + try { + + if (!(msg instanceof BytesMessage)) { + throw new IllegalStateException("expecting JMS BytesMessage: " + msg); + } + + // TODO - Just an experiment + // how should this be wired into databinding? + // how to enforce single byte array parameter + // also casting long -> int! + long noOfBytes = ((BytesMessage)msg).getBodyLength(); + byte [] bytes = new byte[(int)noOfBytes]; + ((BytesMessage)msg).readBytes(bytes); + return new Object[] {bytes}; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + + @Override + protected Message createJMSMessage(Session session, Object o) { + try { + + // TODO - just and experiment. How to enforce a single + // byte array parameter + BytesMessage message = session.createBytesMessage(); + byte [] bytes = (byte[])((Object[])o)[0]; + message.writeBytes(bytes); + return message; + + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } + +} diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java index 0fa67ccc62..22f8f76afb 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java @@ -82,8 +82,13 @@ public class JMSBindingReferenceBindingProvider implements ReferenceBindingProvi this.component = component; this.jmsResourceFactory = jmsResourceFactory; - if (XMLTextMessageProcessor.class.isAssignableFrom(JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding).getClass())) { - setXMLDataBinding(reference); + // TODO - need to look at what the impact of the wireformat + // on the binding interface contract is + if ((jmsBinding.getRequestWireFormat() == null) || + (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault)) { + if (XMLTextMessageProcessor.class.isAssignableFrom(JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding).getClass())) { + setXMLDataBinding(reference); + } } // Get the factories/providers for operation selection @@ -97,6 +102,7 @@ public class JMSBindingReferenceBindingProvider implements ReferenceBindingProvi // Get the factories/providers for wire format + // TODO - Move into the binding // if no request wire format specified then assume the default if (jmsBinding.getRequestWireFormat() == null){ jmsBinding.setRequestWireFormat(new WireFormatJMSDefault()); @@ -115,7 +121,7 @@ public class JMSBindingReferenceBindingProvider implements ReferenceBindingProvi this.responseWireFormatProviderFactory = (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getResponseWireFormat().getClass()); - if (this.responseWireFormatProvider != null){ + if (this.responseWireFormatProviderFactory != null){ this.responseWireFormatProvider = responseWireFormatProviderFactory.createReferenceWireFormatProvider(component, reference, jmsBinding); } diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java index 2642d6d370..779288a6be 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java @@ -124,9 +124,14 @@ public class JMSBindingServiceBindingProvider implements ServiceBindingProviderR } } - if (XMLTextMessageProcessor.class.isAssignableFrom(JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding).getClass())) { - if (!isOnMessage()) { - setXMLDataBinding(service); + // TODO - need to look at what the impact of the wireformat + // on the binding interface contract is + if ((jmsBinding.getRequestWireFormat() == null) || + (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault)) { + if (XMLTextMessageProcessor.class.isAssignableFrom(JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding).getClass())) { + if (!isOnMessage()) { + setXMLDataBinding(service); + } } } @@ -168,7 +173,7 @@ public class JMSBindingServiceBindingProvider implements ServiceBindingProviderR this.responseWireFormatProviderFactory = (WireFormatProviderFactory)providerFactories.getProviderFactory(jmsBinding.getResponseWireFormat().getClass()); - if (this.responseWireFormatProvider != null){ + if (this.responseWireFormatProviderFactory != null){ this.responseWireFormatProvider = responseWireFormatProviderFactory.createServiceWireFormatProvider(component, service, jmsBinding); } } diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytes.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytes.java index 899bbbc13f..84d1a2740f 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytes.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytes.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.tuscany.sca.binding.jms.wireformat.bytes; +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes; import javax.xml.namespace.QName; @@ -30,10 +30,10 @@ import org.apache.tuscany.sca.assembly.WireFormat; * @version $Rev$ $Date$ */ public class WireFormatJMSBytes implements WireFormat { - public static final QName WIRE_FORMAT_JMS_BYTE_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.JMSBytes"); + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsBytes"); public QName getSchemaName() { - return WIRE_FORMAT_JMS_BYTE_QNAME; + return WIRE_FORMAT_JMS_BYTES_QNAME; } public boolean isUnresolved() { diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesProcessor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesProcessor.java index 62b87fd54f..c8a5dea2cb 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesProcessor.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesProcessor.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.tuscany.sca.binding.jms.wireformat.bytes; +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; @@ -44,7 +44,7 @@ import org.apache.tuscany.sca.monitor.Monitor; public class WireFormatJMSBytesProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<WireFormatJMSBytes> { public QName getArtifactType() { - return WireFormatJMSBytes.WIRE_FORMAT_JMS_BYTE_QNAME; + return WireFormatJMSBytes.WIRE_FORMAT_JMS_BYTES_QNAME; } public WireFormatJMSBytesProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesProviderFactory.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesProviderFactory.java index f26ef4f546..19c703264c 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesProviderFactory.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesProviderFactory.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.binding.jms.wireformat.bytes; +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.core.ExtensionPointRegistry; diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesReferenceInterceptor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesReferenceInterceptor.java index edc998bcd9..b4575701b3 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesReferenceInterceptor.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesReferenceInterceptor.java @@ -16,17 +16,21 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.tuscany.sca.binding.jms.wireformat.bytes; +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes; +import javax.jms.JMSException; import javax.jms.Session; import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; 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.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; @@ -44,24 +48,73 @@ public class WireFormatJMSBytesReferenceInterceptor implements Interceptor { private JMSBinding jmsBinding; private JMSMessageProcessor requestMessageProcessor; private JMSMessageProcessor responseMessageProcessor; + private WireFormat requestWireFormat; + private WireFormat responseWireFormat; public WireFormatJMSBytesReferenceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { super(); this.jmsBinding = jmsBinding; this.runtimeWire = runtimeWire; this.jmsResourceFactory = jmsResourceFactory; + + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytes){ + this.requestWireFormat = jmsBinding.getRequestWireFormat(); + this.jmsBinding.setRequestMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME); + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytes){ + this.responseWireFormat = jmsBinding.getResponseWireFormat(); + this.jmsBinding.setResponseMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME); + } + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + } public Message invoke(Message msg) { + if (requestWireFormat != null){ + msg = invokeRequest(msg); + } - if (next != null){ - return getNext().invoke(msg); - } else { - return msg; + msg = getNext().invoke(msg); + + if (responseWireFormat != null){ + msg = invokeResponse(msg); } + + return msg; + } + + public Message invokeRequest(Message msg) { + try { + // get the jms context + JMSBindingContext context = (JMSBindingContext)msg.getHeaders().get(JMSBindingConstants.MSG_CTXT_POSITION); + Session session = context.getJmsSession(); + + javax.jms.Message requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody()); + msg.setBody(requestMsg); + + requestMsg.setJMSReplyTo(context.getReplyToDestination()); + + return msg; + } catch (JMSException e) { + throw new JMSBindingException(e); + } } + + public Message invokeResponse(Message msg) { + if (msg.getBody() != null){ + Object[] response = (Object[])responseMessageProcessor.extractPayloadFromJMSMessage((javax.jms.Message)msg.getBody()); + if (response != null && response.length > 0){ + msg.setBody(response[0]); + } else { + msg.setBody(null); + } + } + + return msg; + } public Invoker getNext() { return next; diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesReferenceProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesReferenceProvider.java index 0aaca0c909..77bc9509aa 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesReferenceProvider.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesReferenceProvider.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.binding.jms.wireformat.bytes; +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes; import java.util.List; diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesServiceInterceptor.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesServiceInterceptor.java index 39965a56ba..245619b92f 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesServiceInterceptor.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesServiceInterceptor.java @@ -16,12 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.tuscany.sca.binding.jms.wireformat.bytes; +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes; + +import javax.jms.JMSException; +import javax.jms.Session; import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext; import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants; +import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; 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; @@ -43,30 +47,87 @@ public class WireFormatJMSBytesServiceInterceptor implements Interceptor { private JMSBinding jmsBinding; private JMSMessageProcessor requestMessageProcessor; private JMSMessageProcessor responseMessageProcessor; + private WireFormat requestWireFormat; + private WireFormat responseWireFormat; + private String correlationScheme; public WireFormatJMSBytesServiceInterceptor(JMSBinding jmsBinding, JMSResourceFactory jmsResourceFactory, RuntimeWire runtimeWire) { super(); this.jmsBinding = jmsBinding; this.runtimeWire = runtimeWire; this.jmsResourceFactory = jmsResourceFactory; + + if (jmsBinding.getRequestWireFormat() instanceof WireFormatJMSBytes){ + this.requestWireFormat = jmsBinding.getRequestWireFormat(); + this.jmsBinding.setRequestMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME); + } + + if (jmsBinding.getResponseWireFormat() instanceof WireFormatJMSBytes){ + this.responseWireFormat = jmsBinding.getResponseWireFormat(); + this.jmsBinding.setResponseMessageProcessorName(JMSBindingConstants.BYTES_MP_CLASSNAME); + } + this.requestMessageProcessor = JMSMessageProcessorUtil.getRequestMessageProcessor(jmsBinding); this.responseMessageProcessor = JMSMessageProcessorUtil.getResponseMessageProcessor(jmsBinding); + + this.correlationScheme = jmsBinding.getCorrelationScheme(); } public Message invoke(Message msg) { + if (requestWireFormat != null){ + msg = invokeRequest(msg); + } + + msg = getNext().invoke(msg); + + if (responseWireFormat != null){ + msg = invokeResponse(msg); + } + + return msg; + } + + public Message invokeRequest(Message msg) { // get the jms context JMSBindingContext context = (JMSBindingContext)msg.getHeaders().get(JMSBindingConstants.MSG_CTXT_POSITION); javax.jms.Message jmsMsg = context.getJmsMsg(); + + Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg); + msg.setBody(requestPayload); + + return msg; + } + + public Message invokeResponse(Message msg) { + try { + // get the jms context + JMSBindingContext context = (JMSBindingContext)msg.getHeaders().get(JMSBindingConstants.MSG_CTXT_POSITION); + javax.jms.Message requestJMSMsg = context.getJmsMsg(); + Session session = context.getJmsSession(); + + javax.jms.Message responseJMSMsg; + if (msg.isFault()) { + responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody()); + } else { + responseJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, msg.getBody()); + } + + responseJMSMsg.setJMSDeliveryMode(requestJMSMsg.getJMSDeliveryMode()); + responseJMSMsg.setJMSPriority(requestJMSMsg.getJMSPriority()); + + 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()); + } - msg.setBody(requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg)); - - if (next != null){ - return getNext().invoke(msg); - } else { + msg.setBody(responseJMSMsg); + return msg; - } - - } + } catch (JMSException e) { + throw new JMSBindingException(e); + } + } public Invoker getNext() { return next; diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesServiceProvider.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesServiceProvider.java index 059b0e52cb..bbd3feb3c4 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/bytes/WireFormatJMSBytesServiceProvider.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsbytes/WireFormatJMSBytesServiceProvider.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.binding.jms.wireformat.bytes; +package org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes; import java.util.List; diff --git a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java index 6edb6f8b33..7e802f55f5 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java +++ b/java/sca/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/jmsdefault/WireFormatJMSDefault.java @@ -28,7 +28,7 @@ import org.apache.tuscany.sca.assembly.WireFormat; * @version $Rev$ $Date$ */ public class WireFormatJMSDefault implements WireFormat { - public static final QName WIRE_FORMAT_JMS_DEFAULT_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.JMSDefault"); + public static final QName WIRE_FORMAT_JMS_DEFAULT_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "wireFormat.jmsDefault"); public QName getSchemaName() { return WIRE_FORMAT_JMS_DEFAULT_QNAME; diff --git a/java/sca/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor index 6a4fcca25f..1b9020c59b 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor +++ b/java/sca/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -17,4 +17,5 @@ # Implementation class for the artifact processor extension
org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefaultProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#wireFormat.jmsDefault,model=org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault
+org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytesProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wireFormat.jmsBytes,model=org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes
org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefaultProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#operationSelector.jmsDefault,model=org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefault
diff --git a/java/sca/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory b/java/sca/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory index 3658a30bb6..56c07992bd 100644 --- a/java/sca/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory +++ b/java/sca/modules/binding-jms-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory @@ -17,4 +17,4 @@ # Implementation class for the binding extension
org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefaultProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.jmsdefault.WireFormatJMSDefault
-org.apache.tuscany.sca.binding.jms.wireformat.bytes.WireFormatJMSDBytesProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.bytes.WireFormatJMSBytes
+org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytesProviderFactory;model=org.apache.tuscany.sca.binding.jms.wireformat.jmsbytes.WireFormatJMSBytes
diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java index 589bde333b..adb9f29460 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java @@ -60,6 +60,7 @@ public interface JMSBindingConstants { String XML_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.XMLTextMessageProcessor"; String TEXT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.TextMessageProcessor"; String OBJECT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor"; + String BYTES_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.BytesMessageProcessor"; String DEFAULT_MP_CLASSNAME = XML_MP_CLASSNAME; String DEFAULT_OPERATION_PROP_NAME = "scaOperationName"; |