summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/services/smsgateway-jms
diff options
context:
space:
mode:
authornash <nash@13f79535-47bb-0310-9956-ffa450edef68>2009-09-16 07:11:31 +0000
committernash <nash@13f79535-47bb-0310-9956-ffa450edef68>2009-09-16 07:11:31 +0000
commite86155b8e75297d8fc5f4e07caf8280cacadced8 (patch)
treec629e4eb23fecdc04129781057fd3e92583e3593 /sandbox/travelsample/services/smsgateway-jms
parent02f65ca4eee882a3217de613bf0f63c5460d884e (diff)
Rename services modules
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@815636 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/travelsample/services/smsgateway-jms')
-rw-r--r--sandbox/travelsample/services/smsgateway-jms/build.xml48
-rw-r--r--sandbox/travelsample/services/smsgateway-jms/pom.xml88
-rw-r--r--sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGateway.java31
-rw-r--r--sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayImpl.java126
-rw-r--r--sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java40
5 files changed, 333 insertions, 0 deletions
diff --git a/sandbox/travelsample/services/smsgateway-jms/build.xml b/sandbox/travelsample/services/smsgateway-jms/build.xml
new file mode 100644
index 0000000000..1bd42894db
--- /dev/null
+++ b/sandbox/travelsample/services/smsgateway-jms/build.xml
@@ -0,0 +1,48 @@
+<!--
+ * 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 name="scatours-service-smsgateway-jms" default="compile">
+ <property environment="env"/>
+
+ <target name="compile">
+ <mkdir dir="target/classes"/>
+ <javac destdir="target/classes" debug="on" source="1.5" target="1.5">
+ <src path="src/main/java"/>
+ <classpath>
+ <pathelement location="${env.TUSCANY}/lib/tuscany-sca-manifest.jar"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <target name="run">
+ <java classname="scatours.smsgateway.SMSGatewayJMSServiceBootstrap" fork="true">
+ <classpath>
+ <pathelement location="target/classes"/>
+ <pathelement location="${env.TUSCANY}/lib/tuscany-sca-manifest.jar"/>
+ </classpath>
+ </java>
+ </target>
+
+ <target name="clean">
+ <delete includeemptydirs="true">
+ <fileset dir="target"/>
+ </delete>
+ </target>
+
+</project>
diff --git a/sandbox/travelsample/services/smsgateway-jms/pom.xml b/sandbox/travelsample/services/smsgateway-jms/pom.xml
new file mode 100644
index 0000000000..3c5a12d367
--- /dev/null
+++ b/sandbox/travelsample/services/smsgateway-jms/pom.xml
@@ -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-service-smsgateway-jms</artifactId>
+ <name>Apache Tuscany SCA Tours SMS Gateway JMS Service</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>
diff --git a/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGateway.java b/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGateway.java
new file mode 100644
index 0000000000..a900dfecee
--- /dev/null
+++ b/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGateway.java
@@ -0,0 +1,31 @@
+/*
+ * 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.smsgateway;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+
+/**
+ * A gateway to send SMS messages.
+ */
+public interface SMSGateway extends Remote {
+ boolean sendSMS(String fromNumber, String toNumber, String text) throws RemoteException;
+}
diff --git a/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayImpl.java b/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayImpl.java
new file mode 100644
index 0000000000..adacac77f5
--- /dev/null
+++ b/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayImpl.java
@@ -0,0 +1,126 @@
+/*
+ * 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.smsgateway;
+
+import java.io.ByteArrayInputStream;
+
+import javax.jms.BytesMessage;
+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.jms.TextMessage;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+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 SMSGatewayImpl implements SMSGateway {
+
+ private final Session session;
+ private final MessageConsumer consumer;
+ private final MessageProducer producer;
+
+ public SMSGatewayImpl(Session session) throws JMSException {
+ this.session = session;
+ Destination requestDest = session.createQueue("SMSRequestQueue");
+ consumer = session.createConsumer(requestDest);
+
+ Destination responseDest = session.createQueue("SMSResponseQueue");
+ producer = session.createProducer(responseDest);
+ }
+
+ public void start() throws JMSException, XMLStreamException {
+ while (true) {
+ Message message = consumer.receive();
+ handleRequest(message);
+ }
+ }
+
+ private void handleRequest(Message inMessage) throws XMLStreamException, JMSException {
+ OMElement xml = parseXMLPayload(inMessage);
+
+ String fromNumber = getStringArg(xml, 0);
+ String toNumber = getStringArg(xml, 1);
+ String text = getStringArg(xml, 2);
+
+ boolean result = sendSMS(fromNumber, toNumber, text);
+
+ String responseXML = createXMLResponse(result);
+
+ TextMessage outMessage = createResponseMessage(inMessage.getJMSMessageID(), responseXML);
+ producer.send(outMessage);
+ }
+
+ private OMElement parseXMLPayload(Message inMessage) throws JMSException, XMLStreamException {
+ final byte[] msgData;
+ if (inMessage instanceof TextMessage) {
+ msgData = ((TextMessage) inMessage).getText().getBytes();
+ } else if (inMessage instanceof BytesMessage) {
+ BytesMessage bytesMessage = (BytesMessage) inMessage;
+ msgData = new byte[(int) bytesMessage.getBodyLength()];
+ bytesMessage.readBytes(msgData);
+ } else {
+ throw new JMSException("Unsupported JMS message type of " + inMessage.getClass().getName());
+ }
+ ByteArrayInputStream in = new ByteArrayInputStream(msgData);
+ StAXOMBuilder builder = new StAXOMBuilder(in);
+ OMElement doc = builder.getDocumentElement();
+ return doc;
+ }
+
+ private String getStringArg(OMElement doc, int i) {
+ QName argQName = new QName("arg" + i);
+ OMElement arg = doc.getFirstChildWithName(argQName);
+ if (arg == null) {
+ return null;
+ }
+ return arg.getText();
+ }
+
+ public boolean sendSMS(String fromNumber, String toNumber, String text) {
+ System.out.println("From: " + fromNumber);
+ System.out.println("To: " + toNumber);
+ System.out.println(text);
+ return true;
+ }
+
+ private String createXMLResponse(boolean result) {
+ OMFactory omFactory = OMAbstractFactory.getOMFactory();
+ OMElement response = omFactory.createOMElement("sendSMS", "http://smsgateway.scatours/", "ns2");
+ OMElement returnValue = omFactory.createOMElement("return", null);
+ OMText returnV = omFactory.createOMText(Boolean.toString(result));
+ returnValue.addChild(returnV);
+ response.addChild(returnValue);
+ return response.toString();
+ }
+
+ private TextMessage createResponseMessage(String correlationID, String responseXML) throws JMSException {
+ TextMessage outMessage = session.createTextMessage("sendSMS");
+ outMessage.setText(responseXML);
+ outMessage.setJMSCorrelationID(correlationID);
+ return outMessage;
+ }
+ }
diff --git a/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java b/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java
new file mode 100644
index 0000000000..6fe08a44b5
--- /dev/null
+++ b/sandbox/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java
@@ -0,0 +1,40 @@
+/*
+ * 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.smsgateway;
+
+import javax.jms.Connection;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+
+public class SMSGatewayJMSServiceBootstrap {
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("Publishing SMS Gateway Service as a JMS service");
+
+ ActiveMQConnectionFactory connectionFactory
+ = new ActiveMQConnectionFactory("tcp://localhost:61619");
+ Connection connection = connectionFactory.createConnection();
+ connection.start();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ SMSGatewayImpl impl = new SMSGatewayImpl(session);
+ impl.start();
+ }
+}