camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1432420 - in /camel/branches/camel-2.10.x/components: camel-jpa/src/main/java/org/apache/camel/component/jpa/ camel-smpp/src/main/java/org/apache/camel/component/smpp/ camel-smpp/src/test/java/org/apache/camel/component/smpp/
Date Sat, 12 Jan 2013 13:18:49 GMT
Author: cmueller
Date: Sat Jan 12 13:18:48 2013
New Revision: 1432420

URL: http://svn.apache.org/viewvc?rev=1432420&view=rev
Log:
CAMEL-5708: Make camel-smpp component get username from parameters instead of address

Modified:
    camel/branches/camel-2.10.x/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
    camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
    camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
    camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
    camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppEndpointTest.java
    camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java

Modified: camel/branches/camel-2.10.x/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java?rev=1432420&r1=1432419&r2=1432420&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
Sat Jan 12 13:18:48 2013
@@ -37,10 +37,8 @@ import org.springframework.orm.jpa.JpaTe
 import org.springframework.orm.jpa.JpaTransactionManager;
 import org.springframework.transaction.PlatformTransactionManager;
 
-/**
- * @version 
- */
 public class JpaEndpoint extends ScheduledPollEndpoint {
+
     private EntityManagerFactory entityManagerFactory;
     private PlatformTransactionManager transactionManager;
     private String persistenceUnit = "camel";

Modified: camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java?rev=1432420&r1=1432419&r2=1432420&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
Sat Jan 12 13:18:48 2013
@@ -54,6 +54,8 @@ public interface SmppConstants {
     String SOURCE_ADDR_TON = "CamelSmppSourceAddrTon";
     String SUBMITTED = "CamelSmppSubmitted";
     String SUBMIT_DATE = "CamelSmppSubmitDate";
+    String SYSTEM_ID = "CamelSmppSystemId";
+    String PASSWORD = "CamelSmppSystemId";
     String VALIDITY_PERIOD = "CamelSmppValidityPeriod";
     
     String UCS2_ENCODING = "UTF-16BE";

Modified: camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java?rev=1432420&r1=1432419&r2=1432420&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
Sat Jan 12 13:18:48 2013
@@ -154,7 +154,7 @@ public class SmppEndpoint extends Defaul
      */
     public String getConnectionString() {
         return (configuration.getUsingSSL() ? "smpps://" : "smpp://") 
-                + getConfiguration().getSystemId() + "@"
+                + (getConfiguration().getSystemId() != null ? getConfiguration().getSystemId()
+ "@" : "")
                 + getConfiguration().getHost() + ":"
                 + getConfiguration().getPort();
     }

Modified: camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java?rev=1432420&r1=1432419&r2=1432420&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
Sat Jan 12 13:18:48 2013
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultProducer;
 import org.jsmpp.DefaultPDUReader;
 import org.jsmpp.DefaultPDUSender;
@@ -79,7 +80,7 @@ public class SmppProducer extends Defaul
             }
         }
     }
-    
+
     private SMPPSession createSession() throws IOException {
         LOG.debug("Connecting to: " + getEndpoint().getConnectionString() + "...");
         
@@ -103,7 +104,7 @@ public class SmppProducer extends Defaul
         
         return session;
     }
-    
+
     /**
      * Factory method to easily instantiate a mock SMPPSession
      * 
@@ -117,10 +118,19 @@ public class SmppProducer extends Defaul
 
     public void process(Exchange exchange) throws Exception {
         if (session == null) {
-            if (getConfiguration().isLazySessionCreation()) {
+            if (this.configuration.isLazySessionCreation()) {
                 if (connectLock.tryLock()) {
                     try {
                         if (session == null) {
+                            // set the system id and password with which we will try to connect
to the SMSC
+                            Message in = exchange.getIn();
+                            String systemId = in.getHeader(SmppConstants.SYSTEM_ID, String.class);
+                            String password = in.getHeader(SmppConstants.PASSWORD, String.class);
+                            if (systemId != null && password != null) {
+                                log.info("using the system id '{}' to connect to the SMSC...",
systemId);
+                                this.configuration.setSystemId(systemId);
+                                this.configuration.setPassword(password);
+                            }
                             session = createSession();
                         }
                     } finally {

Modified: camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppEndpointTest.java?rev=1432420&r1=1432419&r2=1432420&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppEndpointTest.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppEndpointTest.java
Sat Jan 12 13:18:48 2013
@@ -78,7 +78,7 @@ public class SmppEndpointTest {
     @Test
     public void createEndpointUriShouldReturnTheEndpointUri() {
         expect(configuration.getUsingSSL()).andReturn(false);
-        expect(configuration.getSystemId()).andReturn("smppclient");
+        expect(configuration.getSystemId()).andReturn("smppclient").times(2);
         expect(configuration.getHost()).andReturn("localhost");
         expect(configuration.getPort()).andReturn(new Integer(2775));
         
@@ -90,6 +90,20 @@ public class SmppEndpointTest {
     }
 
     @Test
+    public void createEndpointUriWithoutUserShouldReturnTheEndpointUri() {
+        expect(configuration.getUsingSSL()).andReturn(false);
+        expect(configuration.getSystemId()).andReturn(null);
+        expect(configuration.getHost()).andReturn("localhost");
+        expect(configuration.getPort()).andReturn(new Integer(2775));
+        
+        replay(configuration);
+        
+        assertEquals("smpp://localhost:2775", endpoint.createEndpointUri());
+        
+        verify(configuration);
+    }
+
+    @Test
     public void createConsumerShouldReturnASmppConsumer() throws Exception {
         Processor processor = createMock(Processor.class);
         
@@ -220,7 +234,7 @@ public class SmppEndpointTest {
     @Test
     public void getConnectionStringShouldReturnTheConnectionString() {
         expect(configuration.getUsingSSL()).andReturn(false);
-        expect(configuration.getSystemId()).andReturn("smppclient");
+        expect(configuration.getSystemId()).andReturn("smppclient").times(2);
         expect(configuration.getHost()).andReturn("localhost");
         expect(configuration.getPort()).andReturn(new Integer(2775));
         
@@ -232,6 +246,20 @@ public class SmppEndpointTest {
     }
 
     @Test
+    public void getConnectionStringWithoutUserShouldReturnTheConnectionString() {
+        expect(configuration.getUsingSSL()).andReturn(false);
+        expect(configuration.getSystemId()).andReturn(null);
+        expect(configuration.getHost()).andReturn("localhost");
+        expect(configuration.getPort()).andReturn(new Integer(2775));
+        
+        replay(configuration);
+        
+        assertEquals("smpp://localhost:2775", endpoint.getConnectionString());
+        
+        verify(configuration);
+    }
+
+    @Test
     public void getConfigurationShouldReturnTheSetValue() {
         assertSame(configuration, endpoint.getConfiguration());
     }

Modified: camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java?rev=1432420&r1=1432419&r2=1432420&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java
Sat Jan 12 13:18:48 2013
@@ -17,6 +17,7 @@
 package org.apache.camel.component.smpp;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.jsmpp.bean.BindType;
 import org.jsmpp.bean.NumberingPlanIndicator;
 import org.jsmpp.bean.TypeOfNumber;
@@ -61,14 +62,14 @@ public class SmppProducerLazySessionCrea
     @Test
     public void doStartShouldNotCreateTheSmppSession() throws Exception {
         expect(endpoint.getConnectionString()).andReturn("smpp://smppclient@localhost:2775");
-    
+
         replay(endpoint, session);
-    
+
         producer.doStart();
-    
+
         verify(endpoint, session);
     }
-    
+
     @Test
     public void processShouldCreateTheSmppSession() throws Exception {
         expect(endpoint.getConnectionString())
@@ -91,16 +92,59 @@ public class SmppProducerLazySessionCrea
         expect(endpoint.getConnectionString()).andReturn("smpp://smppclient@localhost:2775");
         SmppBinding binding = createMock(SmppBinding.class);
         Exchange exchange = createMock(Exchange.class);
+        Message in = createMock(Message.class);
+        SmppCommand command = createMock(SmppCommand.class);
+        expect(endpoint.getBinding()).andReturn(binding);
+        expect(binding.createSmppCommand(session, exchange)).andReturn(command);
+        expect(exchange.getIn()).andReturn(in);
+        expect(in.getHeader("CamelSmppSystemId", String.class)).andReturn(null);
+        expect(in.getHeader("CamelSmppSystemId", String.class)).andReturn(null);
+        command.execute(exchange);
+        
+        replay(session, endpoint, binding, exchange, in, command);
+        
+        producer.doStart();
+        producer.process(exchange);
+        
+        verify(session, endpoint, binding, exchange, in, command);
+    }
+
+    @Test
+    public void processShouldCreateTheSmppSessionWithTheSystemIdAndPasswordFromTheExchange()
throws Exception {
+        expect(endpoint.getConnectionString())
+            .andReturn("smpp://localhost:2775")
+            .times(2);
+        session.setEnquireLinkTimer(5000); //expectation
+        session.setTransactionTimer(10000); //expectation
+        session.addSessionStateListener(isA(SessionStateListener.class));
+        expect(session.connectAndBind(
+            "localhost",
+            new Integer(2775),
+            new BindParameter(
+                    BindType.BIND_TX,
+                    "smppclient2",
+                    "password2",
+                    "cp",
+                    TypeOfNumber.UNKNOWN,
+                    NumberingPlanIndicator.UNKNOWN,
+                    ""))).andReturn("1");
+        expect(endpoint.getConnectionString()).andReturn("smpp://localhost:2775");
+        SmppBinding binding = createMock(SmppBinding.class);
+        Exchange exchange = createMock(Exchange.class);
+        Message in = createMock(Message.class);
         SmppCommand command = createMock(SmppCommand.class);
         expect(endpoint.getBinding()).andReturn(binding);
         expect(binding.createSmppCommand(session, exchange)).andReturn(command);
+        expect(exchange.getIn()).andReturn(in);
+        expect(in.getHeader("CamelSmppSystemId", String.class)).andReturn("smppclient2");
+        expect(in.getHeader("CamelSmppSystemId", String.class)).andReturn("password2");
         command.execute(exchange);
         
-        replay(session, endpoint, binding, exchange, command);
+        replay(session, endpoint, binding, exchange, in, command);
         
         producer.doStart();
         producer.process(exchange);
         
-        verify(session, endpoint, binding, exchange, command);
+        verify(session, endpoint, binding, exchange, in, command);
     }
 }
\ No newline at end of file



Mime
View raw message