Author: cmueller
Date: Sun Jun 13 21:48:26 2010
New Revision: 954316

URL: http://svn.apache.org/viewvc?rev=954316&view=rev
Log:
CAMEL-2782: camel-smpp should reconnect to SMSC

Added:
    
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppConsumerReconnectIntegrationTest.java
   (with props)
    
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppProducerReconnectIntegrationTest.java
   (with props)
Modified:
    
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
    
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
    
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
    
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
    
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java
    
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java

Modified: 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java?rev=954316&r1=954315&r2=954316&view=diff
==============================================================================
--- 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
 (original)
+++ 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
 Sun Jun 13 21:48:26 2010
@@ -54,6 +54,8 @@ public class SmppConfiguration implement
     private byte typeOfNumber = TypeOfNumber.UNKNOWN.value();
     private byte numberingPlanIndicator = 
NumberingPlanIndicator.UNKNOWN.value();
     private boolean usingSSL;
+    private long initialReconnectDelay = 5000;
+    private long reconnectDelay = 5000;
 
     /**
      * A POJO which contains all necessary configuration parameters for the 
SMPP connection
@@ -248,10 +250,26 @@ public class SmppConfiguration implement
     public boolean getUsingSSL() {
         return usingSSL;
     }
-
+    
     public void setUsingSSL(boolean usingSSL) {
         this.usingSSL = usingSSL;
     }
+    
+    public long getInitialReconnectDelay() {
+        return initialReconnectDelay;
+    }
+
+    public void setInitialReconnectDelay(long initialReconnectDelay) {
+        this.initialReconnectDelay = initialReconnectDelay;
+    }
+
+    public long getReconnectDelay() {
+        return reconnectDelay;
+    }
+
+    public void setReconnectDelay(long reconnectDelay) {
+        this.reconnectDelay = reconnectDelay;
+    }
 
     @Override
     public String toString() {
@@ -275,6 +293,9 @@ public class SmppConfiguration implement
             + ", sourceAddr=" + sourceAddr 
             + ", destAddr=" + destAddr 
             + ", typeOfNumber=" + typeOfNumber 
-            + ", numberingPlanIndicator=" + numberingPlanIndicator + "]";
+            + ", numberingPlanIndicator=" + numberingPlanIndicator
+            + ", initialReconnectDelay=" + initialReconnectDelay
+            + ", reconnectDelay=" + reconnectDelay
+            + "]";
     }
 }
\ No newline at end of file

Modified: 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java?rev=954316&r1=954315&r2=954316&view=diff
==============================================================================
--- 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
 (original)
+++ 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
 Sun Jun 13 21:48:26 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.smpp;
 
+import java.io.IOException;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
@@ -31,11 +33,13 @@ import org.jsmpp.bean.DeliverSm;
 import org.jsmpp.bean.NumberingPlanIndicator;
 import org.jsmpp.bean.TypeOfNumber;
 import org.jsmpp.extra.ProcessRequestException;
+import org.jsmpp.extra.SessionState;
 import org.jsmpp.session.BindParameter;
 import org.jsmpp.session.DataSmResult;
 import org.jsmpp.session.MessageReceiverListener;
 import org.jsmpp.session.SMPPSession;
 import org.jsmpp.session.Session;
+import org.jsmpp.session.SessionStateListener;
 import org.jsmpp.util.DefaultComposer;
 import org.jsmpp.util.MessageIDGenerator;
 import org.jsmpp.util.MessageId;
@@ -53,27 +57,28 @@ public class SmppConsumer extends Defaul
 
     private SmppConfiguration configuration;
     private SMPPSession session;
+    private MessageReceiverListener messageReceiverListener;
+    private SessionStateListener sessionStateListener;
 
     /**
-     * The constructor which gets a smpp endpoint, a smpp configuration and a 
processor
+     * The constructor which gets a smpp endpoint, a smpp configuration and a
+     * processor
      */
-    public SmppConsumer(SmppEndpoint endpoint, SmppConfiguration 
configuration, Processor processor) {
+    public SmppConsumer(SmppEndpoint endpoint, SmppConfiguration config, 
Processor processor) {
         super(endpoint, processor);
-        this.configuration = configuration;
-    }
-
-    @Override
-    protected void doStart() throws Exception {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Connecting to: " + getEndpoint().getConnectionString() 
+ "...");
-        }
-
-        super.doStart();
 
-        session = createSMPPSession();
-        session.setEnquireLinkTimer(this.configuration.getEnquireLinkTimer());
-        session.setTransactionTimer(this.configuration.getTransactionTimer());
-        session.setMessageReceiverListener(new MessageReceiverListener() {
+        this.configuration = config;
+        this.sessionStateListener = new SessionStateListener() {
+            public void onStateChange(SessionState newState, SessionState 
oldState, Object source) {
+                if (newState.equals(SessionState.CLOSED)) {
+                    LOG.warn("Loost connection to: " + 
getEndpoint().getConnectionString()
+                            + " - trying to reconnect...");
+                    closeSession(session);
+                    reconnect(configuration.getInitialReconnectDelay());
+                }
+            }
+        };
+        this.messageReceiverListener = new MessageReceiverListener() {
             private final MessageIDGenerator messageIDGenerator = new 
RandomMessageIDGenerator();
 
             public void onAcceptAlertNotification(AlertNotification 
alertNotification) {
@@ -82,7 +87,8 @@ public class SmppConsumer extends Defaul
                 }
 
                 try {
-                    Exchange exchange = 
getEndpoint().createOnAcceptAlertNotificationExchange(alertNotification);
+                    Exchange exchange = 
getEndpoint().createOnAcceptAlertNotificationExchange(
+                            alertNotification);
 
                     LOG.trace("Processing the new smpp exchange...");
                     getProcessor().process(exchange);
@@ -108,15 +114,17 @@ public class SmppConsumer extends Defaul
                 }
             }
 
-            public DataSmResult onAcceptDataSm(DataSm dataSm, Session session) 
 throws ProcessRequestException {
+            public DataSmResult onAcceptDataSm(DataSm dataSm, Session session)
+                throws ProcessRequestException {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Received a dataSm " + dataSm);
                 }
 
                 MessageId newMessageId = messageIDGenerator.newMessageId();
-                
+
                 try {
-                    Exchange exchange = 
getEndpoint().createOnAcceptDataSm(dataSm, newMessageId.getValue());
+                    Exchange exchange = 
getEndpoint().createOnAcceptDataSm(dataSm,
+                            newMessageId.getValue());
 
                     LOG.trace("processing the new smpp exchange...");
                     getProcessor().process(exchange);
@@ -125,26 +133,37 @@ public class SmppConsumer extends Defaul
                     getExceptionHandler().handleException(e);
                     throw new ProcessRequestException(e.getMessage(), 255, e);
                 }
-                
+
                 return new DataSmResult(newMessageId, 
dataSm.getOptionalParametes());
             }
-        });
+        };
+    }
 
-        session.connectAndBind(
-                this.configuration.getHost(),
-                this.configuration.getPort(),
-                new BindParameter(
-                        BindType.BIND_RX,
-                        this.configuration.getSystemId(),
-                        this.configuration.getPassword(),
-                        this.configuration.getSystemType(),
-                        TypeOfNumber.UNKNOWN,
-                        NumberingPlanIndicator.UNKNOWN,
-                        ""));
+    @Override
+    protected void doStart() throws Exception {
+        LOG.debug("Connecting to: " + getEndpoint().getConnectionString() + 
"...");
+
+        super.doStart();
+        session = createSession();
 
         LOG.info("Connected to: " + getEndpoint().getConnectionString());
     }
 
+    private SMPPSession createSession() throws IOException {
+        SMPPSession session = createSMPPSession();
+        session = createSMPPSession();
+        session.setEnquireLinkTimer(configuration.getEnquireLinkTimer());
+        session.setTransactionTimer(configuration.getTransactionTimer());
+        session.addSessionStateListener(sessionStateListener);
+        session.setMessageReceiverListener(messageReceiverListener);
+        session.connectAndBind(this.configuration.getHost(), 
this.configuration.getPort(),
+                new BindParameter(BindType.BIND_RX, 
this.configuration.getSystemId(),
+                        this.configuration.getPassword(), 
this.configuration.getSystemType(),
+                        TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, 
""));
+        
+        return session;
+    }
+    
     /**
      * Factory method to easily instantiate a mock SMPPSession
      * 
@@ -152,8 +171,9 @@ public class SmppConsumer extends Defaul
      */
     SMPPSession createSMPPSession() {
         if (configuration.getUsingSSL()) {
-            return new SMPPSession(new SynchronizedPDUSender(new 
DefaultPDUSender(new DefaultComposer())),
-                new DefaultPDUReader(), 
SmppSSLConnectionFactory.getInstance());
+            return new SMPPSession(new SynchronizedPDUSender(new 
DefaultPDUSender(
+                    new DefaultComposer())), new DefaultPDUReader(), 
SmppSSLConnectionFactory
+                    .getInstance());
         } else {
             return new SMPPSession();
         }
@@ -164,13 +184,46 @@ public class SmppConsumer extends Defaul
         LOG.debug("Disconnecting from: " + getEndpoint().getConnectionString() 
+ "...");
 
         super.doStop();
+        closeSession(session);
 
+        LOG.info("Disconnected from: " + getEndpoint().getConnectionString());
+    }
+
+    private void closeSession(SMPPSession session) {
         if (session != null) {
+            session.removeSessionStateListener(this.sessionStateListener);
             session.close();
             session = null;
         }
+    }
 
-        LOG.info("Disconnected from: " + getEndpoint().getConnectionString());
+    private void reconnect(final long initialReconnectDelay) {
+        new Thread() {
+            @Override
+            public void run() {
+                LOG.info("Schedule reconnect after " + initialReconnectDelay + 
" millis");
+                try {
+                    Thread.sleep(initialReconnectDelay);
+                } catch (InterruptedException e) {
+                }
+
+                int attempt = 0;
+                while (!(isStopping() || isStopped()) && (session == null || 
session.getSessionState().equals(SessionState.CLOSED))) {
+                    try {
+                        LOG.info("Trying to reconnect to " + 
getEndpoint().getConnectionString() + " - attempt #" + (++attempt) + "...");
+                        session = createSession();
+                    } catch (IOException e) {
+                        LOG.info("Failed to reconnect to " + 
getEndpoint().getConnectionString());
+                        closeSession(session);
+                        try {
+                            Thread.sleep(configuration.getReconnectDelay());
+                        } catch (InterruptedException ee) {
+                        }
+                    }
+                }
+                LOG.info("Reconnected to " + 
getEndpoint().getConnectionString());
+            }
+        }.start();
     }
 
     @Override
@@ -191,5 +244,4 @@ public class SmppConsumer extends Defaul
     public SmppConfiguration getConfiguration() {
         return configuration;
     }
-
 }
\ No newline at end of file

Modified: 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java?rev=954316&r1=954315&r2=954316&view=diff
==============================================================================
--- 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
 (original)
+++ 
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
 Sun Jun 13 21:48:26 2010
@@ -24,8 +24,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jsmpp.DefaultPDUReader;
 import org.jsmpp.DefaultPDUSender;
-import org.jsmpp.InvalidResponseException;
-import org.jsmpp.PDUException;
 import org.jsmpp.SynchronizedPDUSender;
 import org.jsmpp.bean.Alphabet;
 import org.jsmpp.bean.BindType;
@@ -36,10 +34,10 @@ import org.jsmpp.bean.NumberingPlanIndic
 import org.jsmpp.bean.RegisteredDelivery;
 import org.jsmpp.bean.SubmitSm;
 import org.jsmpp.bean.TypeOfNumber;
-import org.jsmpp.extra.NegativeResponseException;
-import org.jsmpp.extra.ResponseTimeoutException;
+import org.jsmpp.extra.SessionState;
 import org.jsmpp.session.BindParameter;
 import org.jsmpp.session.SMPPSession;
+import org.jsmpp.session.SessionStateListener;
 import org.jsmpp.util.DefaultComposer;
 
 /**
@@ -54,23 +52,37 @@ public class SmppProducer extends Defaul
 
     private SmppConfiguration configuration;
     private SMPPSession session;
+    private SessionStateListener sessionStateListener;
 
-    public SmppProducer(SmppEndpoint endpoint, SmppConfiguration 
configuration) {
+    public SmppProducer(SmppEndpoint endpoint, SmppConfiguration config) {
         super(endpoint);
-        this.configuration = configuration;
+        this.configuration = config;
+        this.sessionStateListener = new SessionStateListener() { 
+            public void onStateChange(SessionState newState, SessionState 
oldState, Object source) {
+                if (newState.equals(SessionState.CLOSED)) {
+                    LOG.warn("Loosing connection to: " + 
getEndpoint().getConnectionString() + " - trying to reconnect...");
+                    closeSession(session);
+                    reconnect(configuration.getInitialReconnectDelay());
+                }
+            }
+        };
     }
 
     @Override
     protected void doStart() throws Exception {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Connecting to: " + getEndpoint().getConnectionString() 
+ "...");
-        }
+        LOG.debug("Connecting to: " + getEndpoint().getConnectionString() + 
"...");
 
         super.doStart();
+        session = createSession();
 
-        session = createSMPPSession();
+        LOG.info("Connected to: " + getEndpoint().getConnectionString());
+    }
+    
+    private SMPPSession createSession() throws IOException {
+        SMPPSession session = createSMPPSession();
         session.setEnquireLinkTimer(this.configuration.getEnquireLinkTimer());
         session.setTransactionTimer(this.configuration.getTransactionTimer());
+        session.addSessionStateListener(sessionStateListener);
         session.connectAndBind(
                 this.configuration.getHost(),
                 this.configuration.getPort(),
@@ -82,8 +94,8 @@ public class SmppProducer extends Defaul
                         TypeOfNumber.valueOf(configuration.getTypeOfNumber()),
                         
NumberingPlanIndicator.valueOf(configuration.getNumberingPlanIndicator()),
                         ""));
-
-        LOG.info("Connected to: " + getEndpoint().getConnectionString());
+        
+        return session;
     }
     
     /**
@@ -105,45 +117,13 @@ public class SmppProducer extends Defaul
             LOG.debug("Sending a short message for exchange id '"
                     + exchange.getExchangeId() + "'...");
         }
-
-        SubmitSm submitSm = 
getEndpoint().getBinding().createSubmitSm(exchange);
-        String messageId;
-        try {
-            messageId = doProcess(submitSm);
-        } catch (Exception e) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Caught exception while trying to send short message 
for exchange id '"
-                        + exchange.getExchangeId() + "', retrying...", e);
-            }
-            doStop();
-            doStart();
-            
-            messageId = doProcess(submitSm);
+        
+        // only possible by trying to reconnect 
+        if (this.session == null) {
+            throw new IOException("Lost connection to " + 
getEndpoint().getConnectionString() + " and yet not reconnected");
         }
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Sent a short message for exchange id '"
-                    + exchange.getExchangeId() + "' and received message id '"
-                    + messageId + "'");
-        }
-
-        if (exchange.getPattern().isOutCapable()) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Exchange is out capable, setting headers on out 
exchange...");
-            }
-            exchange.getOut().setHeader(SmppBinding.ID, messageId);
-        } else {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Exchange is not out capable, setting headers on in 
exchange...");
-            }
-            exchange.getIn().setHeader(SmppBinding.ID, messageId);
-        }
-    }
-
-    private String doProcess(SubmitSm submitSm) throws PDUException,
-            ResponseTimeoutException, InvalidResponseException,
-            NegativeResponseException, IOException {
-
+        SubmitSm submitSm = 
getEndpoint().getBinding().createSubmitSm(exchange);
         String messageId = session.submitShortMessage(
                 submitSm.getServiceType(), 
                 TypeOfNumber.valueOf(submitSm.getSourceAddrTon()),
@@ -167,25 +147,72 @@ public class SmppProducer extends Defaul
                 (byte) 0,
                 submitSm.getShortMessage());
 
-        return messageId;
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Sent a short message for exchange id '"
+                    + exchange.getExchangeId() + "' and received message id '"
+                    + messageId + "'");
+        }
+
+        if (exchange.getPattern().isOutCapable()) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Exchange is out capable, setting headers on out 
exchange...");
+            }
+            exchange.getOut().setHeader(SmppBinding.ID, messageId);
+        } else {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Exchange is not out capable, setting headers on in 
exchange...");
+            }
+            exchange.getIn().setHeader(SmppBinding.ID, messageId);
+        }
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Disconnecting from: " + 
getEndpoint().getConnectionString() + "...");
-        }
+        LOG.debug("Disconnecting from: " + getEndpoint().getConnectionString() 
+ "...");
 
         super.doStop();
+        closeSession(session);
 
+        LOG.info("Disconnected from: " + getEndpoint().getConnectionString());
+    }
+    
+    private void closeSession(SMPPSession session) {
         if (session != null) {
+            session.removeSessionStateListener(this.sessionStateListener);
             session.close();
             session = null;
         }
-
-        LOG.info("Disconnected from: " + getEndpoint().getConnectionString());
     }
 
+    private void reconnect(final long initialReconnectDelay) {
+        new Thread() {
+            @Override
+            public void run() {
+                LOG.info("Schedule reconnect after " + initialReconnectDelay + 
" millis");
+                try {
+                    Thread.sleep(initialReconnectDelay);
+                } catch (InterruptedException e) {
+                }
+
+                int attempt = 0;
+                while (!(isStopping() || isStopped()) && (session == null || 
session.getSessionState().equals(SessionState.CLOSED))) {
+                    try {
+                        LOG.info("Trying to reconnect to " + 
getEndpoint().getConnectionString() + " - attempt #" + (++attempt) + "...");
+                        session = createSession();
+                    } catch (IOException e) {
+                        LOG.info("Failed to reconnect to " + 
getEndpoint().getConnectionString());
+                        closeSession(session);
+                        try {
+                            Thread.sleep(configuration.getReconnectDelay());
+                        } catch (InterruptedException ee) {
+                        }
+                    }
+                }
+                LOG.info("Reconnected to " + 
getEndpoint().getConnectionString());
+            }
+        }.start();
+    }
+    
     @Override
     public SmppEndpoint getEndpoint() {
         return (SmppEndpoint) super.getEndpoint();
@@ -204,5 +231,4 @@ public class SmppProducer extends Defaul
     public String toString() {
         return "SmppProducer[" + getEndpoint().getConnectionString() + "]";
     }
-
 }
\ No newline at end of file

Modified: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java?rev=954316&r1=954315&r2=954316&view=diff
==============================================================================
--- 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
 (original)
+++ 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
 Sun Jun 13 21:48:26 2010
@@ -66,6 +66,8 @@ public class SmppConfigurationTest {
         assertEquals(0x00, configuration.getNumberingPlanIndicator());
         assertEquals(0x00, configuration.getTypeOfNumber());
         assertEquals(false, configuration.getUsingSSL());
+        assertEquals(5000, configuration.getInitialReconnectDelay());
+        assertEquals(5000, configuration.getReconnectDelay());
     }
     
     @Test
@@ -94,6 +96,8 @@ public class SmppConfigurationTest {
         assertEquals(0x08, configuration.getNumberingPlanIndicator());
         assertEquals(0x02, configuration.getTypeOfNumber());
         assertEquals(true, configuration.getUsingSSL());
+        assertEquals(5001, configuration.getInitialReconnectDelay());
+        assertEquals(5002, configuration.getReconnectDelay());
     }
 
     @Test
@@ -132,6 +136,9 @@ public class SmppConfigurationTest {
         assertEquals(config.getNumberingPlanIndicator(), 
configuration.getNumberingPlanIndicator());
         assertEquals(config.getTypeOfNumber(), 
configuration.getTypeOfNumber());
         assertEquals(config.getUsingSSL(), configuration.getUsingSSL());
+        assertEquals(config.getInitialReconnectDelay(), 
configuration.getInitialReconnectDelay());
+        assertEquals(config.getReconnectDelay(), 
configuration.getReconnectDelay());
+        
     }
     
     @Test
@@ -157,7 +164,9 @@ public class SmppConfigurationTest {
                 + "sourceAddr=1616, "
                 + "destAddr=1717, "
                 + "typeOfNumber=0, "
-                + "numberingPlanIndicator=0]";
+                + "numberingPlanIndicator=0, "
+                + "initialReconnectDelay=5000, "
+                + "reconnectDelay=5000]";
         assertEquals(expected, configuration.toString());
     }
 
@@ -184,5 +193,7 @@ public class SmppConfigurationTest {
         
config.setNumberingPlanIndicator(NumberingPlanIndicator.NATIONAL.value());
         config.setTypeOfNumber(TypeOfNumber.NATIONAL.value());
         config.setUsingSSL(true);
+        config.setInitialReconnectDelay(5001);
+        config.setReconnectDelay(5002);
     }
 }
\ No newline at end of file

Modified: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java?rev=954316&r1=954315&r2=954316&view=diff
==============================================================================
--- 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java
 (original)
+++ 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java
 Sun Jun 13 21:48:26 2010
@@ -23,6 +23,7 @@ import org.jsmpp.bean.TypeOfNumber;
 import org.jsmpp.session.BindParameter;
 import org.jsmpp.session.MessageReceiverListener;
 import org.jsmpp.session.SMPPSession;
+import org.jsmpp.session.SessionStateListener;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -68,6 +69,7 @@ public class SmppConsumerTest {
             .times(2);
         session.setEnquireLinkTimer(5000); //expectation
         session.setTransactionTimer(10000); //expectation
+        session.addSessionStateListener(isA(SessionStateListener.class));
         
session.setMessageReceiverListener(isA(MessageReceiverListener.class)); 
//expectation
         expect(session.connectAndBind(
                 "localhost",
@@ -110,6 +112,7 @@ public class SmppConsumerTest {
         expect(endpoint.getConnectionString())
             .andReturn("smpp://smppcli...@localhost:2775")
             .times(3);
+        session.removeSessionStateListener(isA(SessionStateListener.class));
         session.close();
         
         replay(session, endpoint);

Modified: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java?rev=954316&r1=954315&r2=954316&view=diff
==============================================================================
--- 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java
 (original)
+++ 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java
 Sun Jun 13 21:48:26 2010
@@ -33,6 +33,7 @@ import org.jsmpp.bean.SubmitSm;
 import org.jsmpp.bean.TypeOfNumber;
 import org.jsmpp.session.BindParameter;
 import org.jsmpp.session.SMPPSession;
+import org.jsmpp.session.SessionStateListener;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -77,6 +78,7 @@ public class SmppProducerTest {
             .times(2);
         session.setEnquireLinkTimer(5000); //expectation
         session.setTransactionTimer(10000); //expectation
+        session.addSessionStateListener(isA(SessionStateListener.class));
         expect(session.connectAndBind(
             "localhost",
             new Integer(2775),
@@ -140,6 +142,7 @@ public class SmppProducerTest {
         expect(endpoint.getConnectionString())
             .andReturn("smpp://smppcli...@localhost:2775")
             .times(2);
+        session.removeSessionStateListener(isA(SessionStateListener.class));
         session.close();
         expect(endpoint.getConnectionString())
             .andReturn("smpp://smppcli...@localhost:2775");
@@ -247,88 +250,6 @@ public class SmppProducerTest {
     }
     
     @Test
-    public void processShouldDoAReconnectAfterAnIOException() throws Exception 
{
-        doStartExpectations();
-        SmppBinding binding = createMock(SmppBinding.class);
-        Exchange exchange = createMock(Exchange.class);
-        Message message = createMock(Message.class);
-        SubmitSm submitSm = createMock(SubmitSm.class);
-        
expect(exchange.getExchangeId()).andReturn("ID-muellerc-macbookpro/3690-1214458315718/2-0");
-        expect(endpoint.getBinding()).andReturn(binding);
-        
expect(exchange.getExchangeId()).andReturn("ID-muellerc-macbookpro/3690-1214458315718/2-0");
-        expect(binding.createSubmitSm(exchange)).andReturn(submitSm);
-        submitSmExpectations(exchange, binding, submitSm);
-        expect(session.submitShortMessage(
-                eq("CMT"),
-                eq(TypeOfNumber.UNKNOWN),
-                eq(NumberingPlanIndicator.UNKNOWN),
-                eq("1616"),
-                eq(TypeOfNumber.UNKNOWN),
-                eq(NumberingPlanIndicator.UNKNOWN),
-                eq("1717"),
-                isA(ESMClass.class),
-                eq((byte) 0),
-                eq((byte) 1),
-                eq("090830230627004+"),
-                eq("090831232000004+"),
-                eq(new 
RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE)),
-                eq((byte) 0),
-                eq(new GeneralDataCoding(
-                        false,
-                        false,
-                        MessageClass.CLASS1,
-                        Alphabet.ALPHA_DEFAULT)),
-                eq((byte) 0),
-                aryEq("Hello SMPP world!".getBytes("ISO-8859-1"))))
-            .andThrow(new IOException("connection broken"));
-        
-        expect(endpoint.getConnectionString())
-            .andReturn("smpp://smppcli...@localhost:2775")
-            .times(2);
-        session.close(); // expectation without return value
-        expect(endpoint.getConnectionString())
-            .andReturn("smpp://smppcli...@localhost:2775");
-
-        doStartExpectations();
-        
-        submitSmExpectations(exchange, binding, submitSm);
-        expect(session.submitShortMessage(
-                eq("CMT"),
-                eq(TypeOfNumber.UNKNOWN),
-                eq(NumberingPlanIndicator.UNKNOWN),
-                eq("1616"),
-                eq(TypeOfNumber.UNKNOWN),
-                eq(NumberingPlanIndicator.UNKNOWN),
-                eq("1717"),
-                isA(ESMClass.class),
-                eq((byte) 0),
-                eq((byte) 1),
-                eq("090830230627004+"),
-                eq("090831232000004+"),
-                eq(new 
RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE)),
-                eq((byte) 0),
-                eq(new GeneralDataCoding(
-                        false,
-                        false,
-                        MessageClass.CLASS1,
-                        Alphabet.ALPHA_DEFAULT)),
-                eq((byte) 0),
-                aryEq("Hello SMPP world!".getBytes("ISO-8859-1"))))
-            .andReturn("1");
-        expect(exchange.getPattern()).andReturn(ExchangePattern.InOnly);
-        expect(exchange.getIn()).andReturn(message);
-        message.setHeader(SmppBinding.ID, "1"); // expectation without return 
value
-        
expect(exchange.getExchangeId()).andReturn("ID-muellerc-macbookpro/3690-1214458315718/2-0");
-        
-        replay(session, endpoint, binding, exchange, message, submitSm);
-        
-        producer.doStart();
-        producer.process(exchange);
-        
-        verify(session, endpoint, binding, exchange, message, submitSm);
-    }
-
-    @Test
     public void getterShouldReturnTheSetValues() {
         assertSame(endpoint, producer.getEndpoint());
         assertSame(configuration, producer.getConfiguration());

Added: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppConsumerReconnectIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppConsumerReconnectIntegrationTest.java?rev=954316&view=auto
==============================================================================
--- 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppConsumerReconnectIntegrationTest.java
 (added)
+++ 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppConsumerReconnectIntegrationTest.java
 Sun Jun 13 21:48:26 2010
@@ -0,0 +1,54 @@
+/**
+ * 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.camel.component.smpp.integration;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Spring based integration test for the smpp component. To run this test, 
ensure that
+ * the SMSC is running on:
+ * host:     localhost
+ * port:     2775
+ * user:     smppclient
+ * password: password
+ * <br/>
+ * A SMSC for test is available here: 
http://www.seleniumsoftware.com/downloads.html
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+...@ignore("Must be manually tested")
+public class SmppConsumerReconnectIntegrationTest extends CamelTestSupport {
+
+    @Test
+    public void test() throws Exception {
+        Thread.sleep(1000000);
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
from("smpp://smppcli...@localhost:2775?password=password&enquireLinkTimer=3000&transactionTimer=5000&systemType=consumer")
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppConsumerReconnectIntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppConsumerReconnectIntegrationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppProducerReconnectIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppProducerReconnectIntegrationTest.java?rev=954316&view=auto
==============================================================================
--- 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppProducerReconnectIntegrationTest.java
 (added)
+++ 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppProducerReconnectIntegrationTest.java
 Sun Jun 13 21:48:26 2010
@@ -0,0 +1,54 @@
+/**
+ * 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.camel.component.smpp.integration;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Spring based integration test for the smpp component. To run this test, 
ensure that
+ * the SMSC is running on:
+ * host:     localhost
+ * port:     2775
+ * user:     smppclient
+ * password: password
+ * <br/>
+ * A SMSC for test is available here: 
http://www.seleniumsoftware.com/downloads.html
+ * 
+ * @version $Revision$
+ * @author muellerc
+ */
+...@ignore("Must be manually tested")
+public class SmppProducerReconnectIntegrationTest extends CamelTestSupport {
+
+    @Test
+    public void test() throws Exception {
+        Thread.sleep(1000000);
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    
.to("smpp://smppcli...@localhost:2775?password=password&enquireLinkTimer=3000&transactionTimer=5000&systemType=producerr");
+            }
+        };
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppProducerReconnectIntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppProducerReconnectIntegrationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to