Initial checkin of a version of the currency converter that uses the JMS binding

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@793377 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
mcombellack 2009-07-12 17:15:54 +00:00
parent e72041272b
commit 4c8b1b3019
8 changed files with 504 additions and 0 deletions

View file

@ -0,0 +1,89 @@
<?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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-sca</artifactId>
<version>1.6-SNAPSHOT</version>
<!--relativePath>../../pom.xml</relativePath-->
</parent>
<version>1.0-SNAPSHOT</version>
<artifactId>currency-converter-jms-client</artifactId>
<name>Apache Tuscany SCA Tours Currency Converter JMS Client</name>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.2.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-web-demo</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.7</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.7</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
</build>
</project>

View file

@ -0,0 +1,104 @@
/*
* 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 scatours;
import java.io.ByteArrayInputStream;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.xml.stream.XMLStreamException;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
public class LaunchJMSClient {
private static Connection activeMQConnection;
private static Session activeMQSession;
private static Destination requestDestination;
private static MessageProducer activeMQProducer;
private static Destination responseDestination;
private static MessageConsumer consumer;
private static OMFactory omFactory;
public static void main(String[] args) throws JMSException, XMLStreamException {
startActiveMQSession();
OMElement request = omFactory.createOMElement("convert", "http://goodvaluetrips.com/", "ns2");
request.addChild(createArg(0, "USD"));
request.addChild(createArg(1, "GBP"));
request.addChild(createArg(2, "100.0"));
TextMessage message = activeMQSession.createTextMessage("convert");
message.setStringProperty("scaOperationName", "convert");
message.setJMSReplyTo(responseDestination);
message.setText(request.toString());
activeMQProducer.send(message);
TextMessage response = (TextMessage) consumer.receive();
StAXOMBuilder builder = new StAXOMBuilder(
new ByteArrayInputStream(response.getText().getBytes()));
OMText returnElement = (OMText) builder.getDocumentElement().getFirstOMChild();
String returnValue = returnElement.getText();
System.out.println("100 USD = " + returnValue + "GBP");
stopActiveMQSession();
}
private static void startActiveMQSession() throws JMSException {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61619");
activeMQConnection = connectionFactory.createConnection();
activeMQConnection.start();
activeMQSession = activeMQConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
requestDestination = activeMQSession.createQueue("RequestQueue");
activeMQProducer = activeMQSession.createProducer(requestDestination);
responseDestination = activeMQSession.createQueue("ResponseQueue");
consumer = activeMQSession.createConsumer(responseDestination);
omFactory = OMAbstractFactory.getOMFactory();
}
private static void stopActiveMQSession() throws JMSException {
consumer.close();
activeMQProducer.close();
activeMQSession.close();
activeMQConnection.close();
}
private static OMElement createArg(int argNumber, String value) {
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMElement arg = omFactory.createOMElement("arg" + argNumber, null);
OMText senderOM = omFactory.createOMText(value);
arg.addChild(senderOM);
return arg;
}
}

View file

@ -0,0 +1,83 @@
<?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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-sca</artifactId>
<version>1.6-SNAPSHOT</version>
<!--relativePath>../../pom.xml</relativePath-->
</parent><version>1.0-SNAPSHOT</version>
<artifactId>scatours-currency-jms-contribution</artifactId>
<name>Apache Tuscany SCA Tours Currency Converter Contribution With JMS Binding</name>
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<version>1.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>
<version>1.6-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-jms-runtime</artifactId>
<version>1.6-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-jms-asf</artifactId>
<version>1.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.2.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-web-demo</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
</build>
</project>

View file

@ -0,0 +1,22 @@
<?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.
-->
<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0">
<import.java package="scatours.currencyconverter"/>
</contribution>

View file

@ -0,0 +1,37 @@
<?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.
-->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://goodvaluetrips.com/"
name="currencyconverter">
<component name="CurrencyConverter">
<implementation.java class="scatours.currencyconverter.CurrencyConverterImpl"/>
<service name="CurrencyConverter">
<interface.java interface="scatours.currencyconverter.CurrencyConverter"/>
<binding.jms initialContextFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
jndiURL="tcp://localhost:61619">
<destination name="RequestQueue" create="ifnotexist"/>
<response>
<destination name="ResponseQueue" create="ifnotexist"/>
</response>
</binding.jms>
</service>
</component>
</composite>

View file

@ -0,0 +1,88 @@
<?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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-sca</artifactId>
<version>1.6-SNAPSHOT</version>
<!--relativePath>../../pom.xml</relativePath-->
</parent><version>1.0-SNAPSHOT</version>
<artifactId>scatours-currency-converter-jms-launcher</artifactId>
<name>Apache Tuscany SCA Tours Currency Converter JMS Launcher</name>
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-api</artifactId>
<version>1.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>
<version>1.6-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-node-runtime</artifactId>
<version>1.6-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-jms-runtime</artifactId>
<version>1.6-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-jms-asf</artifactId>
<version>1.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.2.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-web-demo</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
</build>
</project>

View file

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package scatours;
import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.SCANodeFactory;
public class LaunchCurrencyConverterJMSNode {
public static void main(String[] args) throws Exception {
SCAContribution currencyJMSContribution =
new SCAContribution("currency-jms", "../../contributions/currency-jms-contribution/target/classes");
SCAContribution currencyContribution =
new SCAContribution("currency", "../../contributions/currency-contribution/target/classes");
SCANode node = SCANodeFactory.newInstance().createSCANode(
"currency-converter-jms.composite",currencyContribution, currencyJMSContribution);
node.start();
System.out.println("Node started - Press enter to shutdown.");
System.in.read();
node.stop();
}
}

View file

@ -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 scatours;
import org.apache.activemq.broker.BrokerService;
public class LaunchJMSBroker {
public static void main(String[] args) throws Exception {
final BrokerService jmsBroker = new BrokerService();
jmsBroker.setPersistent(false);
jmsBroker.setUseJmx(false);
jmsBroker.addConnector("tcp://localhost:61619");
jmsBroker.start();
System.out.println("JMS Message Broker started");
System.out.println("Press enter to shutdown.");
System.in.read();
jmsBroker.stop();
}
}