camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject [2/2] git commit: CAMEL-6655: SMPP - add support of Vendor Specific Optional Parameter
Date Sun, 25 Aug 2013 14:28:27 GMT
CAMEL-6655: SMPP - add support of Vendor Specific Optional Parameter


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0e0f3ab7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0e0f3ab7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0e0f3ab7

Branch: refs/heads/camel-2.11.x
Commit: 0e0f3ab77f851970d560766df680c7b3e97c28b3
Parents: d281f3b
Author: cmueller <cmueller@apache.org>
Authored: Sun Aug 25 16:24:15 2013 +0200
Committer: cmueller <cmueller@apache.org>
Committed: Sun Aug 25 16:26:10 2013 +0200

----------------------------------------------------------------------
 .../camel/component/smpp/SmppDataSmCommand.java | 32 ++++++++++++++++++--
 .../component/smpp/SmppDataSmCommandTest.java   | 27 ++++++++++++++++-
 2 files changed, 56 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0e0f3ab7/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java
b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java
index a29a388..213af70 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.smpp;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -24,6 +25,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.jsmpp.bean.DataCoding;
 import org.jsmpp.bean.DataSm;
+import org.jsmpp.bean.DeliverSm;
 import org.jsmpp.bean.ESMClass;
 import org.jsmpp.bean.NumberingPlanIndicator;
 import org.jsmpp.bean.OptionalParameter;
@@ -78,10 +80,11 @@ public class SmppDataSmCommand extends AbstractSmppCommand {
 
         Message message = getResponseMessage(exchange);
         message.setHeader(SmppConstants.ID, result.getMessageId());
-        message.setHeader(SmppConstants.OPTIONAL_PARAMETERS, getOptionalParametersAsMap(result.getOptionalParameters()));
+        message.setHeader(SmppConstants.OPTIONAL_PARAMETERS, createOptionalParameterByName(result.getOptionalParameters()));
+        message.setHeader(SmppConstants.OPTIONAL_PARAMETER, createOptionalParameterByCode(result.getOptionalParameters()));
     }
 
-    protected Map<String, String> getOptionalParametersAsMap(OptionalParameter[] optionalParameters)
{
+    protected Map<String, String> createOptionalParameterByName(OptionalParameter[]
optionalParameters) {
         if (optionalParameters == null) {
             return null;
         }
@@ -109,6 +112,31 @@ public class SmppDataSmCommand extends AbstractSmppCommand {
         return optParams;
     }
 
+    protected Map<java.lang.Short, Object> createOptionalParameterByCode(OptionalParameter[]
optionalParameters) {
+        if (optionalParameters == null) {
+            return null;
+        }
+
+        Map<java.lang.Short, Object> optParams = new HashMap<java.lang.Short, Object>();
+        for (OptionalParameter optPara : optionalParameters) {
+            if (COctetString.class.isInstance(optPara)) {
+                optParams.put(java.lang.Short.valueOf(optPara.tag), ((COctetString) optPara).getValueAsString());
+            } else if (org.jsmpp.bean.OptionalParameter.OctetString.class.isInstance(optPara))
{
+                optParams.put(java.lang.Short.valueOf(optPara.tag), ((OctetString) optPara).getValue());
+            } else if (org.jsmpp.bean.OptionalParameter.Byte.class.isInstance(optPara)) {
+                optParams.put(java.lang.Short.valueOf(optPara.tag), java.lang.Byte.valueOf(((org.jsmpp.bean.OptionalParameter.Byte)
optPara).getValue()));
+            } else if (org.jsmpp.bean.OptionalParameter.Short.class.isInstance(optPara))
{
+                optParams.put(java.lang.Short.valueOf(optPara.tag), java.lang.Short.valueOf(((org.jsmpp.bean.OptionalParameter.Short)
optPara).getValue()));
+            } else if (org.jsmpp.bean.OptionalParameter.Int.class.isInstance(optPara)) {
+                optParams.put(java.lang.Short.valueOf(optPara.tag), Integer.valueOf(((org.jsmpp.bean.OptionalParameter.Int)
optPara).getValue()));
+            } else if (Null.class.isInstance(optPara)) {
+                optParams.put(java.lang.Short.valueOf(optPara.tag), null);
+            }
+        }
+
+        return optParams;
+    }
+
     @SuppressWarnings({"unchecked"})
     protected DataSm createDataSm(Exchange exchange) {
         Message in = exchange.getIn();

http://git-wip-us.apache.org/repos/asf/camel/blob/0e0f3ab7/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDataSmCommandTest.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDataSmCommandTest.java
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDataSmCommandTest.java
index 8fe3193..e95da28 100644
--- a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDataSmCommandTest.java
+++ b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDataSmCommandTest.java
@@ -45,6 +45,7 @@ import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
@@ -164,7 +165,9 @@ public class SmppDataSmCommandTest {
 
         verify(session);
 
+        assertEquals(3, exchange.getOut().getHeaders().size());
         assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
+
         Map<String, String> optParamMap = exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS,
Map.class);
         assertEquals(6, optParamMap.size());
         assertEquals("1292", optParamMap.get("SOURCE_SUBADDRESS"));
@@ -174,8 +177,18 @@ public class SmppDataSmCommandTest {
         assertEquals("2", optParamMap.get("DEST_TELEMATICS_ID"));
         assertEquals("3600000", optParamMap.get("QOS_TIME_TO_LIVE"));
         assertNull(optParamMap.get("ALERT_ON_MESSAGE_DELIVERY"));
+
+        Map<Short, Object> optionalResultParameter = exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETER,
Map.class);
+        assertEquals(6, optionalResultParameter.size());
+        assertArrayEquals("1292".getBytes("UTF-8"), (byte[]) optionalResultParameter.get(Short.valueOf((short)
0x0202)));
+        // FIXME: fix required in JSMPP. See http://code.google.com/p/jsmpp/issues/detail?id=140
+        //assertEquals("urgent", optionalResultParameter.get(Short.valueOf((short) 0x001D)));
+        assertEquals(Byte.valueOf((byte) 4), optionalResultParameter.get(Short.valueOf((short)
0x0005)));
+        assertEquals(Short.valueOf((short) 2), optionalResultParameter.get(Short.valueOf((short)
0x0008)));
+        assertEquals(Integer.valueOf(3600000), optionalResultParameter.get(Short.valueOf((short)
0x0017)));
+        assertNull(optionalResultParameter.get(Short.valueOf((short) 0x130C)));
     }
-    
+
     @SuppressWarnings("unchecked")
     @Test
     public void executeWithOptionalParameterNewStyle() throws Exception {
@@ -223,7 +236,9 @@ public class SmppDataSmCommandTest {
 
         verify(session);
 
+        assertEquals(3, exchange.getOut().getHeaders().size());
         assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
+
         Map<String, String> optParamMap = exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS,
Map.class);
         assertEquals(6, optParamMap.size());
         assertEquals("1292", optParamMap.get("SOURCE_SUBADDRESS"));
@@ -233,5 +248,15 @@ public class SmppDataSmCommandTest {
         assertEquals("2", optParamMap.get("DEST_TELEMATICS_ID"));
         assertEquals("3600000", optParamMap.get("QOS_TIME_TO_LIVE"));
         assertNull(optParamMap.get("ALERT_ON_MESSAGE_DELIVERY"));
+
+        Map<Short, Object> optionalResultParameter = exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETER,
Map.class);
+        assertEquals(6, optionalResultParameter.size());
+        assertArrayEquals("1292".getBytes("UTF-8"), (byte[]) optionalResultParameter.get(Short.valueOf((short)
0x0202)));
+        // FIXME: fix required in JSMPP. See http://code.google.com/p/jsmpp/issues/detail?id=140
+        //assertEquals("urgent", optionalResultParameter.get(Short.valueOf((short) 0x001D)));
+        assertEquals(Byte.valueOf((byte) 4), optionalResultParameter.get(Short.valueOf((short)
0x0005)));
+        assertEquals(Short.valueOf((short) 2), optionalResultParameter.get(Short.valueOf((short)
0x0008)));
+        assertEquals(Integer.valueOf(3600000), optionalResultParameter.get(Short.valueOf((short)
0x0017)));
+        assertNull(optionalResultParameter.get(Short.valueOf((short) 0x130C)));
     }
 }
\ No newline at end of file


Mime
View raw message