camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1054271 - in /camel/trunk/components/camel-smpp/src: main/java/org/apache/camel/component/smpp/ test/java/org/apache/camel/component/smpp/
Date Sat, 01 Jan 2011 18:38:40 GMT
Author: cmueller
Date: Sat Jan  1 18:38:40 2011
New Revision: 1054271

URL: http://svn.apache.org/viewvc?rev=1054271&view=rev
Log:
CAMEL-3475: Idenitify incoming message type in camel-smpp consumer

Added:
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessageType.java
  (with props)
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/SmppComponent.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.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/SmppMessageTest.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=1054271&r1=1054270&r2=1054271&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
Sat Jan  1 18:38:40 2011
@@ -70,6 +70,7 @@ public class SmppBinding {
     public static final String ESME_ADDR = "CamelSmppEsmeAddr";
     public static final String FINAL_STATUS = "CamelSmppStatus";
     public static final String DATA_CODING = "CamelSmppDataCoding";
+    public static final String MESSAGE_TYPE = "CamelSmppMessageType";
 
     private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter();
 
@@ -185,6 +186,7 @@ public class SmppBinding {
     public SmppMessage createSmppMessage(AlertNotification alertNotification) {
         SmppMessage smppMessage = new SmppMessage(alertNotification, configuration);
 
+        smppMessage.setHeader(MESSAGE_TYPE, SmppMessageType.AlertNotification.toString());
         smppMessage.setHeader(SEQUENCE_NUMBER, alertNotification.getSequenceNumber());
         smppMessage.setHeader(COMMAND_ID, alertNotification.getCommandId());
         smppMessage.setHeader(COMMAND_STATUS, alertNotification.getCommandStatus());
@@ -205,6 +207,7 @@ public class SmppBinding {
         SmppMessage smppMessage = new SmppMessage(deliverSm, configuration);
 
         if (deliverSm.isSmscDeliveryReceipt()) {
+            smppMessage.setHeader(MESSAGE_TYPE, SmppMessageType.DeliveryReceipt.toString());
             DeliveryReceipt smscDeliveryReceipt = deliverSm.getShortMessageAsDeliveryReceipt();
             smppMessage.setBody(smscDeliveryReceipt.getText());
 
@@ -218,6 +221,7 @@ public class SmppBinding {
             smppMessage.setHeader(SUBMITTED, smscDeliveryReceipt.getSubmitted());
             smppMessage.setHeader(FINAL_STATUS, smscDeliveryReceipt.getFinalStatus());
         } else {
+            smppMessage.setHeader(MESSAGE_TYPE, SmppMessageType.DeliverSm.toString());
             if (deliverSm.getShortMessage() != null) {
                 smppMessage.setBody(String.valueOf(new String(deliverSm.getShortMessage(),
                         configuration.getEncoding())));
@@ -247,6 +251,7 @@ public class SmppBinding {
     public SmppMessage createSmppMessage(DataSm dataSm, String smppMessageId) {
         SmppMessage smppMessage = new SmppMessage(dataSm, configuration);
 
+        smppMessage.setHeader(MESSAGE_TYPE, SmppMessageType.DataSm.toString());
         smppMessage.setHeader(ID, smppMessageId);
         smppMessage.setHeader(SEQUENCE_NUMBER, dataSm.getSequenceNumber());
         smppMessage.setHeader(COMMAND_ID, dataSm.getCommandId());

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java?rev=1054271&r1=1054270&r2=1054271&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
(original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppComponent.java
Sat Jan  1 18:38:40 2011
@@ -43,7 +43,7 @@ public class SmppComponent extends Defau
         super(context);
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws
Exception {
         if (this.configuration == null) {

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java?rev=1054271&r1=1054270&r2=1054271&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
(original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
Sat Jan  1 18:38:40 2011
@@ -59,6 +59,22 @@ public class SmppMessage extends Default
     public SmppMessage newInstance() {
         return new SmppMessage(this.configuration);
     }
+    
+    public boolean isAlertNotification() {
+        return command instanceof AlertNotification;
+    }
+    
+    public boolean isDataSm() {
+        return command instanceof DataSm;
+    }
+    
+    public boolean isDeliverSm() {
+        return command instanceof DeliverSm && !((DeliverSm) command).isSmscDeliveryReceipt();
+    }
+    
+    public boolean isDeliveryReceipt() {
+        return command instanceof DeliverSm && ((DeliverSm) command).isSmscDeliveryReceipt();
+    }
 
     @Override
     protected Object createBody() {

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessageType.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessageType.java?rev=1054271&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessageType.java
(added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessageType.java
Sat Jan  1 18:38:40 2011
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.smpp;
+
+public enum SmppMessageType {
+    AlertNotification,
+    DataSm,
+    DeliveryReceipt,
+    DeliverSm;
+}

Propchange: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessageType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1054271&r1=1054270&r2=1054271&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
Sat Jan  1 18:38:40 2011
@@ -164,7 +164,7 @@ public class SmppBindingTest {
         SmppMessage smppMessage = binding.createSmppMessage(alertNotification);
         
         assertNull(smppMessage.getBody());
-        assertEquals(9, smppMessage.getHeaders().size());
+        assertEquals(10, smppMessage.getHeaders().size());
         assertEquals(1, smppMessage.getHeader(SmppBinding.SEQUENCE_NUMBER));
         assertEquals(1, smppMessage.getHeader(SmppBinding.COMMAND_ID));
         assertEquals(0, smppMessage.getHeader(SmppBinding.COMMAND_STATUS));
@@ -174,6 +174,7 @@ public class SmppBindingTest {
         assertEquals("1717", smppMessage.getHeader(SmppBinding.ESME_ADDR));
         assertEquals((byte) 8, smppMessage.getHeader(SmppBinding.ESME_ADDR_NPI));
         assertEquals((byte) 2, smppMessage.getHeader(SmppBinding.ESME_ADDR_TON));
+        assertEquals(SmppMessageType.AlertNotification.toString(), smppMessage.getHeader(SmppBinding.MESSAGE_TYPE));
     }
 
     @Test
@@ -184,7 +185,7 @@ public class SmppBindingTest {
         SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
         
         assertEquals("Hello SMPP world!", smppMessage.getBody());
-        assertEquals(7, smppMessage.getHeaders().size());
+        assertEquals(8, smppMessage.getHeaders().size());
         assertEquals("2", smppMessage.getHeader(SmppBinding.ID));
         assertEquals(1, smppMessage.getHeader(SmppBinding.DELIVERED));
         // To avoid the test failure when running in different TimeZone
@@ -193,6 +194,7 @@ public class SmppBindingTest {
         //assertEquals(new Date(1251753000000L), smppMessage.getHeader(SmppBinding.SUBMIT_DATE));
         assertEquals(1, smppMessage.getHeader(SmppBinding.SUBMITTED));
         assertEquals(DeliveryReceiptState.DELIVRD, smppMessage.getHeader(SmppBinding.FINAL_STATUS));
+        assertEquals(SmppMessageType.DeliveryReceipt.toString(), smppMessage.getHeader(SmppBinding.MESSAGE_TYPE));
     }
     
     @Test
@@ -209,7 +211,7 @@ public class SmppBindingTest {
         SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
         
         assertEquals("Hello SMPP world!", smppMessage.getBody());
-        assertEquals(7, smppMessage.getHeaders().size());
+        assertEquals(8, smppMessage.getHeaders().size());
         assertEquals(1, smppMessage.getHeader(SmppBinding.SEQUENCE_NUMBER));
         assertEquals(1, smppMessage.getHeader(SmppBinding.COMMAND_ID));
         assertEquals("1818", smppMessage.getHeader(SmppBinding.SOURCE_ADDR));
@@ -217,6 +219,7 @@ public class SmppBindingTest {
         assertEquals("090831230627004+", smppMessage.getHeader(SmppBinding.SCHEDULE_DELIVERY_TIME));
         assertEquals("090901230627004+", smppMessage.getHeader(SmppBinding.VALIDITY_PERIOD));
         assertEquals("WAP", smppMessage.getHeader(SmppBinding.SERVICE_TYPE));
+        assertEquals(SmppMessageType.DeliverSm.toString(), smppMessage.getHeader(SmppBinding.MESSAGE_TYPE));
     }
     
     @Test
@@ -233,7 +236,7 @@ public class SmppBindingTest {
         SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
         
         assertEquals("Hello SMPP world!", smppMessage.getBody());
-        assertEquals(7, smppMessage.getHeaders().size());
+        assertEquals(8, smppMessage.getHeaders().size());
         assertEquals(1, smppMessage.getHeader(SmppBinding.SEQUENCE_NUMBER));
         assertEquals(1, smppMessage.getHeader(SmppBinding.COMMAND_ID));
         assertEquals("1818", smppMessage.getHeader(SmppBinding.SOURCE_ADDR));
@@ -241,6 +244,7 @@ public class SmppBindingTest {
         assertEquals("090831230627004+", smppMessage.getHeader(SmppBinding.SCHEDULE_DELIVERY_TIME));
         assertEquals("090901230627004+", smppMessage.getHeader(SmppBinding.VALIDITY_PERIOD));
         assertEquals("WAP", smppMessage.getHeader(SmppBinding.SERVICE_TYPE));
+        assertEquals(SmppMessageType.DeliverSm.toString(), smppMessage.getHeader(SmppBinding.MESSAGE_TYPE));
     }
     
     @Test
@@ -260,7 +264,7 @@ public class SmppBindingTest {
         SmppMessage smppMessage = binding.createSmppMessage(dataSm, "1");
         
         assertNull(smppMessage.getBody());
-        assertEquals(13, smppMessage.getHeaders().size());
+        assertEquals(14, smppMessage.getHeaders().size());
         assertEquals("1", smppMessage.getHeader(SmppBinding.ID));
         assertEquals(1, smppMessage.getHeader(SmppBinding.SEQUENCE_NUMBER));
         assertEquals(1, smppMessage.getHeader(SmppBinding.COMMAND_ID));
@@ -274,6 +278,7 @@ public class SmppBindingTest {
         assertEquals("WAP", smppMessage.getHeader(SmppBinding.SERVICE_TYPE));
         assertEquals((byte) 0, smppMessage.getHeader(SmppBinding.REGISTERED_DELIVERY));
         assertEquals((byte) 0, smppMessage.getHeader(SmppBinding.DATA_CODING));
+        assertEquals(SmppMessageType.DataSm.toString(), smppMessage.getHeader(SmppBinding.MESSAGE_TYPE));
     }
 
     @Test

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java?rev=1054271&r1=1054270&r2=1054271&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java
(original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java
Sat Jan  1 18:38:40 2011
@@ -17,6 +17,7 @@
 package org.apache.camel.component.smpp;
 
 import org.jsmpp.bean.AlertNotification;
+import org.jsmpp.bean.DataSm;
 import org.jsmpp.bean.DeliverSm;
 import org.junit.Test;
 
@@ -50,6 +51,17 @@ public class SmppMessageTest {
         
         assertTrue(message.getCommand() instanceof AlertNotification);
         assertTrue(message.getHeaders().isEmpty());
+        assertTrue(message.isAlertNotification());
+    }
+    
+    @Test
+    public void testSmppMessageDataSm() {
+        DataSm command = new DataSm();
+        message = new SmppMessage(command, new SmppConfiguration());
+        
+        assertTrue(message.getCommand() instanceof DataSm);
+        assertTrue(message.getHeaders().isEmpty());
+        assertTrue(message.isDataSm());
     }
 
     @Test
@@ -59,8 +71,21 @@ public class SmppMessageTest {
         
         assertTrue(message.getCommand() instanceof DeliverSm);
         assertTrue(message.getHeaders().isEmpty());
+        assertTrue(message.isDeliverSm());
     }
-
+    
+    @Test
+    public void testSmppMessageDeliverReceipt() {
+        DeliverSm command = new DeliverSm();
+        command.setSmscDeliveryReceipt();
+        command.setShortMessage("id:2 sub:001 dlvrd:001 submit date:0908312310 done date:0908312311
stat:DELIVRD err:xxx Text:Hello SMPP world!".getBytes());
+        message = new SmppMessage(command, new SmppConfiguration());
+        
+        assertTrue(message.getCommand() instanceof DeliverSm);
+        assertTrue(message.getHeaders().isEmpty());
+        assertTrue(message.isDeliveryReceipt());
+    }
+    
     @Test
     public void newInstanceShouldReturnAnInstanceWithoutACommand() {
         message = new SmppMessage(new SmppConfiguration());



Mime
View raw message