camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1345771 - in /camel/branches/camel-2.9.x/components/camel-smpp: ./ src/main/java/org/apache/camel/component/smpp/ src/test/java/org/apache/camel/component/smpp/
Date Sun, 03 Jun 2012 20:32:36 GMT
Author: cmueller
Date: Sun Jun  3 20:32:36 2012
New Revision: 1345771

URL: http://svn.apache.org/viewvc?rev=1345771&view=rev
Log:
CAMEL-5043: Provision for setting a custom SessionStateListener

Modified:
    camel/branches/camel-2.9.x/components/camel-smpp/pom.xml
    camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
    camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
    camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
    camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
    camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java
    camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java

Modified: camel/branches/camel-2.9.x/components/camel-smpp/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-smpp/pom.xml?rev=1345771&r1=1345770&r2=1345771&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-smpp/pom.xml (original)
+++ camel/branches/camel-2.9.x/components/camel-smpp/pom.xml Sun Jun  3 20:32:36 2012
@@ -74,7 +74,6 @@
         <dependency>
             <groupId>org.easymock</groupId>
             <artifactId>easymockclassextension</artifactId>
-            <version>${easymock-version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>

Modified: camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java?rev=1345771&r1=1345770&r2=1345771&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
Sun Jun  3 20:32:36 2012
@@ -22,7 +22,6 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.util.IntrospectionSupport;
 
 /**
  * @version 
@@ -53,11 +52,7 @@ public class SmppComponent extends Defau
         SmppConfiguration config = this.configuration.copy();
 
         config.configureFromURI(new URI(uri));
-        if (getCamelContext() != null) {
-            IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), config,
parameters);
-        } else {
-            IntrospectionSupport.setProperties(config, parameters);
-        }
+        setProperties(config, parameters);
 
         return createEndpoint(uri, config);
     }

Modified: camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java?rev=1345771&r1=1345770&r2=1345771&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
Sun Jun  3 20:32:36 2012
@@ -24,6 +24,7 @@ import org.jsmpp.bean.NumberingPlanIndic
 import org.jsmpp.bean.ReplaceIfPresentFlag;
 import org.jsmpp.bean.SMSCDeliveryReceipt;
 import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.SessionStateListener;
 
 /**
  * Contains the SMPP component configuration properties</a>
@@ -63,6 +64,7 @@ public class SmppConfiguration implement
     private Integer httpProxyPort = Integer.valueOf(3128);
     private String httpProxyUsername;
     private String httpProxyPassword;
+    private SessionStateListener sessionStateListener;
 
     /**
      * A POJO which contains all necessary configuration parameters for the SMPP connection
@@ -325,6 +327,14 @@ public class SmppConfiguration implement
     public void setHttpProxyPassword(String httpProxyPassword) {
         this.httpProxyPassword = httpProxyPassword;
     }
+    
+    public SessionStateListener getSessionStateListener() {
+        return sessionStateListener;
+    }
+
+    public void setSessionStateListener(SessionStateListener sessionStateListener) {
+        this.sessionStateListener = sessionStateListener;
+    }
 
     @Override
     public String toString() {

Modified: camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java?rev=1345771&r1=1345770&r2=1345771&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
Sun Jun  3 20:32:36 2012
@@ -48,7 +48,8 @@ public class SmppConsumer extends Defaul
     private SmppConfiguration configuration;
     private SMPPSession session;
     private MessageReceiverListener messageReceiverListener;
-    private SessionStateListener sessionStateListener;
+    private SessionStateListener internalSessionStateListener;
+
     private final ReentrantLock reconnectLock = new ReentrantLock();
 
     /**
@@ -59,11 +60,14 @@ public class SmppConsumer extends Defaul
         super(endpoint, processor);
 
         this.configuration = config;
-        this.sessionStateListener = new SessionStateListener() {
+        this.internalSessionStateListener = new SessionStateListener() {
             public void onStateChange(SessionState newState, SessionState oldState, Object
source) {
+                if (configuration.getSessionStateListener() != null) {
+                    configuration.getSessionStateListener().onStateChange(newState, oldState,
source);
+                }
+                
                 if (newState.equals(SessionState.CLOSED)) {
-                    LOG.warn("Lost connection to: " + getEndpoint().getConnectionString()
-                            + " - trying to reconnect...");
+                    LOG.warn("Lost connection to: {} - trying to reconnect...", getEndpoint().getConnectionString());
                     closeSession();
                     reconnect(configuration.getInitialReconnectDelay());
                 }
@@ -86,7 +90,7 @@ public class SmppConsumer extends Defaul
         SMPPSession session = createSMPPSession();
         session.setEnquireLinkTimer(configuration.getEnquireLinkTimer());
         session.setTransactionTimer(configuration.getTransactionTimer());
-        session.addSessionStateListener(sessionStateListener);
+        session.addSessionStateListener(internalSessionStateListener);
         session.setMessageReceiverListener(messageReceiverListener);
         session.connectAndBind(this.configuration.getHost(), this.configuration.getPort(),
                 new BindParameter(BindType.BIND_RX, this.configuration.getSystemId(),
@@ -119,7 +123,7 @@ public class SmppConsumer extends Defaul
 
     private void closeSession() {
         if (session != null) {
-            session.removeSessionStateListener(this.sessionStateListener);
+            session.removeSessionStateListener(this.internalSessionStateListener);
             // remove this hack after http://code.google.com/p/jsmpp/issues/detail?id=93
is fixed
             try {
                 Thread.sleep(1000);

Modified: camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java?rev=1345771&r1=1345770&r2=1345771&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
Sun Jun  3 20:32:36 2012
@@ -44,16 +44,20 @@ public class SmppProducer extends Defaul
 
     private SmppConfiguration configuration;
     private SMPPSession session;
-    private SessionStateListener sessionStateListener;
+    private SessionStateListener internalSessionStateListener;
     private final ReentrantLock connectLock = new ReentrantLock();
 
     public SmppProducer(SmppEndpoint endpoint, SmppConfiguration config) {
         super(endpoint);
         this.configuration = config;
-        this.sessionStateListener = new SessionStateListener() {
+        this.internalSessionStateListener = new SessionStateListener() {
             public void onStateChange(SessionState newState, SessionState oldState, Object
source) {
+                if (configuration.getSessionStateListener() != null) {
+                    configuration.getSessionStateListener().onStateChange(newState, oldState,
source);
+                }
+                
                 if (newState.equals(SessionState.CLOSED)) {
-                    LOG.warn("Lost connection to: " + getEndpoint().getConnectionString()
+ " - trying to reconnect...");
+                    LOG.warn("Lost connection to: {} - trying to reconnect...", getEndpoint().getConnectionString());
                     closeSession();
                     reconnect(configuration.getInitialReconnectDelay());
                 }
@@ -82,7 +86,7 @@ public class SmppProducer extends Defaul
         SMPPSession session = createSMPPSession();
         session.setEnquireLinkTimer(this.configuration.getEnquireLinkTimer());
         session.setTransactionTimer(this.configuration.getTransactionTimer());
-        session.addSessionStateListener(sessionStateListener);
+        session.addSessionStateListener(internalSessionStateListener);
         session.connectAndBind(
                 this.configuration.getHost(),
                 this.configuration.getPort(),
@@ -147,7 +151,7 @@ public class SmppProducer extends Defaul
     
     private void closeSession() {
         if (session != null) {
-            session.removeSessionStateListener(this.sessionStateListener);
+            session.removeSessionStateListener(this.internalSessionStateListener);
             // remove this hack after http://code.google.com/p/jsmpp/issues/detail?id=93
is fixed
             try {
                 Thread.sleep(1000);

Modified: camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java?rev=1345771&r1=1345770&r2=1345771&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppComponentTest.java
Sun Jun  3 20:32:36 2012
@@ -23,12 +23,14 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.SimpleRegistry;
+import org.jsmpp.extra.SessionState;
+import org.jsmpp.session.SessionStateListener;
 import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
@@ -40,10 +42,12 @@ import static org.junit.Assert.assertTru
 public class SmppComponentTest {
     
     private SmppComponent component;
+    private DefaultCamelContext context;
 
     @Before
     public void setUp() {
-        component = new SmppComponent();
+        context = new DefaultCamelContext();
+        component = new SmppComponent(context);
     }
 
     @Test
@@ -117,7 +121,7 @@ public class SmppComponentTest {
         assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getConnectionString());
         assertEquals(ExchangePattern.InOnly, smppEndpoint.getExchangePattern());
         assertTrue(smppEndpoint.getBinding() instanceof SmppBinding);
-        assertNull(smppEndpoint.getCamelContext());
+        assertNotNull(smppEndpoint.getCamelContext());
     }
 
     @Test
@@ -133,7 +137,7 @@ public class SmppComponentTest {
         assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getConnectionString());
         assertEquals(ExchangePattern.InOnly, smppEndpoint.getExchangePattern());
         assertTrue(smppEndpoint.getBinding() instanceof SmppBinding);
-        assertNull(smppEndpoint.getCamelContext());
+        assertNotNull(smppEndpoint.getCamelContext());
     }
 
     @Test
@@ -149,7 +153,7 @@ public class SmppComponentTest {
         assertEquals("smpp://smppclient@localhost:2775", smppEndpoint.getConnectionString());
         assertEquals(ExchangePattern.InOnly, smppEndpoint.getExchangePattern());
         assertTrue(smppEndpoint.getBinding() instanceof SmppBinding);
-        assertNull(smppEndpoint.getCamelContext());
+        assertNotNull(smppEndpoint.getCamelContext());
     }
 
     @Test
@@ -159,4 +163,18 @@ public class SmppComponentTest {
         
         assertSame(configuration, component.getConfiguration());
     }
+    
+    @Test
+    public void createEndpointWithSessionStateListener() throws Exception {
+        SimpleRegistry registry = new SimpleRegistry();
+        registry.put("sessionStateListener", new SessionStateListener() {
+            public void onStateChange(SessionState arg0, SessionState arg1, Object arg2)
{
+            }
+        });
+        context.setRegistry(registry);
+        component = new SmppComponent(context);
+        SmppEndpoint endpoint = (SmppEndpoint) component.createEndpoint("smpp://smppclient@localhost:2775?password=password&sessionStateListener=#sessionStateListener");
+        
+        assertNotNull(endpoint.getConfiguration().getSessionStateListener());
+    }
 }
\ No newline at end of file

Modified: camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java?rev=1345771&r1=1345770&r2=1345771&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
Sun Jun  3 20:32:36 2012
@@ -22,10 +22,13 @@ import java.net.URISyntaxException;
 import org.jsmpp.bean.NumberingPlanIndicator;
 import org.jsmpp.bean.SMSCDeliveryReceipt;
 import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.extra.SessionState;
+import org.jsmpp.session.SessionStateListener;
 import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 /**
  * JUnit test class for <code>org.apache.camel.component.smpp.SmppConfiguration</code>
@@ -71,6 +74,7 @@ public class SmppConfigurationTest {
         assertEquals(new Integer(3128), configuration.getHttpProxyPort());
         assertEquals(null, configuration.getHttpProxyUsername());
         assertEquals(null, configuration.getHttpProxyPassword());
+        assertEquals(null, configuration.getSessionStateListener());
     }
     
     @Test
@@ -105,6 +109,7 @@ public class SmppConfigurationTest {
         assertEquals(new Integer(3129), configuration.getHttpProxyPort());
         assertEquals("user", configuration.getHttpProxyUsername());
         assertEquals("secret", configuration.getHttpProxyPassword());
+        assertNotNull(configuration.getSessionStateListener());
     }
 
     @Test
@@ -149,7 +154,7 @@ public class SmppConfigurationTest {
         assertEquals(config.getHttpProxyPort(), configuration.getHttpProxyPort());
         assertEquals(config.getHttpProxyUsername(), configuration.getHttpProxyUsername());
         assertEquals(config.getHttpProxyPassword(), configuration.getHttpProxyPassword());
-        
+        assertEquals(config.getSessionStateListener(), configuration.getSessionStateListener());
     }
     
     @Test
@@ -217,5 +222,9 @@ public class SmppConfigurationTest {
         config.setHttpProxyPort(new Integer(3129));
         config.setHttpProxyUsername("user");
         config.setHttpProxyPassword("secret");
+        config.setSessionStateListener(new SessionStateListener() {
+            public void onStateChange(SessionState arg0, SessionState arg1, Object arg2)
{
+            }
+        });
     }
 }
\ No newline at end of file



Mime
View raw message