Author: amilas
Date: Tue Aug 18 15:39:55 2009
New Revision: 805457

URL: http://svn.apache.org/viewvc?rev=805457&view=rev
Log:
committing the test cases patch for WSCOMMONS-494

Added:
    webservices/commons/trunk/modules/transport/modules/sms/src/test/
    webservices/commons/trunk/modules/transport/modules/sms/src/test/java/
    webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SMSTransportTest.java
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.java
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/MessageHolder.java
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageNotifier.java
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageObserver.java
    
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SimpleSMSC.java
Modified:
    webservices/commons/trunk/modules/transport/modules/sms/pom.xml

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=805457&r1=805456&r2=805457&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/sms/pom.xml (original)
+++ webservices/commons/trunk/modules/transport/modules/sms/pom.xml Tue Aug 18 
15:39:55 2009
@@ -19,94 +19,130 @@
   -->
 
 <project
-    xmlns="http://maven.apache.org/POM/4.0.0";
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
+        xmlns="http://maven.apache.org/POM/4.0.0";
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.axis2</groupId>
+        <artifactId>axis2-transport</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <relativePath>../parent/pom.xml</relativePath>
+    </parent>
+
     <groupId>org.apache.axis2</groupId>
-    <artifactId>axis2-transport</artifactId>
-    <version>1.0-SNAPSHOT</version>
-    <relativePath>../parent/pom.xml</relativePath>
-  </parent>
-
-  <groupId>org.apache.axis2</groupId>
-  <artifactId>axis2-transport-sms</artifactId>
-  <name>Apache Axis2 - Transport - Sms</name>
-  <description>Apache Axis2 - SmsTransport</description>
-  <packaging>bundle</packaging>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <version>1.4.0</version>
-        <extensions>true</extensions>
-        <configuration>
-          <instructions>
-            <Bundle-Version>1.0</Bundle-Version>
-            <Bundle-Name>${pom.artifactId}</Bundle-Name>
-            <Bundle-Vendor>Apache Software Foundation</Bundle-Vendor>
-            <Bundle-Description>${pom.description}</Bundle-Description>
-            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
-            <Export-Package>
-              org.apache.axis2.transport.sms.*;-split-package:=merge-last,
-            </Export-Package>
-            <Import-Package>
-              !javax.xml.namespace,
-              javax.xml.namespace; version=0.0.0,
-              *; resolution:=optional
-            </Import-Package>
-          </instructions>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-dependency-plugin</artifactId>
-        <version>2.0</version>
-        <executions>
-          <execution>
-            <id>copy</id>
-            <phase>generate-test-resources</phase>
-            <goals>
-              <goal>copy</goal>
-            </goals>
-            <configuration>
-              <stripVersion>true</stripVersion>
-              <artifactItems>
-                <artifactItem>
-                  <groupId>org.aspectj</groupId>
-                  <artifactId>aspectjweaver</artifactId>
-                  <outputDirectory>target/lib</outputDirectory>
-                </artifactItem>
-              </artifactItems>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <version>2.3</version>
-        <configuration>
-          <systemProperties>
-            <property>
-              <name>log4j.configuration</name>
-              <value>file:../../log4j.properties</value>
-            </property>
-            <property>
-              <name>net.sourceforge.cobertura.datafile</name>
-              <value>target/cobertura.ser</value>
-            </property>
-          </systemProperties>
-          <argLine>-javaagent:target/lib/aspectjweaver.jar -Xms64m 
-Xmx128m</argLine>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+    <artifactId>axis2-transport-sms</artifactId>
+    <name>Apache Axis2 - Transport - Sms</name>
+    <description>Apache Axis2 - SmsTransport</description>
+    <packaging>bundle</packaging>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>1.4.0</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Version>1.0</Bundle-Version>
+                        <Bundle-Name>${pom.artifactId}</Bundle-Name>
+                        <Bundle-Vendor>Apache Software 
Foundation</Bundle-Vendor>
+                        
<Bundle-Description>${pom.description}</Bundle-Description>
+                        
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Export-Package>
+                            
org.apache.axis2.transport.sms.*;-split-package:=merge-last,
+                        </Export-Package>
+                        <Import-Package>
+                            !javax.xml.namespace,
+                            javax.xml.namespace; version=0.0.0,
+                            *; resolution:=optional
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <version>2.0</version>
+                <executions>
+                    <execution>
+                        <id>copy</id>
+                        <phase>generate-test-resources</phase>
+                        <goals>
+                            <goal>copy</goal>
+                        </goals>
+                        <configuration>
+                            <stripVersion>true</stripVersion>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>org.aspectj</groupId>
+                                    <artifactId>aspectjweaver</artifactId>
+                                    
<outputDirectory>target/lib</outputDirectory>
+                                </artifactItem>
+                            </artifactItems>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.3</version>
+                <configuration>
+                    <systemProperties>
+                        <property>
+                            <name>log4j.configuration</name>
+                            <value>file:../../log4j.properties</value>
+                        </property>
+                        <property>
+                            <name>net.sourceforge.cobertura.datafile</name>
+                            <value>target/cobertura.ser</value>
+                        </property>
+                    </systemProperties>
+                    <argLine>-javaagent:target/lib/aspectjweaver.jar -Xms64m 
-Xmx128m</argLine>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>build-repo</id>
+                        <phase>test-compile</phase>
+                        <configuration>
+                            <tasks>
+
+                                <mkdir 
dir="target/test-resources/samples/conf"/>
+                                <mkdir 
dir="target/test-resources/samples/repository/modules"/>
+                                <mkdir 
dir="target/test-resources/samples/repository/services"/>
+                                <mkdir
+                                        
dir="target/test-resources/samples/repository/services/SampleService/org/apache/axis2/transport/sms"/>
+                                <mkdir
+                                        
dir="target/test-resources/samples/repository/services/SampleService/META-INF"/>
+                                <copy 
file="${settings.localRepository}/org/apache/axis2/addressing/${axis2.version}/addressing-${axis2.version}.mar"
+                                      
tofile="target/test-resources/samples/repository/modules/addressing.mar"/>
+                                <copy 
file="target/test-classes/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.class"
+                                      
tofile="target/test-resources/samples/repository/services/SampleService/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.class"/>
+                                <copy file="conf/axis2.xml"
+                                      
tofile="target/test-resources/samples/conf/axis2.xml"/>
+                                <copy 
file="repository/services/SampleService/META-INF/MANIFEST.MF"
+                                      
tofile="target/test-resources/samples/repository/services/SampleService/META-INF/MANIFEST.MF"/>
+                                <copy 
file="repository/services/SampleService/META-INF/services.xml"
+                                      
tofile="target/test-resources/samples/repository/services/SampleService/META-INF/services.xml"/>
+                            </tasks>
+                        </configuration>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 
- <repositories>
+    <repositories>
         <repository>
             <id>apache-snapshots</id>
             <name>Apache Maven 2 Snapshot Repository</name>
@@ -115,7 +151,8 @@
                 <updatePolicy>never</updatePolicy>
             </releases>
             <snapshots>
-                <updatePolicy>interval:10080</updatePolicy> <!-- i.e. refresh 
weekly -->
+                <updatePolicy>interval:10080</updatePolicy>
+                <!-- i.e. refresh weekly -->
             </snapshots>
         </repository>
         <repository>
@@ -126,18 +163,19 @@
                 <updatePolicy>never</updatePolicy>
             </releases>
             <snapshots>
-                <updatePolicy>interval:10080</updatePolicy> <!-- i.e. refresh 
weekly -->
+                <updatePolicy>interval:10080</updatePolicy>
+                <!-- i.e. refresh weekly -->
             </snapshots>
         </repository>
     </repositories>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.axis2</groupId>
-      <artifactId>axis2-transport-base</artifactId>
-      <version>${version}</version>
-    </dependency>
-     <dependency>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.axis2</groupId>
+            <artifactId>axis2-transport-base</artifactId>
+            <version>${version}</version>
+        </dependency>
+        <dependency>
             <groupId>com.google.code</groupId>
             <artifactId>jsmpp</artifactId>
             <version>${jsmpp-version}</version>
@@ -162,14 +200,18 @@
             <artifactId>commons-logging</artifactId>
             <version>1.1.1</version>
         </dependency>
-       <dependency>
+        <dependency>
             <groupId>org.smslib</groupId>
             <artifactId>smslib</artifactId>
             <version>3.4.1</version>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
 
-
- </dependencies>
+    </dependencies>
     <properties>
         <jsmpp-version>2.0.1</jsmpp-version>
         <slf4j-version>1.4.3</slf4j-version>

Added: 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SMSTransportTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SMSTransportTest.java?rev=805457&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SMSTransportTest.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SMSTransportTest.java
 Tue Aug 18 15:39:55 2009
@@ -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.axis2.transport.sms;
+
+import junit.framework.TestCase;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.transport.sms.smpp.SimpleSMSC;
+import org.apache.axis2.transport.sms.smpp.SMSCMessageNotifier;
+import org.apache.axis2.transport.sms.smpp.MessageHolder;
+
+import java.io.File;
+import java.io.IOException;
+
+public class SMSTransportTest extends TestCase {
+
+    private SimpleSMSC smsc;
+    private SMSCMessageNotifier notifier = SMSCMessageNotifier.getInstence();
+    private MessageHolder holder = new MessageHolder();
+
+    public SMSTransportTest() {
+        super(SMSTransportTest.class.getName());
+    }
+
+
+    protected void setUp() throws Exception {
+        smsc = new SimpleSMSC();
+        smsc.startServer();
+        int index = 0;
+        Thread.sleep(2000);
+        while (!smsc.isStarted()) {
+            index++;
+            Thread.sleep(2000);
+            if(index >=10){
+                throw new Exception("It Takes more than 10s to start The 
SMSC");
+            }
+        }
+        //start the Axis2 inscence
+        File file = new 
File(prefixBaseDirectory(Constants.TESTING_REPOSITORY));
+        System.out.println(file.getAbsoluteFile());
+        if (!file.exists()) {
+
+            throw new Exception("Repository directory does not exist");
+        }
+
+
+        ConfigurationContext confContext = 
ConfigurationContextFactory.createConfigurationContextFromFileSystem(
+                file.getAbsolutePath() + "/repository",
+                file.getAbsolutePath() + "/conf/axis2.xml");
+
+
+        ListenerManager lmaneger = new ListenerManager();
+
+        lmaneger.startSystem(confContext);
+        System.out.println(" [Axis2] test Server started on port 2776 ");
+
+
+    }
+
+    public void testSMPPImplimentaion() throws Exception {
+        notifier.addObserver(holder);
+        holder.setHaveMessage(false);
+        smsc.deliverSMS("0896754535", "0676556367", 
"SampleService:SampleInOutOperation");
+
+        int index = 0;
+        while (!holder.isHaveMessage()) {
+
+            Thread.sleep(1000);
+            index++;
+            if (index > 10) {
+                throw new AxisFault("Server was shutdown as the async response 
take too long to complete");
+            }
+        }
+
+        assertEquals("Sucess", holder.getSms());
+        holder.setHaveMessage(false);
+
+    }
+
+    public static String prefixBaseDirectory(String path) {
+        String baseDir;
+        try {
+            baseDir = new File(System.getProperty("basedir", 
".")).getCanonicalPath();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return baseDir + "/" + path;
+    }
+
+
+}

Added: 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.java?rev=805457&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/SimpleInOutMessageReceiver.java
 Tue Aug 18 15:39:55 2009
@@ -0,0 +1,66 @@
+/*
+ *  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;
+
+import org.apache.axis2.receivers.AbstractInOutMessageReceiver;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.AxisFault;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMElement;
+
+/**
+ * A Simple Message reveiver used for the SMS Transport Test.
+ */
+public class SimpleInOutMessageReceiver extends AbstractInOutMessageReceiver {
+
+
+    public void invokeBusinessLogic(MessageContext inMessageContext,
+                                    MessageContext outMessageContext) throws 
AxisFault {
+        log.debug("Got The message to the MessageReceiver");
+
+
+        String soapNamespace = 
inMessageContext.getEnvelope().getNamespace().getNamespaceURI();
+        // creating a soap factory according the the soap namespce uri
+        SOAPFactory soapFactory = null;
+        if (soapNamespace.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)){
+            soapFactory = OMAbstractFactory.getSOAP11Factory();
+        } else if 
(soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)){
+            soapFactory = OMAbstractFactory.getSOAP12Factory();
+        } else {
+            System.out.println("Unknow soap message");
+        }
+
+        SOAPEnvelope responseEnvelope = soapFactory.getDefaultEnvelope();
+
+        // creating a body element
+        OMFactory omFactory = OMAbstractFactory.getOMFactory();
+        OMNamespace omNamespace = 
omFactory.createOMNamespace("http://sms.test","ns1";);
+        OMElement omElement = omFactory.createOMElement("Response", 
omNamespace);
+        omElement.setText("Sucess");
+        responseEnvelope.getBody().addChild(omElement);
+
+        outMessageContext.setEnvelope(responseEnvelope);
+    }
+}

Added: 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/MessageHolder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/MessageHolder.java?rev=805457&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/MessageHolder.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/MessageHolder.java
 Tue Aug 18 15:39:55 2009
@@ -0,0 +1,51 @@
+/*
+ *  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.smpp;
+
+import org.jsmpp.bean.SubmitSm;
+
+/**
+ * Message Hoder will hold the incomming shotmessages so that they can be 
processed.
+ */
+public class MessageHolder implements SMSCMessageObserver{
+
+    private boolean haveMessage = false;
+    private String sms = null;
+    public void messsageIn(SubmitSm msg) {
+        sms = new String(msg.getShortMessage());
+        sms = sms.trim();
+        haveMessage = true;
+    }
+
+    public boolean isHaveMessage() {
+        return haveMessage;
+    }
+
+    public void setHaveMessage(boolean haveMessage) {
+        this.haveMessage = haveMessage;
+    }
+
+    public String getSms() {
+        return sms;
+    }
+
+    public void setSms(String sms) {
+        this.sms = sms;
+    }
+}

Added: 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageNotifier.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageNotifier.java?rev=805457&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageNotifier.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageNotifier.java
 Tue Aug 18 15:39:55 2009
@@ -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.axis2.transport.sms.smpp;
+
+import org.jsmpp.bean.SubmitSm;
+
+import java.util.ArrayList;
+
+/**
+ * Manage the SMSCMessageObservers and notify them when a new SMSC message is 
came in
+ */
+public class SMSCMessageNotifier {
+
+    private ArrayList<SMSCMessageObserver> observers = new 
ArrayList<SMSCMessageObserver>();
+
+    private static SMSCMessageNotifier smsMessageNotifier = new 
SMSCMessageNotifier();
+    private SMSCMessageNotifier() {
+
+    }
+    public static SMSCMessageNotifier getInstence() {
+        return smsMessageNotifier;
+    }
+
+    /**
+     * Notify the registered Observer about the incomming shotMessage
+     * @param sm
+     */
+    public void notifyObservers(SubmitSm sm) {
+        for(SMSCMessageObserver o : observers) {
+            o.messsageIn(sm);    
+        }
+    }
+
+    /**
+     * register the SMSCMessageObserver with the SMSCMessageNotifier so that 
observer will get notified
+     * when the new shot message came from the SMSC
+     * @param o
+     */
+    public void addObserver(SMSCMessageObserver o) {
+        if(o != null) {
+            observers.add(o);
+        }
+    }
+
+    /**
+     * Un register the SMSCMessageObserver so that Observer will not notifed 
of new Shot Message arrivals after that
+     * @param o
+     */
+    public void removeObserver(SMSCMessageObserver o) {
+
+        observers.remove(o);
+    }
+
+}

Added: 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageObserver.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageObserver.java?rev=805457&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageObserver.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SMSCMessageObserver.java
 Tue Aug 18 15:39:55 2009
@@ -0,0 +1,37 @@
+/*
+ *  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.smpp;
+
+import org.apache.axis2.transport.sms.SMSMessage;
+import org.jsmpp.bean.SubmitSm;
+
+
+/**
+ * SMSCMessageObserver will be notifed when the message came in to the SMSC
+ * from a ESME.
+ * To use this observer it must be regietered in the SMSCMessageNotifier
+ */
+public interface SMSCMessageObserver {
+
+    /**
+     * Notify the Mesage in to the SMSC
+     * @param msg ShotMessage that received to the SMSC/
+     */
+    public void messsageIn(SubmitSm msg);
+}

Added: 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SimpleSMSC.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SimpleSMSC.java?rev=805457&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SimpleSMSC.java
 (added)
+++ 
webservices/commons/trunk/modules/transport/modules/sms/src/test/java/org/apache/axis2/transport/sms/smpp/SimpleSMSC.java
 Tue Aug 18 15:39:55 2009
@@ -0,0 +1,178 @@
+/*
+ *  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.smpp;
+
+import org.jsmpp.session.*;
+import org.jsmpp.util.MessageId;
+import org.jsmpp.util.MessageIDGenerator;
+import org.jsmpp.util.RandomMessageIDGenerator;
+import org.jsmpp.bean.*;
+import org.jsmpp.extra.ProcessRequestException;
+import org.jsmpp.PDUStringException;
+import org.jsmpp.SMPPConstant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeoutException;
+import java.io.IOException;
+
+
+/**
+ * This is a simulator of a Shot message service center
+ * this is written for the test perposes of the SMPP
+ * implementation of the SMS Transport
+ *
+ */
+public class SimpleSMSC  extends ServerResponseDeliveryAdapter implements 
Runnable, ServerMessageReceiverListener {
+    private static final Integer DEFAULT_PORT = 2776;
+    private static final Logger logger = 
LoggerFactory.getLogger(SimpleSMSC.class);
+    private final ExecutorService execService = 
Executors.newFixedThreadPool(5);
+    private final MessageIDGenerator messageIDGenerator = new 
RandomMessageIDGenerator();
+    private int port = DEFAULT_PORT;
+    private SMSCMessageNotifier notifier;
+    private boolean started =false;
+    private SMPPServerSession serverSession = null;
+
+    public SimpleSMSC() {
+        notifier = SMSCMessageNotifier.getInstence();
+    }
+
+
+    /**
+     * Delever short message to a bineded ESMC s
+     * @param sender
+     * @param receiver
+     * @param content
+     * @throws Exception
+     */
+     public void deliverSMS(String sender , String receiver , String content) 
throws Exception{
+
+        this.serverSession.deliverShortMessage(
+                "CMT",
+                TypeOfNumber.UNKNOWN ,
+                NumberingPlanIndicator.UNKNOWN ,
+                receiver ,
+                TypeOfNumber.UNKNOWN ,
+                NumberingPlanIndicator.UNKNOWN ,
+                sender ,
+                new ESMClass() ,
+                (byte)0 ,
+                (byte)0,
+                new RegisteredDelivery(0),
+                DataCoding.newInstance(0),
+                content.getBytes());
+    }
+
+    public void run() {
+        try {
+            SMPPServerSessionListener sessionListener = new 
SMPPServerSessionListener(port);
+
+            System.out.println("Simple SMSC Listening on port :: " +  port);
+            started = true;
+            while (true) {
+                serverSession = sessionListener.accept();
+                serverSession.setMessageReceiverListener(this);
+                serverSession.setResponseDeliveryListener(this);
+                execService.execute(new WaitBindTask(serverSession));
+                Thread.sleep(1000);
+
+            }
+        } catch (Exception e) {
+            logger.error("IO error occured", e);
+        }
+    }
+
+    public MessageId onAcceptSubmitSm(SubmitSm submitSm, SMPPServerSession 
smppServerSession) throws ProcessRequestException {
+        MessageId messageId = messageIDGenerator.newMessageId();
+        notifier.notifyObservers(submitSm);
+        return messageId;
+    }
+
+    public SubmitMultiResult onAcceptSubmitMulti(SubmitMulti submitMulti, 
SMPPServerSession smppServerSession) throws ProcessRequestException {
+        return null;
+    }
+
+    public QuerySmResult onAcceptQuerySm(QuerySm querySm, SMPPServerSession 
smppServerSession) throws ProcessRequestException {
+        return null;
+    }
+
+    public void onAcceptReplaceSm(ReplaceSm replaceSm, SMPPServerSession 
smppServerSession) throws ProcessRequestException {
+
+    }
+
+    public void onAcceptCancelSm(CancelSm cancelSm, SMPPServerSession 
smppServerSession) throws ProcessRequestException {
+
+    }
+
+    public DataSmResult onAcceptDataSm(DataSm dataSm) throws 
ProcessRequestException {
+        return null;  
+    }
+
+    private class WaitBindTask implements Runnable {
+        private final SMPPServerSession serverSession;
+
+        public WaitBindTask(SMPPServerSession serverSession) {
+            this.serverSession = serverSession;
+        }
+
+        public void run() {
+            try {
+                BindRequest bindRequest = serverSession.waitForBind(1000);
+                logger.info("Accepting bind for session {}", 
serverSession.getSessionId());
+                try {
+                    bindRequest.accept("sys");
+                } catch (PDUStringException e) {
+                    logger.error("Invalid system id", e);
+                    bindRequest.reject(SMPPConstant.STAT_ESME_RSYSERR);
+                }
+
+            } catch (IllegalStateException e) {
+                logger.error("System error", e);
+            } catch (TimeoutException e) {
+                logger.warn("Wait for bind has reach timeout", e);
+            } catch (IOException e) {
+                logger.error("Failed accepting bind request for session {}", 
serverSession.getSessionId());
+            }
+        }
+    }
+
+    /**
+     * Start the SimpleSMSC server
+     */
+    public void startServer() {
+        Thread t = new Thread(this);
+        t.start();
+
+    }
+
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public boolean isStarted() {
+        return started;
+    }
+}


Reply via email to