camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1454239 - in /camel/trunk/components/camel-smpp/src: main/java/org/apache/camel/component/smpp/SmppBinding.java main/java/org/apache/camel/component/smpp/SmppConstants.java test/java/org/apache/camel/component/smpp/SmppBindingTest.java
Date Fri, 08 Mar 2013 04:20:23 GMT
Author: cmueller
Date: Fri Mar  8 04:20:22 2013
New Revision: 1454239

URL: http://svn.apache.org/r1454239
Log:
CAMEL-6116: Populate all optional parameters from DeliverSm (if it is DeliveryReceipt)

Modified:
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindingTest.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=1454239&r1=1454238&r2=1454239&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
Fri Mar  8 04:20:22 2013
@@ -19,7 +19,9 @@ package org.apache.camel.component.smpp;
 import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.camel.Exchange;
 import org.jsmpp.bean.AlertNotification;
@@ -29,6 +31,8 @@ import org.jsmpp.bean.DataSm;
 import org.jsmpp.bean.DeliverSm;
 import org.jsmpp.bean.DeliveryReceipt;
 import org.jsmpp.bean.OptionalParameter;
+import org.jsmpp.bean.OptionalParameter.COctetString;
+import org.jsmpp.bean.OptionalParameter.Null;
 import org.jsmpp.bean.OptionalParameter.OctetString;
 import org.jsmpp.session.SMPPSession;
 
@@ -102,6 +106,27 @@ public class SmppBinding {
             smppMessage.setHeader(SmppConstants.SUBMIT_DATE, smscDeliveryReceipt.getSubmitDate());
             smppMessage.setHeader(SmppConstants.SUBMITTED, smscDeliveryReceipt.getSubmitted());
             smppMessage.setHeader(SmppConstants.FINAL_STATUS, smscDeliveryReceipt.getFinalStatus());
+            if (deliverSm.getOptionalParametes() != null && deliverSm.getOptionalParametes().length
> 0) {
+                List<OptionalParameter> oplist = Arrays.asList(deliverSm.getOptionalParametes());
+
+                Map<String, Object> optParams = new HashMap<String, Object>();
+                for (OptionalParameter optPara : oplist) {
+                    if (OctetString.class.isInstance(optPara)) {
+                        optParams.put(OptionalParameter.Tag.valueOf(optPara.tag).toString(),
((OctetString) optPara).getValueAsString());
+                    } else if (org.jsmpp.bean.OptionalParameter.COctetString.class.isInstance(optPara))
{
+                        optParams.put(OptionalParameter.Tag.valueOf(optPara.tag).toString(),
((COctetString) optPara).getValueAsString());
+                    } else if (org.jsmpp.bean.OptionalParameter.Byte.class.isInstance(optPara))
{
+                        optParams.put(OptionalParameter.Tag.valueOf(optPara.tag).toString(),
Byte.valueOf(((org.jsmpp.bean.OptionalParameter.Byte) optPara).getValue()));
+                    } else if (org.jsmpp.bean.OptionalParameter.Short.class.isInstance(optPara))
{
+                        optParams.put(OptionalParameter.Tag.valueOf(optPara.tag).toString(),
Short.valueOf(((org.jsmpp.bean.OptionalParameter.Short) optPara).getValue()));
+                    } else if (org.jsmpp.bean.OptionalParameter.Int.class.isInstance(optPara))
{
+                        optParams.put(OptionalParameter.Tag.valueOf(optPara.tag).toString(),
Integer.valueOf(((org.jsmpp.bean.OptionalParameter.Int) optPara).getValue()));
+                    } else if (Null.class.isInstance(optPara)) {
+                        optParams.put(OptionalParameter.Tag.valueOf(optPara.tag).toString(),
null);
+                    }
+                }
+                smppMessage.setHeader(SmppConstants.OPTIONAL_PARAMETERS, optParams);
+            }
         } else {
             smppMessage.setHeader(SmppConstants.MESSAGE_TYPE, SmppMessageType.DeliverSm.toString());
 

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java?rev=1454239&r1=1454238&r2=1454239&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
(original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
Fri Mar  8 04:20:22 2013
@@ -57,6 +57,7 @@ public interface SmppConstants {
     String SYSTEM_ID = "CamelSmppSystemId";
     String PASSWORD = "CamelSmppSystemId";
     String VALIDITY_PERIOD = "CamelSmppValidityPeriod";
+    String OPTIONAL_PARAMETERS = "CamelSmppOptionalParameters";
     
     String UCS2_ENCODING = "UTF-16BE";
     byte UNKNOWN_ALPHABET = -1;

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=1454239&r1=1454238&r2=1454239&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
Fri Mar  8 04:20:22 2013
@@ -18,6 +18,7 @@ package org.apache.camel.component.smpp;
 
 import java.nio.charset.Charset;
 import java.util.Date;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.camel.Exchange;
@@ -29,6 +30,7 @@ import org.jsmpp.bean.DeliverSm;
 import org.jsmpp.bean.NumberingPlanIndicator;
 import org.jsmpp.bean.OptionalParameter;
 import org.jsmpp.bean.OptionalParameter.OctetString;
+import org.jsmpp.bean.OptionalParameter.Tag;
 import org.jsmpp.bean.TypeOfNumber;
 import org.jsmpp.session.SMPPSession;
 import org.jsmpp.util.DeliveryReceiptState;
@@ -118,8 +120,46 @@ public class SmppBindingTest {
         assertEquals(1, smppMessage.getHeader(SmppConstants.SUBMITTED));
         assertEquals(DeliveryReceiptState.DELIVRD, smppMessage.getHeader(SmppConstants.FINAL_STATUS));
         assertEquals(SmppMessageType.DeliveryReceipt.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
+        assertNull(smppMessage.getHeader(SmppConstants.OPTIONAL_PARAMETERS));
     }
-    
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void createSmppMessageFromDeliveryReceiptWithOptionalParametersShouldReturnASmppMessage()
throws Exception {
+        DeliverSm deliverSm = new DeliverSm();
+        deliverSm.setSmscDeliveryReceipt();
+        deliverSm.setShortMessage("id:2 sub:001 dlvrd:001 submit date:0908312310 done date:0908312311
stat:DELIVRD err:xxx Text:Hello SMPP world!".getBytes());
+        deliverSm.setOptionalParametes(
+            new OptionalParameter.OctetString(Tag.SOURCE_SUBADDRESS, "OctetString"),
+            new OptionalParameter.COctetString((short) 0x001D, "COctetString"),
+            new OptionalParameter.Byte(Tag.DEST_ADDR_SUBUNIT, (byte) 0x01),
+            new OptionalParameter.Short(Tag.DEST_TELEMATICS_ID, (short) 1),
+            new OptionalParameter.Int(Tag.QOS_TIME_TO_LIVE, 1),
+            new OptionalParameter.Null(Tag.ALERT_ON_MESSAGE_DELIVERY));
+        SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
+
+        assertEquals("Hello SMPP world!", smppMessage.getBody());
+        assertEquals(9, smppMessage.getHeaders().size());
+        assertEquals("2", smppMessage.getHeader(SmppConstants.ID));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.DELIVERED));
+        // To avoid the test failure when running in different TimeZone
+        //assertEquals(new Date(1251753060000L), smppMessage.getHeader(SmppConstants.DONE_DATE));
+        assertEquals("xxx", smppMessage.getHeader(SmppConstants.ERROR));
+        //assertEquals(new Date(1251753000000L), smppMessage.getHeader(SmppConstants.SUBMIT_DATE));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.SUBMITTED));
+        assertEquals(DeliveryReceiptState.DELIVRD, smppMessage.getHeader(SmppConstants.FINAL_STATUS));
+        assertEquals(SmppMessageType.DeliveryReceipt.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
+        
+        Map<String, String> optionalParameters = smppMessage.getHeader(SmppConstants.OPTIONAL_PARAMETERS,
Map.class);
+        assertEquals(6, optionalParameters.size());
+        assertEquals("OctetString", optionalParameters.get("SOURCE_SUBADDRESS"));
+        assertEquals("COctetStrin", optionalParameters.get("ADDITIONAL_STATUS_INFO_TEXT"));
+        assertEquals(Byte.valueOf((byte) 0x01), optionalParameters.get("DEST_ADDR_SUBUNIT"));
+        assertEquals(Short.valueOf((short) 1), optionalParameters.get("DEST_TELEMATICS_ID"));
+        assertEquals(Integer.valueOf(1), optionalParameters.get("QOS_TIME_TO_LIVE"));
+        assertNull("0x00", optionalParameters.get("ALERT_ON_MESSAGE_DELIVERY"));
+    }
+
     @Test
     public void createSmppMessageFromDeliverSmShouldReturnASmppMessage() throws Exception
{
         DeliverSm deliverSm = new DeliverSm();



Mime
View raw message