Author: amilas
Date: Tue Jul 21 05:26:15 2009
New Revision: 796150
URL: http://svn.apache.org/viewvc?rev=796150&view=rev
Log:
committing the patch for WSCOMMONS-470
Added:
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMDispatcher.java
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportInDetails.java
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportOutDetails.java
Modified:
webservices/commons/trunk/modules/transport/modules/sms/pom.xml
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java
Modified: webservices/commons/trunk/modules/transport/modules/sms/pom.xml
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/pom.xml?rev=796150&r1=796149&r2=796150&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/sms/pom.xml (original)
+++ webservices/commons/trunk/modules/transport/modules/sms/pom.xml Tue Jul 21
05:26:15 2009
@@ -162,6 +162,11 @@
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
+ <dependency>
+ <groupId>org.smslib</groupId>
+ <artifactId>smslib</artifactId>
+ <version>3.4.1</version>
+ </dependency>
</dependencies>
Modified:
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java?rev=796150&r1=796149&r2=796150&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java
Tue Jul 21 05:26:15 2009
@@ -53,5 +53,12 @@
/**
* GSM Constents
*/
+
+ public static String MODEM_GATEWAY_ID = "gateway_id";
+ public static String COM_PORT = "com_port";
+ public static String BAUD_RATE = "baud_rate";
+ public static String MANUFACTURER = "manufacturer";
+ public static String MODEL = "model";
+ public static String MODEM_POLL_INTERVAL="modem_poll_interval";
}
Added:
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMDispatcher.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMDispatcher.java?rev=796150&view=auto
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMDispatcher.java
(added)
+++
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMDispatcher.java
Tue Jul 21 05:26:15 2009
@@ -0,0 +1,93 @@
+/*
+ * 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.axis2.transport.sms.gsm;
+
+import org.smslib.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.axis2.transport.sms.SMSMessage;
+import org.apache.axis2.transport.sms.SMSManager;
+
+/**
+ * GSMDispatcher will access the gsm modem and dispatch the incomming SMS s to
the Axis2
+ */
+public class GSMDispatcher implements Runnable{
+
+ protected Log log = LogFactory.getLog(this.getClass());
+ private boolean keepPolling = true;
+
+ private Service service;
+ private long pollInterval=5000;
+
+ /**
+ * To create a GSMDispatcher a service object that is created for the
current GSM modem is needed
+ * @param service
+ */
+ public GSMDispatcher(Service service) {
+ this.service = service;
+ }
+
+ public void run() {
+
+ while(keepPolling) {
+ List<InboundMessage> arrayList = new ArrayList<InboundMessage>();
+ try {
+ service.readMessages(arrayList,
InboundMessage.MessageClasses.UNREAD) ;
+
+ for(InboundMessage msg : arrayList) {
+ SMSMessage sms =null;
+ synchronized (this) {
+ sms= new
SMSMessage(msg.getOriginator(),null,msg.getText() ,SMSMessage.IN_MESSAGE);
+ }
+ SMSManager.getSMSManager().dispatchToAxis2(sms);
+ //delete the message form inbox
+ service.deleteMessage(msg);
+ }
+ } catch (Exception ex) {
+ log.error("Error Occured while reading messages",ex);
+ }
+
+ try {
+ Thread.sleep(pollInterval);
+ } catch (InterruptedException e) {
+
+ }
+ }
+ }
+
+
+ public void stopPolling(){
+ keepPolling = false;
+ }
+
+ /**
+ * set the modem Polling time
+ * modem polling time will be the time interval that the modem will be
polled to get the unread messages
+ * form the inbox.
+ * the optimal value for this will be diffrent form modem to modem.
+ * Keep the default value of you are not aware of it
+ * @param pollInterval
+ */
+ public void setPollInterval(long pollInterval) {
+ this.pollInterval = pollInterval;
+ }
+}
Added:
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java?rev=796150&view=auto
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java
(added)
+++
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java
Tue Jul 21 05:26:15 2009
@@ -0,0 +1,228 @@
+/*
+ * 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.axis2.transport.sms.gsm;
+
+import org.apache.axis2.transport.sms.SMSImplManager;
+import org.apache.axis2.transport.sms.SMSMessage;
+import org.apache.axis2.transport.sms.SMSTransportConstents;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.smslib.*;
+import org.smslib.modem.SerialModemGateway;
+
+/**
+ * Manage the GSM implimentation of the SMS Transport
+ * To use this with the axis2 to it must be spcified as a implimentation class
in the Axis2 XML
+ * following is a Sample configuration
+ * <transportReceiver name="sms"
+ *
class="org.apache.axis2.transport.sms.SMSMessageReciever">
+ *
+ * <parameter
name="smsImplClass">org.apache.axis2.transport.sms.gsm.GSMImplManager</parameter>
+ * <parameter name="com_port">/dev/ttyUSB0</parameter>
+ * <parameter name="gateway_id">modem.ttyUSB0</parameter>
+ * <parameter name="baud_rate">115200</parameter>
+ * <parameter name="manufacturer">HUAWEI</parameter>
+ * <parameter name="model">E220</parameter>
+ * </transportReceiver>
+ *
+ *
+ */
+public class GSMImplManager implements SMSImplManager {
+ /** the reference to the actual commons logger to be used for log messages
*/
+ protected Log log = LogFactory.getLog(this.getClass());
+ private GSMTransportInDetails gsmTransportInDetails =
GSMTransportInDetails.getInstance();
+ private GSMTransportOutDetails gsmTransportOutDetails =
GSMTransportOutDetails.getInstance();
+ private GSMDispatcher dispatcher;
+ private Service service = null;
+ private SerialModemGateway gateway;
+ public void start() {
+
+ service = new Service();
+ gateway= new SerialModemGateway(gsmTransportInDetails.getGatewayId(),
gsmTransportInDetails.getComPort(),
+
gsmTransportInDetails.getBaudRate(),gsmTransportInDetails.getManufacturer(),
+ gsmTransportInDetails.getModel());
+
+ // Set the modem protocol to PDU (alternative is TEXT).
PDU is the default, anyway...
+ gateway.setProtocol(AGateway.Protocols.PDU);
+
+ // Do we want the Gateway to be used for Inbound
messages?
+ gateway.setInbound(true);
+
+ // Do we want the Gateway to be used for Outbound
messages?
+ gateway.setOutbound(true);
+
+ // Let SMSLib know which is the SIM PIN.
+ gateway.setSimPin("0000");
+
+
+
+ try {
+ // Add the Gateway to the Service object.
+ this.service.addGateway(gateway);
+
+ // Start! (i.e. connect to all defined Gateways)
+ this.service.startService();
+ dispatcher = new GSMDispatcher(service);
+
dispatcher.setPollInterval(gsmTransportInDetails.getModemPollInterval());
+ Thread thread = new Thread(dispatcher);
+ thread.start();
+ System.out.println("[Axis2] Started in Port :" +
gsmTransportInDetails.getComPort() +" ");
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+
+ public void stop() {
+
+ try {
+ dispatcher.stopPolling();
+ service.stopService();
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+
+ public void setTransportOutDetails(TransportOutDescription
transportOutDetails) throws AxisFault {
+
+ if
(transportOutDetails.getParameter(SMSTransportConstents.MODEM_GATEWAY_ID) !=
null) {
+ gsmTransportOutDetails.setGatewayId((String)
transportOutDetails.getParameter(
+ SMSTransportConstents.MODEM_GATEWAY_ID).getValue());
+ } else {
+ throw new AxisFault("GATEWAY ID NOT SET for the SMS transprot");
+ }
+
+ if (transportOutDetails.getParameter(SMSTransportConstents.COM_PORT)
!= null) {
+ gsmTransportOutDetails.setComPort((String)
transportOutDetails.getParameter(
+ SMSTransportConstents.COM_PORT).getValue());
+ } else {
+ throw new AxisFault("COM PORT NOT SET for the SMS transprot");
+ }
+ if (transportOutDetails.getParameter(SMSTransportConstents.BAUD_RATE)
!= null) {
+ int bRate = Integer.parseInt((String)
transportOutDetails.getParameter(
+ SMSTransportConstents.BAUD_RATE).getValue());
+ gsmTransportOutDetails.setBaudRate(bRate);
+ } else {
+ throw new AxisFault("BAUD RATE NOT SET for the SMS transprot");
+ }
+ if
(transportOutDetails.getParameter(SMSTransportConstents.MANUFACTURER) != null) {
+ gsmTransportOutDetails.setManufacturer((String)
transportOutDetails.getParameter(
+ SMSTransportConstents.MANUFACTURER).getValue());
+ } else {
+ throw new AxisFault("Manufactuer NOT SET for the SMS transprot");
+ }
+
+ if (transportOutDetails.getParameter(SMSTransportConstents.MODEL) !=
null) {
+ gsmTransportOutDetails.setModel((String)
transportOutDetails.getParameter(
+ SMSTransportConstents.MODEL).getValue());
+ } else {
+ throw new AxisFault("Model NOT SET for the SMS transprot");
+ }
+
+
+ }
+
+ public void setTransportInDetails(TransportInDescription
transportInDetails) throws AxisFault {
+ if
(transportInDetails.getParameter(SMSTransportConstents.MODEM_GATEWAY_ID) !=
null) {
+ gsmTransportInDetails.setGatewayId((String)
transportInDetails.getParameter(
+ SMSTransportConstents.MODEM_GATEWAY_ID).getValue());
+ } else {
+ throw new AxisFault("GATEWAY ID NOT SET for the SMS transprot");
+ }
+
+ if (transportInDetails.getParameter(SMSTransportConstents.COM_PORT) !=
null) {
+ gsmTransportInDetails.setComPort((String)
transportInDetails.getParameter(
+ SMSTransportConstents.COM_PORT).getValue());
+ } else {
+ throw new AxisFault("COM PORT NOT SET for the SMS transprot");
+ }
+ if (transportInDetails.getParameter(SMSTransportConstents.BAUD_RATE)
!= null) {
+ int bRate = Integer.parseInt((String)
transportInDetails.getParameter(
+ SMSTransportConstents.BAUD_RATE).getValue());
+ gsmTransportInDetails.setBaudRate(bRate);
+ } else {
+ throw new AxisFault("BAUD RATE NOT SET for the SMS transprot");
+ }
+ if
(transportInDetails.getParameter(SMSTransportConstents.MANUFACTURER) != null) {
+ gsmTransportInDetails.setManufacturer((String)
transportInDetails.getParameter(
+ SMSTransportConstents.MANUFACTURER).getValue());
+ } else {
+ throw new AxisFault("Manufactuer NOT SET for the SMS transprot");
+ }
+
+ if (transportInDetails.getParameter(SMSTransportConstents.MODEL) !=
null) {
+ gsmTransportInDetails.setModel((String)
transportInDetails.getParameter(
+ SMSTransportConstents.MODEL).getValue());
+ } else {
+ throw new AxisFault("Model NOT SET for the SMS transprot");
+ }
+
+ if
(transportInDetails.getParameter(SMSTransportConstents.MODEM_POLL_INTERVAL) !=
null) {
+ String pollTime = (String)
transportInDetails.getParameter(SMSTransportConstents.MODEM_POLL_INTERVAL).
+ getValue();
+
gsmTransportInDetails.setModemPollInterval(Long.parseLong(pollTime));
+ }
+ }
+
+ public void sendSMS(SMSMessage sm) {
+ if (service == null) {
+ //Operating in the Out Only mode
+ service = new Service();
+ gateway = new
SerialModemGateway(gsmTransportOutDetails.getGatewayId(),
gsmTransportOutDetails.getComPort(),
+ gsmTransportOutDetails.getBaudRate(),
gsmTransportOutDetails.getManufacturer(),
+ gsmTransportOutDetails.getModel());
+
+ // Set the modem protocol to PDU (alternative is TEXT). PDU is the
default, anyway...
+ gateway.setProtocol(AGateway.Protocols.PDU);
+
+
+ // Do we want the Gateway to be used for Outbound messages?
+ gateway.setOutbound(true);
+
+ // Let SMSLib know which is the SIM PIN.
+ gateway.setSimPin("0000");
+ try {
+ // Add the Gateway to the Service object.
+ this.service.addGateway(gateway);
+
+ // Similarly, you may define as many Gateway objects,
representing
+ // various GSM modems, add them in the Service object and
control all of them.
+
+ // Start! (i.e. connect to all defined Gateways)
+ this.service.startService();
+
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ }
+
+ OutboundMessage msg = new OutboundMessage(sm.getReceiver(),
sm.getContent());
+ try {
+ // a blocking call.This will be blocked untill the message is sent.
+ // normal rate is about 6msgs per minute
+ service.sendMessage(msg);
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+
+}
Added:
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportInDetails.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportInDetails.java?rev=796150&view=auto
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportInDetails.java
(added)
+++
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportInDetails.java
Tue Jul 21 05:26:15 2009
@@ -0,0 +1,92 @@
+/*
+ * 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.axis2.transport.sms.gsm;
+
+/**
+ * holds the TransportIn details thats needed for the GSM implimentation
+ */
+public class GSMTransportInDetails {
+ private static GSMTransportInDetails ourInstance;
+
+ private String gatewayId;
+ private String comPort;
+ private int baudRate;
+ private String manufacturer;
+ private String model;
+ private long modemPollInterval = 5000;
+
+ public static GSMTransportInDetails getInstance() {
+ if (ourInstance == null) {
+ ourInstance = new GSMTransportInDetails();
+ }
+ return ourInstance;
+ }
+
+ private GSMTransportInDetails() {
+
+ }
+
+ public String getGatewayId() {
+ return gatewayId;
+ }
+
+ public void setGatewayId(String gatewayId) {
+ this.gatewayId = gatewayId;
+ }
+
+ public String getComPort() {
+ return comPort;
+ }
+
+ public void setComPort(String comPort) {
+ this.comPort = comPort;
+ }
+
+ public int getBaudRate() {
+ return baudRate;
+ }
+
+ public void setBaudRate(int baudRate) {
+ this.baudRate = baudRate;
+ }
+
+ public String getManufacturer() {
+ return manufacturer;
+ }
+
+ public void setManufacturer(String manufacturer) {
+ this.manufacturer = manufacturer;
+ }
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+
+ public long getModemPollInterval() {
+ return modemPollInterval;
+ }
+
+ public void setModemPollInterval(long modemPollInterval) {
+ this.modemPollInterval = modemPollInterval;
+ }
+}
Added:
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportOutDetails.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportOutDetails.java?rev=796150&view=auto
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportOutDetails.java
(added)
+++
webservices/commons/trunk/modules/transport/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMTransportOutDetails.java
Tue Jul 21 05:26:15 2009
@@ -0,0 +1,81 @@
+/*
+ * 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.axis2.transport.sms.gsm;
+
+/**
+ * holds the transport out details for the GSM implementation
+ */
+public class GSMTransportOutDetails {
+ private static GSMTransportOutDetails ourInstance ;
+ private String gatewayId;
+ private String comPort;
+ private int baudRate;
+ private String manufacturer;
+ private String model;
+
+ public static GSMTransportOutDetails getInstance() {
+ if(ourInstance == null) {
+ ourInstance = new GSMTransportOutDetails();
+ }
+ return ourInstance;
+ }
+
+ private GSMTransportOutDetails() {
+ }
+
+ public String getGatewayId() {
+ return gatewayId;
+ }
+
+ public void setGatewayId(String gatewayId) {
+ this.gatewayId = gatewayId;
+ }
+
+ public String getComPort() {
+ return comPort;
+ }
+
+ public void setComPort(String comPort) {
+ this.comPort = comPort;
+ }
+
+ public int getBaudRate() {
+ return baudRate;
+ }
+
+ public void setBaudRate(int baudRate) {
+ this.baudRate = baudRate;
+ }
+
+ public String getManufacturer() {
+ return manufacturer;
+ }
+
+ public void setManufacturer(String manufacturer) {
+ this.manufacturer = manufacturer;
+ }
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+}