camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1142500 - in /camel/trunk/components/camel-smpp/src: main/java/org/apache/camel/component/smpp/ test/java/org/apache/camel/component/smpp/ test/java/org/apache/camel/component/smpp/integration/
Date Sun, 03 Jul 2011 21:06:26 GMT
Author: cmueller
Date: Sun Jul  3 21:06:25 2011
New Revision: 1142500

URL: http://svn.apache.org/viewvc?rev=1142500&view=rev
Log:
CAMEL-4170: camel-smpp component doesn't support sms messages longer than 254 symbols.

Modified:
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentIntegrationTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentSpringIntegrationTest.java

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java?rev=1142500&r1=1142499&r2=1142500&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
(original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
Sun Jul  3 21:06:25 2011
@@ -30,6 +30,7 @@ import org.jsmpp.bean.DeliverSm;
 import org.jsmpp.bean.DeliveryReceipt;
 import org.jsmpp.bean.OptionalParameter;
 import org.jsmpp.bean.OptionalParameter.OctetString;
+import org.jsmpp.bean.OptionalParameters;
 import org.jsmpp.bean.SubmitSm;
 import org.jsmpp.util.AbsoluteTimeFormatter;
 import org.jsmpp.util.TimeFormatter;
@@ -90,9 +91,22 @@ public class SmppBinding {
      */
     public SubmitSm createSubmitSm(Exchange exchange) throws UnsupportedEncodingException
{
         Message in = exchange.getIn();
-
+        String body = exchange.getIn().getBody(String.class);
+        
         SubmitSm submitSm = new SubmitSm();
-        submitSm.setShortMessage(exchange.getIn().getBody(String.class).getBytes(configuration.getEncoding()));
+        
+        if (body != null) {
+            byte[] shortMessage = body.getBytes(configuration.getEncoding());
+            
+            if (shortMessage.length < 255) {
+                submitSm.setShortMessage(shortMessage);
+            } else {
+                submitSm.setShortMessage(new byte[0]);
+                OptionalParameter messagePayloadTLV = OptionalParameters.deserialize(OptionalParameter.Tag.MESSAGE_PAYLOAD.code(),
shortMessage);
+
+                submitSm.setOptionalParametes(messagePayloadTLV);
+            }
+        }
 
         if (in.getHeaders().containsKey(DEST_ADDR)) {
             submitSm.setDestAddress(in.getHeader(DEST_ADDR, String.class));

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java?rev=1142500&r1=1142499&r2=1142500&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java
(original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.java
Sun Jul  3 21:06:25 2011
@@ -148,6 +148,31 @@ public class SmppBindingTest {
         //assertEquals(0, submitSm.getCommandStatus());
         //assertEquals(0, submitSm.getSequenceNumber());
     }
+    
+    @Test
+    public void createSubmitSmWithLongMessageBody() throws UnsupportedEncodingException {
+        String payload = "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP
World! Hello SMPP World! "
+            + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello
SMPP World! "
+            + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello
SMPP World! "; // 270 chars
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setBody(payload);
+        SubmitSm submitSm = binding.createSubmitSm(exchange);
+
+        assertArrayEquals(new byte[0], submitSm.getShortMessage());
+        
+        OptionalParameter[] optionalParametes = submitSm.getOptionalParametes();
+        assertEquals(1, optionalParametes.length);
+        
+        OptionalParameter messagePayloadTLV = optionalParametes[0];
+        assertEquals(OptionalParameter.Tag.MESSAGE_PAYLOAD.code(), messagePayloadTLV.tag);
+        byte[] expectedTLV = new byte[274];
+        expectedTLV[0] = 4;
+        expectedTLV[1] = 36;
+        expectedTLV[2] = 1;
+        expectedTLV[3] = 14;
+        System.arraycopy(payload.getBytes(), 0, expectedTLV, 4, 270);
+        assertArrayEquals(expectedTLV, messagePayloadTLV.serialize());
+    }
 
     @Test
     public void createSmppMessageFromAlertNotificationShouldReturnASmppMessage() {

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentIntegrationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentIntegrationTest.java?rev=1142500&r1=1142499&r2=1142500&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentIntegrationTest.java
(original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentIntegrationTest.java
Sun Jul  3 21:06:25 2011
@@ -93,6 +93,27 @@ public class SmppComponentIntegrationTes
         
         assertNotNull(exchange.getIn().getHeader(SmppBinding.ID));
     }
+    
+    @Test
+    public void sendLongMessage() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedMessageCount(1);
+        
+        Endpoint start = getMandatoryEndpoint("direct:start");
+        Exchange exchange = start.createExchange();
+        exchange.setPattern(ExchangePattern.InOnly);
+        exchange.getIn().setBody("Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello
SMPP World! Hello SMPP World! "
+                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World!
Hello SMPP World! "
+                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World!
Hello SMPP World! "); // 270 chars
+
+        template.send(start, exchange);
+        
+        assertMockEndpointsSatisfied();
+        Exchange resultExchange = result.getExchanges().get(0);
+        assertEquals(SmppMessageType.DeliveryReceipt.toString(), resultExchange.getIn().getHeader(SmppBinding.MESSAGE_TYPE));
+        
+        assertNotNull(exchange.getIn().getHeader(SmppBinding.ID));
+    }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentSpringIntegrationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentSpringIntegrationTest.java?rev=1142500&r1=1142499&r2=1142500&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentSpringIntegrationTest.java
(original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/integration/SmppComponentSpringIntegrationTest.java
Sun Jul  3 21:06:25 2011
@@ -93,6 +93,27 @@ public class SmppComponentSpringIntegrat
         
         assertNotNull(exchange.getIn().getHeader(SmppBinding.ID));
     }
+    
+    @Test
+    public void sendLongMessage() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedMessageCount(1);
+        
+        Endpoint start = getMandatoryEndpoint("direct:start");
+        Exchange exchange = start.createExchange();
+        exchange.setPattern(ExchangePattern.InOnly);
+        exchange.getIn().setBody("Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello
SMPP World! Hello SMPP World! "
+                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World!
Hello SMPP World! "
+                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World!
Hello SMPP World! "); // 270 chars
+
+        template.send(start, exchange);
+        
+        assertMockEndpointsSatisfied();
+        Exchange resultExchange = result.getExchanges().get(0);
+        assertEquals(SmppMessageType.DeliveryReceipt.toString(), resultExchange.getIn().getHeader(SmppBinding.MESSAGE_TYPE));
+        
+        assertNotNull(exchange.getIn().getHeader(SmppBinding.ID));
+    }
 
     @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {



Mime
View raw message