diff options
Diffstat (limited to 'sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway')
3 files changed, 0 insertions, 203 deletions
diff --git a/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGateway.java b/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGateway.java deleted file mode 100644 index e6e866fa1d..0000000000 --- a/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGateway.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayImpl.java b/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayImpl.java deleted file mode 100644 index c35aa61513..0000000000 --- a/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayImpl.java +++ /dev/null @@ -1,126 +0,0 @@ -/*
- * 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/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java b/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java deleted file mode 100644 index d8543266e3..0000000000 --- a/sca-java-2.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java +++ /dev/null @@ -1,47 +0,0 @@ -/*
- * 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;
-import org.apache.activemq.broker.BrokerService;
-
-public class SMSGatewayJMSServiceBootstrap {
-
- 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("Publishing SMS Gateway Service as a JMS service: tcp://localhost:61619");
- System.out.println("Press Ctrl^C to terminate...");
-
- 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();
- }
-}
|