summaryrefslogtreecommitdiffstats
path: root/sandbox/old/contrib/binding-jms/src
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/old/contrib/binding-jms/src')
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/DefaultOperationAndDataBinding.java162
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java177
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingDefinition.java257
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingException.java40
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingLoader.java199
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSProxy.java131
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSReferenceBinding.java75
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSResourceFactory.java38
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSServiceBinding.java100
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSTargetInvoker.java119
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/OperationAndDataBinding.java49
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/SimpleJMSResourceFactory.java114
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/AbstractJmsTransformer.java100
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/Input2JmsInputTransformer.java68
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/JmsInput2InputTransformer.java67
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/JmsOutput2OutputTransformer.java71
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/Output2JmsOutputTransformer.java70
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/resources/META-INF/sca/default.scdl52
-rw-r--r--sandbox/old/contrib/binding-jms/src/main/resources/META-INF/sca/jms.system.scdl52
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/GreetingService.java26
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/GreetingServiceImpl.java27
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/HelloworldService.java26
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/HelloworldServiceImpl.java27
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/IntroService.java23
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/IntroServiceImpl.java36
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSBindingLoaderTestCase.java110
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSBindingTestCaseX.java112
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSProxyTestCase.java89
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/databinding/JmsTransformerTestCase.java64
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/resources/META-INF/sca/default.scdl61
-rw-r--r--sandbox/old/contrib/binding-jms/src/test/resources/wsdl/helloworld.wsdl130
31 files changed, 2672 insertions, 0 deletions
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/DefaultOperationAndDataBinding.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/DefaultOperationAndDataBinding.java
new file mode 100644
index 0000000000..c96bb76b1b
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/DefaultOperationAndDataBinding.java
@@ -0,0 +1,162 @@
+/*
+ * 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.binding.jms;
+
+import java.io.Serializable;
+import java.io.StringReader;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+
+public class DefaultOperationAndDataBinding implements OperationAndDataBinding {
+
+ protected String operationPropertyName;
+
+ private boolean xmlFormat;
+
+ public DefaultOperationAndDataBinding(JMSBindingDefinition jmsBinding) {
+ this.operationPropertyName = jmsBinding.getOperationSelectorPropertyName();
+ this.xmlFormat = jmsBinding.isXMLFormat();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#getOperationName(javax.jms.Message)
+ */
+ public String getOperationName(Message message) {
+ try {
+
+ return message.getStringProperty(operationPropertyName);
+
+ } catch (JMSException e) {
+ throw new JMSBindingException("Exception retreiving operation name from message", e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#setOperationName(javax.jms.Message,
+ * java.lang.String)
+ */
+ public void setOperationName(String operationName, Message message) {
+ try {
+
+ message.setStringProperty(operationPropertyName, operationName);
+
+ } catch (JMSException e) {
+ throw new JMSBindingException("Exception setting the operation name on message", e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#extractPayload(javax.jms.Session,
+ * java.lang.Object)
+ */
+ public Message createJMSMessage(Session session, Object o) {
+ if (xmlFormat) {
+ return createXMLJMSMessage(session, o);
+ } else {
+ return createObjectJMSMessage(session, o);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#extractPayload(javax.jms.Message)
+ */
+ public Object extractPayload(Message msg) {
+ if (xmlFormat) {
+ return extractXMLPayload(msg);
+ } else {
+ return extractObjectPayload(msg);
+ }
+ }
+
+ protected Object extractXMLPayload(Message msg) {
+ try {
+
+ String xml = ((TextMessage)msg).getText();
+
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
+ StAXOMBuilder builder = new StAXOMBuilder(reader);
+ OMElement omElement = builder.getDocumentElement();
+
+ return new Object[] {omElement};
+
+ } catch (XMLStreamException e) {
+ throw new JMSBindingException(e);
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ protected Message createXMLJMSMessage(Session session, Object o) {
+ try {
+
+ TextMessage message = session.createTextMessage();
+
+ if (o instanceof OMElement) {
+ message.setText(o.toString());
+ } else {
+ message.setText(((Object[])o)[0].toString());
+ }
+
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ protected Object extractObjectPayload(Message msg) {
+ try {
+
+ return ((ObjectMessage)msg).getObject();
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ protected Message createObjectJMSMessage(Session session, Object o) {
+ try {
+
+ ObjectMessage message = session.createObjectMessage(); // default
+ message.setObject((Serializable)o);
+ return message;
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java
new file mode 100644
index 0000000000..6b38743b20
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java
@@ -0,0 +1,177 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.binding.jms;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import javax.jms.Destination;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.BindingBuilderExtension;
+import org.apache.tuscany.spi.model.BoundReferenceDefinition;
+import org.apache.tuscany.spi.model.BoundServiceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.tuscany.idl.wsdl.WSDLServiceContract;
+
+/**
+ * Builds a Service or Reference for JMS binding.
+ *
+ * @version $Rev: 449970 $ $Date: 2006-09-26 06:05:35 -0400 (Tue, 26 Sep 2006) $
+ */
+
+public class JMSBindingBuilder extends BindingBuilderExtension<JMSBindingDefinition> {
+
+ private static final String DEFAULT_JMS_RESOURCE_FACTORY =
+ "org.apache.tuscany.binding.jms.SimpleJMSResourceFactory";
+
+ private static final String OM_DATA_BINDING = OMElement.class.getName();
+
+ protected Class<JMSBindingDefinition> getBindingType() {
+ return JMSBindingDefinition.class;
+ }
+
+ public ServiceBinding build(CompositeComponent parent,
+ BoundServiceDefinition serviceDefinition,
+ JMSBindingDefinition jmsBinding,
+ DeploymentContext deploymentContext) {
+
+ Class<?> interfaze = serviceDefinition.getServiceContract().getInterfaceClass();
+
+ ServiceContract serviceContract = serviceDefinition.getServiceContract();
+ jmsBinding.setXMLFormat(serviceContract instanceof WSDLServiceContract);
+
+ JMSResourceFactory jmsResourceFactory = getJMSResourceFactory(jmsBinding);
+
+ if (serviceContract instanceof WSDLServiceContract) {
+ serviceContract.setDataBinding(OM_DATA_BINDING);
+ }
+
+ OperationAndDataBinding requestODB =
+ getRequestOperationAndDatabinding(jmsBinding, deploymentContext.getClassLoader());
+ OperationAndDataBinding responseODB =
+ getRequestOperationAndDatabinding(jmsBinding, deploymentContext.getClassLoader());
+
+ return new JMSServiceBinding(serviceDefinition.getName(), parent, jmsBinding, jmsResourceFactory,
+ serviceContract, requestODB, responseODB, interfaze);
+ }
+
+ public JMSReferenceBinding build(CompositeComponent parent,
+ BoundReferenceDefinition referenceDefinition,
+ JMSBindingDefinition jmsBinding,
+ DeploymentContext deploymentContext) {
+
+ String name = referenceDefinition.getName();
+ ServiceContract serviceContract;
+ try {
+ serviceContract = (ServiceContract) referenceDefinition.getServiceContract().clone();
+ } catch (CloneNotSupportedException e) {
+ throw new JMSBindingException("Couldn't clone the Service Contract", e);
+ }
+ serviceContract.setDataBinding(OM_DATA_BINDING);
+
+ JMSResourceFactory jmsResourceFactory = getJMSResourceFactory(jmsBinding);
+
+ Destination requestDest;
+ Destination replyDest = null;
+ try {
+ requestDest = jmsResourceFactory.lookupDestination(jmsBinding.getDestinationName());
+ if (jmsBinding.getResponseDestinationName() != null) {
+ replyDest = jmsResourceFactory.lookupDestination(jmsBinding.getResponseDestinationName());
+ }
+ } catch (NamingException e) {
+ throw new JMSBindingException(e);
+ }
+
+ OperationAndDataBinding requestODB =
+ getRequestOperationAndDatabinding(jmsBinding, deploymentContext.getClassLoader());
+ OperationAndDataBinding responseODB =
+ getRequestOperationAndDatabinding(jmsBinding, deploymentContext.getClassLoader());
+
+ return new JMSReferenceBinding(name, parent, jmsBinding, jmsResourceFactory, serviceContract, requestODB, responseODB,
+ requestDest, replyDest);
+
+ }
+
+ private JMSResourceFactory getJMSResourceFactory(JMSBindingDefinition jmsBinding) {
+ String className = jmsBinding.getJmsResourceFactoryName();
+ if (className != null && !className.equals("")) {
+ try {
+ Class factoryClass = Class.forName(className != null ? className : DEFAULT_JMS_RESOURCE_FACTORY);
+ Constructor constructor = factoryClass.getDeclaredConstructor(new Class[]{JMSBindingDefinition.class});
+ return (JMSResourceFactory) constructor.newInstance(jmsBinding);
+ } catch (ClassNotFoundException e) {
+ throw new JMSBindingException("Error loading the JMSResourceFactory", e);
+ } catch (SecurityException e) {
+ throw new JMSBindingException("Error loading the JMSResourceFactory", e);
+ } catch (NoSuchMethodException e) {
+ throw new JMSBindingException("Error loading the JMSResourceFactory", e);
+ } catch (IllegalArgumentException e) {
+ throw new JMSBindingException("Error loading the JMSResourceFactory", e);
+ } catch (InstantiationException e) {
+ throw new JMSBindingException("Error loading the JMSResourceFactory", e);
+ } catch (IllegalAccessException e) {
+ throw new JMSBindingException("Error loading the JMSResourceFactory", e);
+ } catch (InvocationTargetException e) {
+ throw new JMSBindingException("Error loading the JMSResourceFactory", e);
+ }
+ } else {
+ return new SimpleJMSResourceFactory(jmsBinding);
+ }
+
+ }
+
+ protected OperationAndDataBinding getRequestOperationAndDatabinding(JMSBindingDefinition jmsBinding,
+ ClassLoader cl) {
+ String className = jmsBinding.getRequestOperationAndDatabindingName();
+ OperationAndDataBinding operationAndDataBinding = instantiateClass(jmsBinding, cl, className);
+ return operationAndDataBinding;
+ }
+
+ protected OperationAndDataBinding getResponseOperationAndDatabinding(JMSBindingDefinition jmsBinding,
+ ClassLoader cl) {
+ String className = jmsBinding.getResponseOperationAndDatabindingName();
+ OperationAndDataBinding operationAndDataBinding = instantiateClass(jmsBinding, cl, className);
+ return operationAndDataBinding;
+ }
+
+ protected OperationAndDataBinding instantiateClass(JMSBindingDefinition jmsBinding, ClassLoader cl,
+ String className) {
+ OperationAndDataBinding operationAndDataBinding;
+ if (cl == null) {
+ cl = this.getClass().getClassLoader();
+ }
+ try {
+ Class clazz;
+ try {
+ clazz = cl.loadClass(className);
+ } catch (ClassNotFoundException e) {
+ clazz = this.getClass().getClassLoader().loadClass(className);
+ }
+ Constructor constructor = clazz.getDeclaredConstructor(new Class[]{JMSBindingDefinition.class});
+ operationAndDataBinding = (OperationAndDataBinding) constructor.newInstance(jmsBinding);
+
+ } catch (Throwable e) {
+ throw new JMSBindingException("Exception instantiating OperationAndDataBinding class", e);
+ }
+ return operationAndDataBinding;
+ }
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingDefinition.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingDefinition.java
new file mode 100644
index 0000000000..96f2599645
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingDefinition.java
@@ -0,0 +1,257 @@
+/*
+ * 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.binding.jms;
+
+import javax.jms.DeliveryMode;
+
+import org.apache.tuscany.spi.model.BindingDefinition;
+
+/**
+ * Represents a binding to a JMS resource.
+ */
+
+public class JMSBindingDefinition extends BindingDefinition {
+
+ public final static int DESTINATION_TYPE_QUEUE = 0;
+ public final static int DESTINATION_TYPE_TOPIC = 1;
+
+ private int destinationType = DESTINATION_TYPE_QUEUE;
+
+ private String destinationName;
+
+ // Topic or Query factory name
+ private String connectionFactoryName;
+
+ private String activationSpecName;
+
+ private String initialContextFactoryName; // "org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+
+ private String jNDIProviderURL; // "tcp://hostname:61616"
+
+ // Maps to javax.jms.DeliveryMode
+ private int deliveryMode = DeliveryMode.NON_PERSISTENT;
+
+ private int timeToLive = 1000; // in mili seconds
+
+ private int priority;
+
+ private String replyTo;
+
+ private String jmsResourceFactoryName;
+
+ private String operationSelectorName;
+
+ private String operationSelectorPropertyName = DEFAULT_OPERATION_PROP_NAME;
+
+ private String correlationScheme;
+ private String responseDestinationName;
+
+ private String requestOperationAndDatabindingName = DEFAULT_ODB_CLASSNAME;
+ private String responseOperationAndDatabindingName = DEFAULT_ODB_CLASSNAME;
+
+ private boolean xmlFormat;
+
+ public static final String DEFAULT_ODB_CLASSNAME = DefaultOperationAndDataBinding.class.getName();
+ public static final String DEFAULT_OPERATION_PROP_NAME = "scaOperationName";
+
+ public JMSBindingDefinition(int destinationType,
+ String destinationName,
+ String connectionFactoryName,
+ String activationSpecName,
+ String initialContextFactoryName,
+ String providerURL,
+ int deliveryMode,
+ int timeToLive,
+ int priority,
+ String replyTo) {
+ super();
+ this.destinationType = destinationType;
+ this.destinationName = destinationName;
+ this.connectionFactoryName = connectionFactoryName;
+ this.activationSpecName = activationSpecName;
+ this.initialContextFactoryName = initialContextFactoryName;
+ this.jNDIProviderURL = providerURL;
+ this.deliveryMode = deliveryMode;
+ this.timeToLive = timeToLive;
+ this.priority = priority;
+ this.replyTo = replyTo;
+ }
+
+ public JMSBindingDefinition() {
+ super();
+ }
+
+ public String getActivationSpecName() {
+ return activationSpecName;
+ }
+
+ public void setActivationSpecName(String activationSpecName) {
+ this.activationSpecName = activationSpecName;
+ }
+
+ public String getConnectionFactoryName() {
+ return connectionFactoryName;
+ }
+
+ public void setConnectionFactoryName(String connectionFactoryName) {
+ this.connectionFactoryName = connectionFactoryName;
+ }
+
+ public int getDeliveryMode() {
+ return deliveryMode;
+ }
+
+ public void setDeliveryMode(int deliveryMode) {
+ this.deliveryMode = deliveryMode;
+ }
+
+ public String getDestinationName() {
+ return destinationName;
+ }
+
+ public void setDestinationName(String destinationName) {
+ this.destinationName = destinationName;
+ }
+
+ public String getInitialContextFactoryName() {
+ return initialContextFactoryName;
+ }
+
+ public void setInitialContextFactoryName(String initialContextFactoryName) {
+ this.initialContextFactoryName = initialContextFactoryName;
+ }
+
+ public String getJNDIProviderURL() {
+ return jNDIProviderURL;
+ }
+
+ public void setJNDIProviderURL(String providerURL) {
+ jNDIProviderURL = providerURL;
+ }
+
+ public int getPriority() {
+ return priority;
+ }
+
+ public void setPriority(int priority) {
+ this.priority = priority;
+ }
+
+ public String getReplyTo() {
+ return replyTo;
+ }
+
+ public void setReplyTo(String replyTo) {
+ this.replyTo = replyTo;
+ }
+
+ public int getTimeToLive() {
+ return timeToLive;
+ }
+
+ public void setTimeToLive(int timeToLive) {
+ this.timeToLive = timeToLive;
+ }
+
+ public int getDestinationType() {
+ return destinationType;
+ }
+
+ public void setDestinationType(int destinationType) {
+ this.destinationType = destinationType;
+ }
+
+ public String getJmsResourceFactoryName() {
+ return jmsResourceFactoryName;
+ }
+
+ public void setJmsResourceFactoryName(String jmsResourceFactoryName) {
+ this.jmsResourceFactoryName = jmsResourceFactoryName;
+ }
+
+ public String getOperationSelectorName() {
+ return operationSelectorName;
+ }
+
+ public void setOperationSelectorName(String operationSelectorName) {
+ this.operationSelectorName = operationSelectorName;
+ }
+
+ public String getOperationSelectorPropertyName() {
+ return operationSelectorPropertyName;
+ }
+
+ public void setOperationSelectorPropertyName(String operationSelectorPropertyName) {
+ this.operationSelectorPropertyName = operationSelectorPropertyName;
+ }
+
+ public void setCorrelationScheme(String correlationScheme) {
+ this.correlationScheme = correlationScheme;
+ }
+
+ public String getCorrelationScheme() {
+ return correlationScheme;
+ }
+
+ public void setCreateDestination(String create) {
+ }
+
+ public void setResponseDestinationName(String name) {
+ this.responseDestinationName = name;
+ }
+
+ public String getResponseDestinationName() {
+ return responseDestinationName;
+ }
+
+ public void setResponseDestinationType(int destination_type_queue2) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setCreateResponseDestination(String create) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setRequestOperationAndDatabindingName(String name) {
+ this.requestOperationAndDatabindingName = name;
+ }
+
+ public String getRequestOperationAndDatabindingName() {
+ return requestOperationAndDatabindingName;
+ }
+
+ public void setResponseOperationAndDatabindingName(String name) {
+ this.responseOperationAndDatabindingName = name;
+ }
+
+ public String getResponseOperationAndDatabindingName() {
+ return responseOperationAndDatabindingName;
+ }
+
+ public boolean isXMLFormat() {
+ return xmlFormat;
+ }
+
+ public void setXMLFormat(boolean b) {
+ this.xmlFormat = b;
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingException.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingException.java
new file mode 100644
index 0000000000..a197eeffc6
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingException.java
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.binding.jms;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+public class JMSBindingException extends TuscanyRuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ public JMSBindingException() {
+ super();
+ }
+
+ public JMSBindingException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+ public JMSBindingException(String arg0) {
+ super(arg0);
+ }
+
+ public JMSBindingException(Throwable arg0) {
+ super(arg0);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingLoader.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingLoader.java
new file mode 100644
index 0000000000..c20b5250f4
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingLoader.java
@@ -0,0 +1,199 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.binding.jms;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * Loader for handling <binding.jms> elements based on the 0.96 draft 1 spec.
+ */
+@Scope("COMPOSITE")
+public class JMSBindingLoader extends LoaderExtension<JMSBindingDefinition> {
+
+ public static final QName BINDING_JMS =
+ new QName(XML_NAMESPACE_1_0, "binding.jms");
+
+ public static final List<String> VALID_CORRELATION_SCHEMES =
+ Arrays.asList(new String[] {"requestmsgidtocorrelid", "requestcorrelidtocorrelid", "none"});
+
+ public JMSBindingLoader(@Autowire LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return BINDING_JMS;
+ }
+
+ public JMSBindingDefinition load(CompositeComponent parent,
+ ModelObject modelObject,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+
+ JMSBindingDefinition jmsBinding = new JMSBindingDefinition();
+
+ String uri = reader.getAttributeValue(null, "uri");
+ if (uri != null && uri.length() > 0) {
+ parseURI(jmsBinding, uri);
+ }
+
+ String correlationScheme = reader.getAttributeValue(null, "correlationScheme");
+ if (correlationScheme != null && correlationScheme.length() > 0) {
+ if (VALID_CORRELATION_SCHEMES.contains(correlationScheme.toLowerCase())) {
+ jmsBinding.setCorrelationScheme(correlationScheme);
+ } else {
+ throw new LoaderException("invalid correlationScheme: " + correlationScheme);
+ }
+ }
+
+ String initialContextFactory = reader.getAttributeValue(null, "initialContextFactory");
+ if (initialContextFactory != null && initialContextFactory.length() > 0) {
+ jmsBinding.setInitialContextFactoryName(initialContextFactory);
+ }
+
+ String jndiProviderURL = reader.getAttributeValue(null, "JNDIProviderURL");
+ if (jndiProviderURL != null && jndiProviderURL.length() > 0) {
+ jmsBinding.setJNDIProviderURL(jndiProviderURL);
+ }
+
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ String elementName = reader.getName().getLocalPart();
+ if ("destination".equals(elementName)) {
+ parseDestination(reader, jmsBinding);
+ } else if ("connectionFactory".equals(elementName)) {
+ parseConnectionFactory(reader, jmsBinding);
+ } else if ("activationSpec".equals(elementName)) {
+ parseActivationSpec(reader, jmsBinding);
+ } else if ("response".equals(elementName)) {
+ parseResponse(reader, jmsBinding);
+ } else if ("headers".equals(elementName)) {
+ parseHeaders(reader, jmsBinding);
+ } else if ("operationAndDataBinding".equals(elementName)) {
+ parseOperationAndDataBinding(reader, jmsBinding);
+ } else if ("operation".equals(elementName)) {
+ parseOperation(reader, jmsBinding);
+ } else if ("resourceAdapter".equals(elementName)) {
+ parseResourceAdapter(reader, jmsBinding);
+ }
+ reader.next();
+ break;
+
+ case END_ELEMENT:
+ QName x = reader.getName();
+ if (x.equals(BINDING_JMS)) {
+ return jmsBinding;
+ }
+ throw new RuntimeException("Incomplete binding.jms definition");
+ }
+ }
+ }
+
+ protected void parseActivationSpec(XMLStreamReader reader, JMSBindingDefinition jmsBinding) {
+ String name = reader.getAttributeValue(null, "name");
+ if (name != null && name.length() > 0) {
+ jmsBinding.setActivationSpecName(name);
+ } else {
+ throw new RuntimeException("missing ActivationSpec name");
+ }
+ }
+
+ protected void parseConnectionFactory(XMLStreamReader reader, JMSBindingDefinition jmsBinding) {
+ String name = reader.getAttributeValue(null, "name");
+ if (name != null && name.length() > 0) {
+ jmsBinding.setConnectionFactoryName(name);
+ } else {
+ throw new RuntimeException("missing connectionFactory name");
+ }
+ }
+
+ protected void parseResponse(XMLStreamReader reader, JMSBindingDefinition jmsBinding) {
+ // TODO Auto-generated method stub
+
+ }
+
+ protected void parseResourceAdapter(XMLStreamReader reader, JMSBindingDefinition jmsBinding) throws XMLStreamException {
+ // TODO Auto-generated method stub
+ }
+
+ protected void parseOperation(XMLStreamReader reader, JMSBindingDefinition jmsBinding) throws XMLStreamException {
+ // TODO Auto-generated method stub
+ }
+
+ protected void parseOperationAndDataBinding(XMLStreamReader reader, JMSBindingDefinition jmsBinding)
+ throws XMLStreamException {
+ String name = reader.getAttributeValue(null, "name");
+ String use = reader.getAttributeValue(null, "use");
+ if (name != null && name.length() > 0) {
+ if ("request".equalsIgnoreCase(use)) {
+ jmsBinding.setRequestOperationAndDatabindingName(name);
+ } else if ("response".equalsIgnoreCase(use)) {
+ jmsBinding.setResponseOperationAndDatabindingName(name);
+ } else {
+ jmsBinding.setRequestOperationAndDatabindingName(name);
+ jmsBinding.setResponseOperationAndDatabindingName(name);
+ }
+ }
+ }
+
+ protected void parseHeaders(XMLStreamReader reader, JMSBindingDefinition jmsBinding) throws XMLStreamException {
+ // TODO Auto-generated method stub
+ }
+
+ protected void parseDestination(XMLStreamReader reader, JMSBindingDefinition jmsBinding) throws XMLStreamException {
+ String name = reader.getAttributeValue(null, "name");
+ if (name != null && name.length() > 0) {
+ jmsBinding.setDestinationName(name);
+ }
+ String type = reader.getAttributeValue(null, "type");
+ if (type != null && type.length() > 0) {
+ if ("queue".equalsIgnoreCase(type)) {
+ jmsBinding.setDestinationType(JMSBindingDefinition.DESTINATION_TYPE_QUEUE);
+ } else if ("topic".equalsIgnoreCase("type")) {
+ jmsBinding.setDestinationType(JMSBindingDefinition.DESTINATION_TYPE_TOPIC);
+ } else {
+ throw new RuntimeException("invalid destination type: " + type);
+ }
+ }
+ String create = reader.getAttributeValue(null, "create");
+ if (create != null && create.length() > 0) {
+ jmsBinding.setCreateDestination(create);
+ }
+ }
+
+ protected void parseURI(JMSBindingDefinition jmsBinding, String uri) {
+ // TODO Auto-generated method stub
+ }
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSProxy.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSProxy.java
new file mode 100644
index 0000000000..56e367eca2
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSProxy.java
@@ -0,0 +1,131 @@
+/*
+ * 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.binding.jms;
+
+import java.lang.reflect.Method;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+public class JMSProxy implements MessageListener {
+
+ protected Method operationMethod;
+ protected JMSResourceFactory jmsResourceFactory;
+ protected OperationAndDataBinding requestOperationAndDataBinding;
+ protected OperationAndDataBinding responseOperationAndDataBinding;
+ protected InboundWire inboundWire;
+ protected String correlationScheme;
+
+ public JMSProxy(InboundWire inboundWire,
+ JMSResourceFactory jmsResourceFactory,
+ OperationAndDataBinding requestOperationAndDataBinding,
+ OperationAndDataBinding responseOperationAndDataBinding,
+ String correlationScheme) throws NamingException {
+
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestOperationAndDataBinding = requestOperationAndDataBinding;
+ this.responseOperationAndDataBinding = responseOperationAndDataBinding;
+ this.inboundWire = inboundWire;
+ this.correlationScheme = correlationScheme;
+ }
+
+ public void onMessage(Message requestJMSMsg) {
+ try {
+ Object responsePayload = invokeService(requestJMSMsg);
+ sendReply(requestJMSMsg, responsePayload);
+ } catch (Exception e) {
+ sendFaultReply(requestJMSMsg, e);
+ }
+ }
+
+ protected Object invokeService(Message requestJMSMsg) throws JMSException {
+
+ String operationName = requestOperationAndDataBinding.getOperationName(requestJMSMsg);
+ Object requestPayload = requestOperationAndDataBinding.extractPayload(requestJMSMsg);
+
+ Operation op = (Operation)inboundWire.getServiceContract().getOperations().get(operationName);
+ InvocationChain chain = inboundWire.getInvocationChains().get(op);
+
+ org.apache.tuscany.spi.wire.Message tuscanyRequestMsg = new MessageImpl();
+ tuscanyRequestMsg.setTargetInvoker(chain.getTargetInvoker());
+ tuscanyRequestMsg.setBody(requestPayload);
+
+ org.apache.tuscany.spi.wire.Message tuscanyResponseMsg = null;
+
+ Interceptor headInterceptor = chain.getHeadInterceptor();
+ if (headInterceptor != null) {
+ tuscanyResponseMsg = headInterceptor.invoke(tuscanyRequestMsg);
+ }
+
+ // TODO: what if headInterceptor is null?
+
+ return tuscanyResponseMsg.getBody();
+ }
+
+ protected void sendReply(Message requestJMSMsg, Object responsePayload) {
+ try {
+
+ if (requestJMSMsg.getJMSReplyTo() == null) {
+ // assume no reply is expected
+ return;
+ }
+
+ Session session = jmsResourceFactory.createSession();
+ Message replyJMSMsg = responseOperationAndDataBinding.createJMSMessage(session, responsePayload);
+
+ replyJMSMsg.setJMSDeliveryMode(requestJMSMsg.getJMSDeliveryMode());
+ replyJMSMsg.setJMSPriority(requestJMSMsg.getJMSPriority());
+
+ if (correlationScheme == null || "RequestMsgIDToCorrelID".equalsIgnoreCase(correlationScheme)) {
+ replyJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSMessageID());
+ } else if ("RequestCorrelIDToCorrelID".equalsIgnoreCase(correlationScheme)) {
+ replyJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSCorrelationID());
+ }
+
+ Destination destination = requestJMSMsg.getJMSReplyTo();
+ MessageProducer producer = session.createProducer(destination);
+
+ producer.send(replyJMSMsg);
+
+ producer.close();
+ session.close();
+
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ } catch (NamingException e) {
+ throw new JMSBindingException(e);
+ }
+ }
+
+ protected void sendFaultReply(Message requestJMSMsg, Exception e) {
+ sendReply(requestJMSMsg, new JMSBindingException("exception invoking JMS service", e));
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSReferenceBinding.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSReferenceBinding.java
new file mode 100644
index 0000000000..3aa0bf31eb
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSReferenceBinding.java
@@ -0,0 +1,75 @@
+/*
+ * 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.binding.jms;
+
+import javax.jms.Destination;
+import javax.xml.namespace.QName;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.extension.ReferenceBindingExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * @version $Rev: 449970 $ $Date: 2006-09-26 06:05:35 -0400 (Tue, 26 Sep 2006) $
+ */
+public class JMSReferenceBinding extends ReferenceBindingExtension {
+ private static final QName BINDING_JMS = new QName(XML_NAMESPACE_1_0, "binding.jms");
+
+ protected JMSBindingDefinition jmsBinding;
+ protected JMSResourceFactory jmsResourceFactory;
+ protected OperationAndDataBinding requestOperationAndDataBinding;
+ protected OperationAndDataBinding responseOperationAndDataBinding;
+ protected Destination requestDest;
+ protected Destination replyDest;
+
+ public JMSReferenceBinding(String name,
+ CompositeComponent parent,
+ JMSBindingDefinition jmsBinding,
+ JMSResourceFactory jmsResourceFactory,
+ ServiceContract<?> bindingServiceContract,
+ OperationAndDataBinding requestOperationAndDataBinding,
+ OperationAndDataBinding responseOperationAndDataBinding,
+ Destination requestDest,
+ Destination replyDest) {
+
+ super(name, parent);
+ this.bindingServiceContract = bindingServiceContract;
+ this.jmsBinding = jmsBinding;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.requestOperationAndDataBinding = requestOperationAndDataBinding;
+ this.responseOperationAndDataBinding = responseOperationAndDataBinding;
+ this.requestDest = requestDest;
+ this.replyDest = replyDest;
+ }
+
+ public QName getBindingType() {
+ return BINDING_JMS;
+ }
+
+ public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) {
+ return new JMSTargetInvoker(jmsResourceFactory, jmsBinding, operation.getName(),
+ requestOperationAndDataBinding, responseOperationAndDataBinding, requestDest,
+ replyDest);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSResourceFactory.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSResourceFactory.java
new file mode 100644
index 0000000000..dbc43a6d34
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSResourceFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.binding.jms;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+public interface JMSResourceFactory {
+
+ public abstract Connection getConnection() throws NamingException, JMSException;
+
+ public abstract Session createSession() throws JMSException, NamingException;
+
+ public abstract void startConnection() throws JMSException, NamingException;
+
+ public abstract void closeConnection() throws JMSException, NamingException;
+
+ public abstract Destination lookupDestination(String jndiName) throws NamingException;
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSServiceBinding.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSServiceBinding.java
new file mode 100644
index 0000000000..16cf6efe39
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSServiceBinding.java
@@ -0,0 +1,100 @@
+/*
+ * 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.binding.jms;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.naming.NamingException;
+import javax.xml.namespace.QName;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.extension.ServiceBindingExtension;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * @version $Rev: 449970 $ $Date: 2006-09-26 06:05:35 -0400 (Tue, 26 Sep 2006) $
+ */
+public class JMSServiceBinding extends ServiceBindingExtension {
+ private static final QName BINDING_JMS = new QName(XML_NAMESPACE_1_0, "binding.jms");
+
+ private JMSBindingDefinition jmsBinding;
+ private JMSResourceFactory jmsResourceFactory;
+ private MessageConsumer consumer;
+ protected OperationAndDataBinding requestOperationAndDataBinding;
+ protected OperationAndDataBinding responseOperationAndDataBinding;
+
+ public JMSServiceBinding(String name,
+ CompositeComponent parent,
+ JMSBindingDefinition jmsBinding,
+ JMSResourceFactory jmsResourceFactory,
+ ServiceContract<?> serviceBindingContract,
+ OperationAndDataBinding requestOperationAndDataBinding,
+ OperationAndDataBinding responseOperationAndDataBinding,
+ Class<?> service) {
+ super(name, parent);
+
+ this.jmsBinding = jmsBinding;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.bindingServiceContract = serviceBindingContract;
+ this.requestOperationAndDataBinding = requestOperationAndDataBinding;
+ this.responseOperationAndDataBinding = responseOperationAndDataBinding;
+ }
+
+ public void start() {
+ super.start();
+ try {
+ registerListerner();
+ } catch (Exception e) {
+ throw new JMSBindingException("Error starting JMSServiceBinding", e);
+ }
+ }
+
+ public void stop() {
+
+ try {
+ consumer.close();
+ jmsResourceFactory.closeConnection();
+ } catch (Exception e) {
+ throw new JMSBindingException("Error stopping JMSServiceBinding", e);
+ }
+
+ super.stop();
+ }
+
+ private void registerListerner() throws NamingException, JMSException {
+
+ Session session = jmsResourceFactory.createSession();
+ Destination destination = session.createQueue(jmsBinding.getDestinationName());
+
+ consumer = session.createConsumer(destination);
+ consumer.setMessageListener(new JMSProxy(getInboundWire(), jmsResourceFactory, requestOperationAndDataBinding,
+ responseOperationAndDataBinding, jmsBinding.getCorrelationScheme()));
+
+ jmsResourceFactory.startConnection();
+
+ }
+
+ public QName getBindingType() {
+ return BINDING_JMS;
+ }
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSTargetInvoker.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSTargetInvoker.java
new file mode 100644
index 0000000000..61e838c41a
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/JMSTargetInvoker.java
@@ -0,0 +1,119 @@
+/*
+ * 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.binding.jms;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.spi.extension.TargetInvokerExtension;
+
+/**
+ * Invoke a JMS reference.
+ */
+public class JMSTargetInvoker extends TargetInvokerExtension {
+
+ protected JMSBindingDefinition jmsBinding;
+ protected JMSResourceFactory jmsResourceFactory;
+
+ protected String operationName;
+ protected OperationAndDataBinding requestOperationAndDataBinding;
+ protected OperationAndDataBinding responseOperationAndDataBinding;
+
+ protected Destination requestDest;
+ protected Destination replyDest;
+
+ public JMSTargetInvoker(JMSResourceFactory jmsResourceFactory,
+ JMSBindingDefinition jmsBinding,
+ String operationName,
+ OperationAndDataBinding requestOperationAndDataBinding,
+ OperationAndDataBinding responseOperationAndDataBinding,
+ Destination requestDest,
+ Destination replyDest) {
+ super(null, null, null);
+ this.jmsBinding = jmsBinding;
+ this.jmsResourceFactory = jmsResourceFactory;
+ this.operationName = operationName;
+ this.requestOperationAndDataBinding = requestOperationAndDataBinding;
+ this.responseOperationAndDataBinding = responseOperationAndDataBinding;
+ this.requestDest = requestDest;
+ this.replyDest = replyDest;
+ }
+
+ public Object invokeTarget(Object payload, final short sequence) throws InvocationTargetException {
+ try {
+ Session session = jmsResourceFactory.createSession();
+ try {
+
+ Destination replyToDest = (replyDest != null) ? replyDest : session.createTemporaryQueue();
+ Message requestMsg = sendRequest((Object[])payload, session, replyToDest);
+ Message replyMsg = receiveReply(session, replyToDest, requestMsg.getJMSMessageID());
+
+ return responseOperationAndDataBinding.extractPayload(replyMsg);
+
+ } finally {
+ session.close();
+ }
+ } catch (JMSException e) {
+ throw new InvocationTargetException(e);
+ } catch (NamingException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ protected Message sendRequest(Object[] payload, Session session, Destination replyToDest) throws JMSException {
+
+ Message requestMsg = requestOperationAndDataBinding.createJMSMessage(session, payload);
+
+ requestMsg.setJMSDeliveryMode(jmsBinding.getDeliveryMode());
+ requestMsg.setJMSPriority(jmsBinding.getPriority());
+
+ requestOperationAndDataBinding.setOperationName(operationName, requestMsg);
+ requestMsg.setJMSReplyTo(replyToDest);
+
+ MessageProducer producer = session.createProducer(requestDest);
+ try {
+ producer.send(requestMsg);
+ } finally {
+ producer.close();
+ }
+ return requestMsg;
+ }
+
+ protected Message receiveReply(Session session, Destination replyToDest, String requestMsgId) throws JMSException,
+ NamingException {
+ String msgSelector = "JMSCorrelationID = '" + requestMsgId + "'";
+ MessageConsumer consumer = session.createConsumer(replyToDest, msgSelector);
+ Message replyMsg;
+ try {
+ jmsResourceFactory.startConnection();
+ replyMsg = consumer.receive(jmsBinding.getTimeToLive());
+ } finally {
+ consumer.close();
+ }
+ return replyMsg;
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/OperationAndDataBinding.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/OperationAndDataBinding.java
new file mode 100644
index 0000000000..9867f7d97b
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/OperationAndDataBinding.java
@@ -0,0 +1,49 @@
+/*
+ * 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.binding.jms;
+
+import javax.jms.Message;
+import javax.jms.Session;
+
+/**
+ * Interface for a component that does operation selection and message payload
+ * databinding
+ */
+public interface OperationAndDataBinding {
+
+ /**
+ * Get the operation name from a JMS Message
+ */
+ public abstract String getOperationName(Message message);
+
+ /**
+ * Set the operation name on a JMS Message
+ */
+ public abstract void setOperationName(String operationName, Message message);
+
+ /**
+ * Extracts the payload from a JMS Message
+ */
+ public abstract Object extractPayload(Message msg);
+
+ /**
+ * Create a JMS Message containing the payload
+ */
+ public abstract Message createJMSMessage(Session session, Object payload);
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/SimpleJMSResourceFactory.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/SimpleJMSResourceFactory.java
new file mode 100644
index 0000000000..86cdfa272e
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/SimpleJMSResourceFactory.java
@@ -0,0 +1,114 @@
+/*
+ * 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.binding.jms;
+
+import java.util.Properties;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+public class SimpleJMSResourceFactory implements JMSResourceFactory {
+
+ private JMSBindingDefinition jmsBinding;
+ private Connection con;
+ private Context context;
+ private boolean isConnectionStarted;
+
+ public SimpleJMSResourceFactory(JMSBindingDefinition jmsBinding) {
+ this.jmsBinding = jmsBinding;
+ }
+
+ /*
+ * This is a simple implementation where a connection is created per binding
+ * Ideally the resource factory should be able to leverage the host
+ * environment to provide connection pooling if it can. For ex If Tuscany is
+ * running inside an AppServer Then we could leverage the JMS resources it
+ * provides
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#getConnection()
+ */
+ public Connection getConnection() throws NamingException, JMSException {
+ if (con == null) {
+ createConnection();
+ }
+ return con;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createSession()
+ */
+ public Session createSession() throws JMSException, NamingException {
+ return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#startConnection()
+ */
+ public void startConnection() throws JMSException, NamingException {
+ if (!isConnectionStarted) {
+ getConnection().start();
+ isConnectionStarted = true;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#closeConnection()
+ */
+ public void closeConnection() throws JMSException, NamingException {
+ if (con != null) {
+ con.close();
+ }
+ }
+
+ private void createConnection() throws NamingException, JMSException {
+ if (context == null) {
+ createInitialContext();
+ }
+ ConnectionFactory conFac = (ConnectionFactory)context.lookup(jmsBinding.getConnectionFactoryName());
+ con = conFac.createConnection();
+ }
+
+ private void createInitialContext() throws NamingException {
+ Properties props = new Properties();
+ props.setProperty(Context.INITIAL_CONTEXT_FACTORY, jmsBinding.getInitialContextFactoryName().trim());
+ props.setProperty(Context.PROVIDER_URL, jmsBinding.getJNDIProviderURL().trim());
+
+ context = new InitialContext(props);
+ }
+
+ public Destination lookupDestination(String jndiName) throws NamingException {
+ if (context == null) {
+ createInitialContext();
+ }
+ return (Destination)context.lookup(jndiName);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/AbstractJmsTransformer.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/AbstractJmsTransformer.java
new file mode 100644
index 0000000000..eb6e068462
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/AbstractJmsTransformer.java
@@ -0,0 +1,100 @@
+/*
+ * 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.binding.jms.databinding;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+
+/**
+ * This is a special transformer to transform the input from one IDL to the
+ * other one
+ */
+public abstract class AbstractJmsTransformer<T> extends TransformerExtension<T, T> implements PullTransformer<T, T> {
+
+ protected static final String IDL_INPUT = "idl:input";
+ protected static final String JMS_INPUT = "jms:input";
+ protected static final String IDL_OUTPUT = "idl:output";
+ protected static final String JMS_OUTPUT = "jms:output";
+
+ protected DataBindingRegistry dataBindingRegistry;
+
+ protected Mediator mediator;
+
+ public AbstractJmsTransformer() {
+ super();
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.Transformer#getWeight()
+ */
+ public int getWeight() {
+ return 10;
+ }
+
+ protected Object read(byte[] bytes) {
+ try {
+ ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bis) {
+
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ try {
+ return Class.forName(desc.getName(), false, this.getClass().getClassLoader());
+ } catch (ClassNotFoundException e) {
+ return super.resolveClass(desc);
+ }
+ }
+
+ };
+ Object object = ois.readObject();
+ ois.close();
+ bis.close();
+
+ return object;
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ protected byte[] write(Object source) {
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(source);
+ oos.close();
+ bos.close();
+ return bos.toByteArray();
+ } catch (IOException e) {
+ throw new TransformationException(e);
+ }
+
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/Input2JmsInputTransformer.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/Input2JmsInputTransformer.java
new file mode 100644
index 0000000000..30add8e082
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/Input2JmsInputTransformer.java
@@ -0,0 +1,68 @@
+/*
+ * 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.binding.jms.databinding;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * This is a special transformer to transform the input from one IDL to the
+ * other one
+ */
+@Service(Transformer.class)
+public class Input2JmsInputTransformer extends AbstractJmsTransformer<Object[]> {
+
+ public Input2JmsInputTransformer() {
+ super();
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return IDL_INPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return JMS_INPUT;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Object[].class;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] transform(Object[] source, TransformationContext context) {
+ return new Object[] {write(source)};
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/JmsInput2InputTransformer.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/JmsInput2InputTransformer.java
new file mode 100644
index 0000000000..65f84d1383
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/JmsInput2InputTransformer.java
@@ -0,0 +1,67 @@
+/*
+ * 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.binding.jms.databinding;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * This is a special transformer to transform the input from one IDL to the
+ * other one
+ */
+@Service(Transformer.class)
+public class JmsInput2InputTransformer extends AbstractJmsTransformer<Object[]> {
+
+ public JmsInput2InputTransformer() {
+ super();
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return JMS_INPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return IDL_INPUT;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Object[].class;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] transform(Object[] source, TransformationContext context) {
+ return (Object[])read((byte[])source[0]);
+ }
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/JmsOutput2OutputTransformer.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/JmsOutput2OutputTransformer.java
new file mode 100644
index 0000000000..1696609743
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/JmsOutput2OutputTransformer.java
@@ -0,0 +1,71 @@
+/*
+ * 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.binding.jms.databinding;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ */
+@Service(Transformer.class)
+public class JmsOutput2OutputTransformer extends AbstractJmsTransformer<Object> {
+
+ /**
+ * @param wrapperHandler
+ */
+ public JmsOutput2OutputTransformer() {
+ super();
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return JMS_OUTPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return IDL_OUTPUT;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Object.class;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object transform(Object response, TransformationContext context) {
+ return read((byte[])response);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/Output2JmsOutputTransformer.java b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/Output2JmsOutputTransformer.java
new file mode 100644
index 0000000000..5a82f912c5
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/java/org/apache/tuscany/binding/jms/databinding/Output2JmsOutputTransformer.java
@@ -0,0 +1,70 @@
+/*
+ * 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.binding.jms.databinding;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ */
+@Service(Transformer.class)
+public class Output2JmsOutputTransformer extends AbstractJmsTransformer<Object> {
+ /**
+ * @param wrapperHandler
+ */
+ public Output2JmsOutputTransformer() {
+ super();
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return IDL_OUTPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return JMS_OUTPUT;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Object.class;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object transform(Object response, TransformationContext context) {
+ return write(response);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/main/resources/META-INF/sca/default.scdl b/sandbox/old/contrib/binding-jms/src/main/resources/META-INF/sca/default.scdl
new file mode 100644
index 0000000000..0c99331b4f
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/resources/META-INF/sca/default.scdl
@@ -0,0 +1,52 @@
+<!--
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.binding.jms.JMSBinding">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.extensions.jms</group>
+ <name>tuscany-jms</name>
+ <version>1.0-incubator-SNAPSHOT</version>
+ </dependency>
+
+ <component name="jms.bindingLoader">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.JMSBindingLoader" />
+ </component>
+
+ <component name="jms.bindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.JMSBindingBuilder" />
+ </component>
+
+ <!-- Transformers -->
+
+ <component name="transformer.JmsInput2InputTransformer">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.databinding.JmsInput2InputTransformer" />
+ </component>
+
+ <component name="transformer.JmsOutput2OutputTransformer">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.databinding.JmsOutput2OutputTransformer" />
+ </component>
+
+ <component name="transformer.Input2JmsInputTransformer">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.databinding.Input2JmsInputTransformer" />
+ </component>
+
+ <component name="transformer.Output2JmsOutputTransformer">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.databinding.Output2JmsOutputTransformer" />
+ </component>
+
+</composite>
diff --git a/sandbox/old/contrib/binding-jms/src/main/resources/META-INF/sca/jms.system.scdl b/sandbox/old/contrib/binding-jms/src/main/resources/META-INF/sca/jms.system.scdl
new file mode 100644
index 0000000000..9f01162f5d
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/main/resources/META-INF/sca/jms.system.scdl
@@ -0,0 +1,52 @@
+<!--
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.binding.jms.JMSBinding">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.extensions.jms</group>
+ <name>tuscany-jms</name>
+ <version>1.0-incubator-SNAPSHOT</version>
+ </dependency>
+
+ <component name="jms.bindingLoader">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.JMSBindingLoader" />
+ </component>
+
+ <component name="jms.bindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.JMSBindingBuilder" />
+ </component>
+
+ <!-- Transformers -->
+
+ <component name="transformer.JmsInput2InputTransformer">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.databinding.JmsInput2InputTransformer" />
+ </component>
+
+ <component name="transformer.JmsOutput2OutputTransformer">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.databinding.JmsOutput2OutputTransformer" />
+ </component>
+
+ <component name="transformer.Input2JmsInputTransformer">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.databinding.Input2JmsInputTransformer" />
+ </component>
+
+ <component name="transformer.Output2JmsOutputTransformer">
+ <system:implementation.system class="org.apache.tuscany.binding.jms.databinding.Output2JmsOutputTransformer" />
+ </component>
+
+</composite>
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/GreetingService.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/GreetingService.java
new file mode 100644
index 0000000000..24472afa53
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/GreetingService.java
@@ -0,0 +1,26 @@
+/*
+ * 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.binding.jms;
+
+import org.osoa.sca.annotations.Remotable;
+
+@Remotable
+public interface GreetingService {
+ String greet(String name);
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/GreetingServiceImpl.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/GreetingServiceImpl.java
new file mode 100644
index 0000000000..abf7ecef88
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/GreetingServiceImpl.java
@@ -0,0 +1,27 @@
+/*
+ * 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.binding.jms;
+
+public class GreetingServiceImpl implements GreetingService {
+
+ public String greet(String name) {
+ return "Hello " + name;
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/HelloworldService.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/HelloworldService.java
new file mode 100644
index 0000000000..21c40bd6b6
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/HelloworldService.java
@@ -0,0 +1,26 @@
+/*
+ * 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.binding.jms;
+
+import org.osoa.sca.annotations.Remotable;
+
+@Remotable
+public interface HelloworldService {
+ String getGreetings(String name);
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/HelloworldServiceImpl.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/HelloworldServiceImpl.java
new file mode 100644
index 0000000000..8119bde323
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/HelloworldServiceImpl.java
@@ -0,0 +1,27 @@
+/*
+ * 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.binding.jms;
+
+public class HelloworldServiceImpl implements HelloworldService {
+
+ public String getGreetings(String name) {
+ return "Hello " + name;
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/IntroService.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/IntroService.java
new file mode 100644
index 0000000000..0b5acb44cc
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/IntroService.java
@@ -0,0 +1,23 @@
+/*
+ * 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.binding.jms;
+
+public interface IntroService {
+ public String greet(String name);
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/IntroServiceImpl.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/IntroServiceImpl.java
new file mode 100644
index 0000000000..6222f368ad
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/IntroServiceImpl.java
@@ -0,0 +1,36 @@
+/*
+ * 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.binding.jms;
+
+import org.osoa.sca.annotations.Reference;
+
+public class IntroServiceImpl implements IntroService {
+
+ private GreetingService extService;
+
+ @Reference
+ public void setExtService(GreetingService extService) {
+ this.extService = extService;
+ }
+
+ public String greet(String name) {
+ return extService.greet(name);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSBindingLoaderTestCase.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSBindingLoaderTestCase.java
new file mode 100644
index 0000000000..d2bf4bfcda
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSBindingLoaderTestCase.java
@@ -0,0 +1,110 @@
+/*
+ * 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.binding.jms;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+public class JMSBindingLoaderTestCase extends TestCase {
+
+ private JMSBindingLoader loader;
+
+ public void testMinimal() throws LoaderException, XMLStreamException {
+ String xml = "<binding.jms></binding.jms>";
+ XMLStreamReader reader = createReader(xml);
+ JMSBindingDefinition jmsBinding = loader.load(null, null, reader, null);
+ assertNotNull(jmsBinding);
+ }
+
+ public void testCorrelationScheme() throws LoaderException, XMLStreamException {
+ XMLStreamReader reader =
+ createReader("<binding.jms correlationScheme=\"RequestMsgIDToCorrelID\"></binding.jms>");
+ JMSBindingDefinition jmsBinding = loader.load(null, null, reader, null);
+ assertEquals("RequestMsgIDToCorrelID", jmsBinding.getCorrelationScheme());
+
+ reader = createReader("<binding.jms correlationScheme=\"RequestCorrelIDToCorrelID\"></binding.jms>");
+ jmsBinding = loader.load(null, null, reader, null);
+ assertEquals("RequestCorrelIDToCorrelID", jmsBinding.getCorrelationScheme());
+
+ reader = createReader("<binding.jms correlationScheme=\"none\"></binding.jms>");
+ jmsBinding = loader.load(null, null, reader, null);
+ assertEquals("none", jmsBinding.getCorrelationScheme());
+
+ reader = createReader("<binding.jms correlationScheme=\"xxx\"></binding.jms>");
+ try {
+ jmsBinding = loader.load(null, null, reader, null);
+ fail("expecting invalid correlationScheme");
+ } catch (LoaderException e) {
+ // expected
+ }
+ }
+
+ public void testDestination() throws LoaderException, XMLStreamException {
+ XMLStreamReader reader = createReader("<binding.jms><destination name=\"foo\"/></binding.jms>");
+ JMSBindingDefinition jmsBinding = loader.load(null, null, reader, null);
+ assertEquals("foo", jmsBinding.getDestinationName());
+ }
+
+ public void testInitialContextFactory() throws LoaderException, XMLStreamException {
+ XMLStreamReader reader = createReader("<binding.jms initialContextFactory=\"myicf\"></binding.jms>");
+ JMSBindingDefinition jmsBinding = loader.load(null, null, reader, null);
+ assertEquals("myicf", jmsBinding.getInitialContextFactoryName());
+ }
+
+ public void testJNDIProviderURL() throws LoaderException, XMLStreamException {
+ XMLStreamReader reader = createReader("<binding.jms JNDIProviderURL=\"myURL\"></binding.jms>");
+ JMSBindingDefinition jmsBinding = loader.load(null, null, reader, null);
+ assertEquals("myURL", jmsBinding.getJNDIProviderURL());
+ }
+
+ public void testConnectionFactory() throws LoaderException, XMLStreamException {
+ XMLStreamReader reader = createReader("<binding.jms> <connectionFactory name=\"myfactory\"/> </binding.jms>");
+ JMSBindingDefinition jmsBinding = loader.load(null, null, reader, null);
+ assertEquals("myfactory", jmsBinding.getConnectionFactoryName());
+ }
+
+ public void testActivationSpec() throws LoaderException, XMLStreamException {
+ XMLStreamReader reader = createReader("<binding.jms> <activationSpec name=\"myas\"/></binding.jms>");
+ JMSBindingDefinition jmsBinding = loader.load(null, null, reader, null);
+ assertEquals("myas", jmsBinding.getActivationSpecName());
+ }
+
+ private XMLStreamReader createReader(String xml) throws XMLStreamException {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+
+ String xxx = "<xxx xmlns=\"" + XML_NAMESPACE_1_0 + "\">" + xml + "</xxx>";
+ XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xxx));
+ reader.nextTag();
+ reader.nextTag();
+ return reader;
+ }
+
+ protected void setUp() throws Exception {
+ this.loader = new JMSBindingLoader(null);
+ }
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSBindingTestCaseX.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSBindingTestCaseX.java
new file mode 100644
index 0000000000..115c88f8b7
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSBindingTestCaseX.java
@@ -0,0 +1,112 @@
+/*
+ * 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.binding.jms;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.naming.NamingException;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.activemq.broker.BrokerContainer;
+import org.activemq.broker.impl.BrokerContainerImpl;
+import org.activemq.store.vm.VMPersistenceAdapter;
+import org.apache.tuscany.test.SCATestCase;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.CurrentCompositeContext;
+import org.xml.sax.SAXException;
+
+public class JMSBindingTestCaseX extends SCATestCase {
+
+ private IntroService introService;
+ private BrokerContainer broker;
+
+ protected static final String REQUEST_XML =
+ "<ns:getGreetings xmlns:ns=\"http://helloworld\"><ns:name>petra</ns:name></ns:getGreetings>";
+ protected static final String REPLY_XML =
+ "<ns1:getGreetingsResponse xmlns:ns1=\"http://helloworld\"><ns1:getGreetingsReturn>Hello petra</ns1:getGreetingsReturn></ns1:getGreetingsResponse>";
+
+ public void testJMSBinding() throws InvocationTargetException, SAXException, IOException,
+ ParserConfigurationException, NamingException, JMSException {
+ String reply = introService.greet("Rajith");
+ assertEquals("Hello Rajith", reply);
+
+ // TODO: the rest should be in a seperate test method but that doesn't
+ // work as you get broker conflicts
+ JMSTargetInvoker invoker = createJMSInvoker();
+ Object[] response = (Object[])invoker.invokeTarget(new Object[] {REQUEST_XML}, (short)0);
+
+ Diff diff = XMLUnit.compareXML(REPLY_XML, response[0].toString());
+ assertTrue(diff.toString(), diff.similar());
+
+ }
+
+ private JMSTargetInvoker createJMSInvoker() throws NamingException, JMSException {
+ JMSBindingDefinition binding = new JMSBindingDefinition();
+ binding.setInitialContextFactoryName("org.activemq.jndi.ActiveMQInitialContextFactory");
+ binding.setConnectionFactoryName("ConnectionFactory");
+ binding.setJNDIProviderURL("tcp://localhost:61616");
+ binding.setDestinationName("dynamicQueues/HelloworldServiceQueue");
+ binding.setTimeToLive(3000);
+ binding.setXMLFormat(true);
+ JMSResourceFactory rf = new SimpleJMSResourceFactory(binding);
+ Destination requestDest = rf.lookupDestination(binding.getDestinationName());
+ DefaultOperationAndDataBinding odb = new DefaultOperationAndDataBinding(binding);
+ JMSTargetInvoker invoker = new JMSTargetInvoker(rf, binding, "getGreetings", odb, odb, requestDest, null);
+ return invoker;
+ }
+
+ protected void setUp() throws Exception {
+ startBroker();
+ setApplicationSCDL(IntroService.class, "META-INF/sca/default.scdl");
+ addExtension("jms.binding", getClass().getClassLoader().getResource("META-INF/sca/jms.system.scdl"));
+ addExtension("idl.wsdl", getClass().getClassLoader().getResource("META-INF/sca/idl.wsdl.scdl"));
+ addExtension("databinding.axiom", getClass().getResource("/META-INF/sca/databinding.axiom.scdl"));
+ super.setUp();
+ CompositeContext context = CurrentCompositeContext.getContext();
+ introService = context.locateService(IntroService.class, "IntroServiceComponent");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ broker.stop();
+ }
+
+ public static void main(String[] args) {
+ JMSBindingTestCaseX test = new JMSBindingTestCaseX();
+ try {
+ test.setUp();
+ test.testJMSBinding();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void startBroker() throws Exception {
+ broker = new BrokerContainerImpl("JMS BindingDefinition Test");
+ // configure the broker
+ broker.addConnector("tcp://localhost:61616");
+ broker.setPersistenceAdapter(new VMPersistenceAdapter());
+ broker.start();
+ }
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSProxyTestCase.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSProxyTestCase.java
new file mode 100644
index 0000000000..63a82ab6da
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/JMSProxyTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * 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.binding.jms;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+
+public class JMSProxyTestCase extends TestCase {
+
+ /**
+ * Tests the jms response msg has correlation id set to the request msg id
+ */
+ public void testOnMessageRequestMsgIDToCorrelID() throws NamingException, JMSException {
+
+ String id = "123";
+
+ MessageProducer producer = EasyMock.createNiceMock(MessageProducer.class);
+
+ Session session = EasyMock.createNiceMock(Session.class);
+ EasyMock.expect(session.createProducer(EasyMock.isA(Destination.class))).andReturn(producer);
+ EasyMock.replay(session);
+
+ ObjectMessage responseJMSMsg = EasyMock.createMock(ObjectMessage.class);
+ responseJMSMsg.setJMSDeliveryMode(1);
+ responseJMSMsg.setJMSPriority(1);
+ responseJMSMsg.setJMSCorrelationID(id);
+ EasyMock.replay(responseJMSMsg);
+
+ JMSResourceFactory jmsResourceFactory = EasyMock.createMock(JMSResourceFactory.class);
+ EasyMock.expect(jmsResourceFactory.createSession()).andReturn(session);
+
+ OperationAndDataBinding odb = EasyMock.createMock(OperationAndDataBinding.class);
+ EasyMock.expect(odb.createJMSMessage(EasyMock.eq(session), EasyMock.isA(Exception.class)))
+ .andReturn(responseJMSMsg);
+ EasyMock.replay(odb);
+
+ JMSProxy jmsProxy = new JMSProxy(null, jmsResourceFactory, null, odb, null);
+
+ Message requestJMSMsg = EasyMock.createMock(Message.class);
+ EasyMock.expect(requestJMSMsg.getJMSReplyTo()).andReturn(new Destination() {
+ });
+
+ EasyMock.expect(requestJMSMsg.getJMSDeliveryMode()).andReturn(1);
+ EasyMock.expect(requestJMSMsg.getJMSPriority()).andReturn(1);
+
+ EasyMock.expect(requestJMSMsg.getJMSReplyTo()).andReturn(new Destination() {
+ });
+ EasyMock.expect(requestJMSMsg.getJMSMessageID()).andReturn(id);
+
+ producer.send(EasyMock.isA(Message.class));
+ EasyMock.replay(producer);
+
+ EasyMock.replay(requestJMSMsg);
+ EasyMock.replay(jmsResourceFactory);
+
+ jmsProxy.onMessage(requestJMSMsg);
+
+ EasyMock.verify(requestJMSMsg);
+ EasyMock.verify(jmsResourceFactory);
+ EasyMock.verify(producer);
+ EasyMock.verify(session);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/databinding/JmsTransformerTestCase.java b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/databinding/JmsTransformerTestCase.java
new file mode 100644
index 0000000000..7c9420b7f9
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/java/org/apache/tuscany/binding/jms/databinding/JmsTransformerTestCase.java
@@ -0,0 +1,64 @@
+/*
+ * 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.binding.jms.databinding;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for transformers
+ */
+public class JmsTransformerTestCase extends TestCase {
+ private Input2JmsInputTransformer t1;
+ private JmsInput2InputTransformer t2;
+ private Output2JmsOutputTransformer t3;
+ private JmsOutput2OutputTransformer t4;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ t1 = new Input2JmsInputTransformer();
+ t2 = new JmsInput2InputTransformer();
+ t3 = new Output2JmsOutputTransformer();
+ t4 = new JmsOutput2OutputTransformer();
+ }
+
+ public void testInput() {
+ Object[] args1 = new Object[] {1, "ABC", 1.0d};
+ Object[] args2 = t1.transform(args1, null);
+ assertEquals(1, args2.length);
+ assertTrue(args2[0] instanceof byte[]);
+ Object[] args3 = t2.transform(args2, null);
+ for (int i = 0; i < args3.length; i++) {
+ assertEquals(args1[i], args3[i]);
+ }
+
+ }
+
+ public void testOutput() {
+ Object args1 = "ABC";
+ Object args2 = t3.transform(args1, null);
+ assertTrue(args2 instanceof byte[]);
+ Object args3 = t4.transform(args2, null);
+ assertEquals(args1, args3);
+ }
+
+}
diff --git a/sandbox/old/contrib/binding-jms/src/test/resources/META-INF/sca/default.scdl b/sandbox/old/contrib/binding-jms/src/test/resources/META-INF/sca/default.scdl
new file mode 100644
index 0000000000..7291363978
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/resources/META-INF/sca/default.scdl
@@ -0,0 +1,61 @@
+ <!--
+ * 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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:wsdli="http://www.w3.org/2006/01/wsdl-instance"
+ name="jms.sample">
+
+ <service name="GreetingJMSService">
+ <interface.java class="org.apache.tuscany.binding.jms.GreetingService"/>
+ <binding.jms initialContextFactory="org.activemq.jndi.ActiveMQInitialContextFactory" JNDIProviderURL="tcp://localhost:61616" >
+ <destination name="greetingServiceQueue" />
+ <connectionFactory name="ConnectionFactory" />
+ </binding.jms>
+ <reference>GretingServiceComponent</reference>
+ </service>
+
+ <component name="GretingServiceComponent">
+ <implementation.java class="org.apache.tuscany.binding.jms.GreetingServiceImpl"/>
+ </component>
+
+ <component name="IntroServiceComponent">
+ <implementation.java class="org.apache.tuscany.binding.jms.IntroServiceImpl"/>
+ <reference name="extService" target="GreetingJMSReference">GreetingJMSReference</reference>
+ </component>
+
+ <reference name="GreetingJMSReference">
+ <interface.java class="org.apache.tuscany.binding.jms.GreetingService"/>
+ <binding.jms initialContextFactory="org.activemq.jndi.ActiveMQInitialContextFactory" JNDIProviderURL="tcp://localhost:61616" >
+ <destination name="dynamicQueues/greetingServiceQueue" />
+ <connectionFactory name="ConnectionFactory" />
+ </binding.jms>
+ </reference>
+
+ <service name="HelloworldJMSService">
+ <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)"
+ wsdli:wsdlLocation="http://helloworld wsdl/helloworld.wsdl" />
+ <binding.jms initialContextFactory="org.activemq.jndi.ActiveMQInitialContextFactory" JNDIProviderURL="tcp://localhost:61616" >
+ <destination name="HelloworldServiceQueue" />
+ <connectionFactory name="ConnectionFactory" />
+ </binding.jms>
+ <reference>HelloworldComponent</reference>
+ </service>
+
+ <component name="HelloworldComponent">
+ <implementation.java class="org.apache.tuscany.binding.jms.HelloworldServiceImpl"/>
+ </component>
+
+</composite>
+
diff --git a/sandbox/old/contrib/binding-jms/src/test/resources/wsdl/helloworld.wsdl b/sandbox/old/contrib/binding-jms/src/test/resources/wsdl/helloworld.wsdl
new file mode 100644
index 0000000000..f1a62d8570
--- /dev/null
+++ b/sandbox/old/contrib/binding-jms/src/test/resources/wsdl/helloworld.wsdl
@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<wsdl:definitions targetNamespace="http://helloworld" xmlns:tns="http://helloworld" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ name="helloworld">
+
+ <wsdl:types>
+ <schema elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns="http://www.w3.org/2001/XMLSchema">
+
+ <element name="getGreetings">
+ <complexType>
+ <sequence>
+ <element name="name" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="getGreetingsResponse">
+ <complexType>
+ <sequence>
+ <element name="getGreetingsReturn" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="getGreetingsCallback">
+ <complexType>
+ <sequence>
+ <element name="getGreetingsReturn" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="getGreetings1">
+ <complexType>
+ <sequence>
+ <element name="name" type="tns:NameType">
+ </element>
+ </sequence>
+ </complexType>
+ </element>
+
+ <complexType name="NameType">
+ <sequence>
+ <element name="firstName" type="string"/>
+ <element name="lastName" type="string"/>
+ </sequence>
+ </complexType>
+
+ <element name="getGreetings1Response">
+ <complexType>
+ <sequence>
+ <element name="getGreetingsReturn" type="xsd:string"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ </schema>
+ </wsdl:types>
+
+ <wsdl:message name="getGreetingsRequest">
+ <wsdl:part element="tns:getGreetings" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:message name="getGreetingsResponse">
+ <wsdl:part element="tns:getGreetingsResponse" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:message name="getGreetingsCallback">
+ <wsdl:part element="tns:getGreetingsCallback" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:message name="getGreetings1Request">
+ <wsdl:part element="tns:getGreetings1" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:message name="getGreetings1Response">
+ <wsdl:part element="tns:getGreetings1Response" name="parameters"/>
+ </wsdl:message>
+
+ <wsdl:portType name="HelloWorld">
+ <wsdl:operation name="getGreetings">
+ <wsdl:input message="tns:getGreetingsRequest" name="getGreetingsRequest"/>
+ <wsdl:output message="tns:getGreetingsResponse" name="getGreetingsResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:portType name="HelloWorldCallback">
+ <wsdl:operation name="getGreetingsCallback">
+ <wsdl:input message="tns:getGreetingsCallback" name="getGreetingsCallback"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld">
+ <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getGreetings">
+ <wsdlsoap:operation soapAction=""/>
+ <wsdl:input name="getGreetingsRequest">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output name="getGreetingsResponse">
+ <wsdlsoap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+
+ </wsdl:binding>
+
+ <wsdl:service name="HelloWorldService">
+ <wsdl:port binding="tns:HelloWorldSoapBinding" name="HelloWorldSoapPort">
+ <wsdlsoap:address location="http://localhost:8080/sample-helloworldws-async-1.0-incubator-SNAPSHOT/services/HelloWorldWebService"/>
+ </wsdl:port>
+ </wsdl:service>
+
+</wsdl:definitions>