You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2011/10/05 23:55:48 UTC

svn commit: r1179457 [1/3] - 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/

Author: cmueller
Date: Wed Oct  5 21:55:46 2011
New Revision: 1179457

URL: http://svn.apache.org/viewvc?rev=1179457&view=rev
Log:
CAMEL-4086: Ability to send multipart and multilingual messages in camel-smpp

Added:
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/AbstractSmppCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/Smpp8BitSplitter.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCancelSmCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommandType.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDefaultSplitter.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppException.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppQuerySmCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplitter.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUcs2Splitter.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUtils.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/AbstractSmppCommandTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/Smpp8BitSplitterTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCancelSmCommandTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCommandTypeTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDefaultSplitterTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppQuerySmCommandTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppReplaceSmCommandTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSplitterTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitMultiCommandTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppSubmitSmCommandTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppUcs2SplitterTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppUtilsTest.java
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/SmppConfiguration.java
    camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.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/SmppConfigurationTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java
    camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.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

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/AbstractSmppCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/AbstractSmppCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/AbstractSmppCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/AbstractSmppCommand.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,49 @@
+/**
+ * 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;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.session.SMPPSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractSmppCommand implements SmppCommand {
+    
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    protected SMPPSession session;
+    protected SmppConfiguration config;
+
+    public AbstractSmppCommand(SMPPSession session, SmppConfiguration config) {
+        this.session = session;
+        this.config = config;
+    }
+    
+    protected Message getResponseMessage(Exchange exchange) {
+        Message message;
+        if (exchange.getPattern().isOutCapable()) {
+            log.debug("Exchange is out capable, setting headers on out exchange...");
+            message = exchange.getOut();
+        } else {
+            log.debug("Exchange is not out capable, setting headers on in exchange...");
+            message = exchange.getIn();
+        }
+        
+        return message;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/Smpp8BitSplitter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/Smpp8BitSplitter.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/Smpp8BitSplitter.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/Smpp8BitSplitter.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,27 @@
+/**
+ * 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 class Smpp8BitSplitter extends SmppSplitter {
+
+    public static final int MAX_MSG_CHAR_SIZE = MAX_MSG_BYTE_LENGTH;
+    public static final int MAX_SEG_BYTE_SIZE = MAX_MSG_BYTE_LENGTH - UDHIE_HEADER_REAL_LENGTH;
+
+    public Smpp8BitSplitter(int segmentLength) {
+        super(MAX_MSG_CHAR_SIZE, MAX_SEG_BYTE_SIZE, segmentLength);
+    }
+}
\ No newline at end of file

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=1179457&r1=1179456&r2=1179457&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 Wed Oct  5 21:55:46 2011
@@ -22,7 +22,6 @@ import java.util.Date;
 import java.util.List;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.jsmpp.bean.AlertNotification;
 import org.jsmpp.bean.Command;
 import org.jsmpp.bean.DataSm;
@@ -30,10 +29,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;
+import org.jsmpp.session.SMPPSession;
 
 /**
  * A Strategy used to convert between a Camel {@link Exchange} and
@@ -43,37 +39,6 @@ import org.jsmpp.util.TimeFormatter;
  */
 public class SmppBinding {
 
-    public static final String SEQUENCE_NUMBER = "CamelSmppSequenceNumber";
-    public static final String SUBMITTED = "CamelSmppSubmitted";
-    public static final String SUBMIT_DATE = "CamelSmppSubmitDate";
-    public static final String ERROR = "CamelSmppError";
-    public static final String DONE_DATE = "CamelSmppDoneDate";
-    public static final String DELIVERED = "CamelSmppDelivered";
-    public static final String COMMAND_ID = "CamelSmppCommandId";
-    public static final String COMMAND_STATUS = "CamelSmppCommandStatus";
-    public static final String ID = "CamelSmppId";
-    public static final String REPLACE_IF_PRESENT_FLAG = "CamelSmppReplaceIfPresentFlag";
-    public static final String VALIDITY_PERIOD = "CamelSmppValidityPeriod";
-    public static final String SCHEDULE_DELIVERY_TIME = "CamelSmppScheduleDeliveryTime";
-    public static final String PRIORITY_FLAG = "CamelSmppPriorityFlag";
-    public static final String PROTOCOL_ID = "CamelSmppProtocolId";
-    public static final String REGISTERED_DELIVERY = "CamelSmppRegisteredDelivery";
-    public static final String SERVICE_TYPE = "CamelSmppServiceType";
-    public static final String SOURCE_ADDR_NPI = "CamelSmppSourceAddrNpi";
-    public static final String SOURCE_ADDR_TON = "CamelSmppSourceAddrTon";
-    public static final String SOURCE_ADDR = "CamelSmppSourceAddr";
-    public static final String DEST_ADDR_NPI = "CamelSmppDestAddrNpi";
-    public static final String DEST_ADDR_TON = "CamelSmppDestAddrTon";
-    public static final String DEST_ADDR = "CamelSmppDestAddr";
-    public static final String ESME_ADDR_NPI = "CamelSmppEsmeAddrNpi";
-    public static final String ESME_ADDR_TON = "CamelSmppEsmeAddrTon";
-    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();
-
     private SmppConfiguration configuration;
 
     public SmppBinding() {
@@ -85,112 +50,15 @@ public class SmppBinding {
     }
 
     /**
-     * Create the SubmitSm object from the inbound exchange
+     * Create the SmppCommand object from the inbound exchange
      * 
      * @throws UnsupportedEncodingException if the encoding is not supported
      */
-    public SubmitSm createSubmitSm(Exchange exchange) throws UnsupportedEncodingException {
-        Message in = exchange.getIn();
-        String body = exchange.getIn().getBody(String.class);
-        
-        SubmitSm submitSm = new SubmitSm();
-        
-        if (body != null) {
-            byte[] shortMessage = body.getBytes(configuration.getEncoding());
-            
-            if (shortMessage.length < 255) {
-                submitSm.setShortMessage(shortMessage);
-                // To avoid the NPE error
-                submitSm.setOptionalParametes(new OptionalParameter[]{});
-            } 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));
-        } else {
-            submitSm.setDestAddress(configuration.getDestAddr());
-        }
-
-        if (in.getHeaders().containsKey(DEST_ADDR_TON)) {
-            submitSm.setDestAddrTon(in.getHeader(DEST_ADDR_TON, Byte.class));
-        } else {
-            submitSm.setDestAddrTon(configuration.getDestAddrTon());
-        }
-
-        if (in.getHeaders().containsKey(DEST_ADDR_NPI)) {
-            submitSm.setDestAddrNpi(in.getHeader(DEST_ADDR_NPI, Byte.class));
-        } else {
-            submitSm.setDestAddrNpi(configuration.getDestAddrNpi());
-        }
-
-        if (in.getHeaders().containsKey(SOURCE_ADDR)) {
-            submitSm.setSourceAddr(in.getHeader(SOURCE_ADDR, String.class));
-        } else {
-            submitSm.setSourceAddr(configuration.getSourceAddr());
-        }
-
-        if (in.getHeaders().containsKey(SOURCE_ADDR_TON)) {
-            submitSm.setSourceAddrTon(in.getHeader(SOURCE_ADDR_TON, Byte.class));
-        } else {
-            submitSm.setSourceAddrTon(configuration.getSourceAddrTon());
-        }
-
-        if (in.getHeaders().containsKey(SOURCE_ADDR_NPI)) {
-            submitSm.setSourceAddrNpi(in.getHeader(SOURCE_ADDR_NPI, Byte.class));
-        } else {
-            submitSm.setSourceAddrNpi(configuration.getSourceAddrNpi());
-        }
-
-        if (in.getHeaders().containsKey(SERVICE_TYPE)) {
-            submitSm.setServiceType(in.getHeader(SERVICE_TYPE, String.class));
-        } else {
-            submitSm.setServiceType(configuration.getServiceType());
-        }
-
-        if (in.getHeaders().containsKey(REGISTERED_DELIVERY)) {
-            submitSm.setRegisteredDelivery(in.getHeader(REGISTERED_DELIVERY, Byte.class));
-        } else {
-            submitSm.setRegisteredDelivery(configuration.getRegisteredDelivery());
-        }
-
-        if (in.getHeaders().containsKey(PROTOCOL_ID)) {
-            submitSm.setProtocolId(in.getHeader(PROTOCOL_ID, Byte.class));
-        } else {
-            submitSm.setProtocolId(configuration.getProtocolId());
-        }
-
-        if (in.getHeaders().containsKey(PRIORITY_FLAG)) {
-            submitSm.setPriorityFlag(in.getHeader(PRIORITY_FLAG, Byte.class));
-        } else {
-            submitSm.setPriorityFlag(configuration.getPriorityFlag());
-        }
-
-        if (in.getHeaders().containsKey(SCHEDULE_DELIVERY_TIME)) {
-            submitSm.setScheduleDeliveryTime(timeFormatter.format(in.getHeader(SCHEDULE_DELIVERY_TIME, Date.class)));
-        } 
-
-        if (in.getHeaders().containsKey(VALIDITY_PERIOD)) {
-            submitSm.setValidityPeriod(timeFormatter.format(in.getHeader(VALIDITY_PERIOD, Date.class)));
-        }
-
-        if (in.getHeaders().containsKey(REPLACE_IF_PRESENT_FLAG)) {
-            submitSm.setReplaceIfPresent(in.getHeader(REPLACE_IF_PRESENT_FLAG, Byte.class));
-        } else {
-            submitSm.setReplaceIfPresent(configuration.getReplaceIfPresentFlag());
-        }
+    public SmppCommand createSmppCommand(SMPPSession session, Exchange exchange) {
+        SmppCommandType commandType = SmppCommandType.fromExchange(exchange);
+        SmppCommand command = commandType.createCommand(session, configuration);
         
-        if (in.getHeaders().containsKey(DATA_CODING)) {
-            submitSm.setDataCoding(in.getHeader(DATA_CODING, Byte.class));
-        } else {
-            submitSm.setDataCoding(configuration.getDataCoding());
-        }
-
-        return submitSm;
+        return command;
     }
 
     /**
@@ -199,16 +67,16 @@ 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());
-        smppMessage.setHeader(SOURCE_ADDR, alertNotification.getSourceAddr());
-        smppMessage.setHeader(SOURCE_ADDR_NPI, alertNotification.getSourceAddrNpi());
-        smppMessage.setHeader(SOURCE_ADDR_TON, alertNotification.getSourceAddrTon());
-        smppMessage.setHeader(ESME_ADDR, alertNotification.getEsmeAddr());
-        smppMessage.setHeader(ESME_ADDR_NPI, alertNotification.getEsmeAddrNpi());
-        smppMessage.setHeader(ESME_ADDR_TON, alertNotification.getEsmeAddrTon());
+        smppMessage.setHeader(SmppConstants.MESSAGE_TYPE, SmppMessageType.AlertNotification.toString());
+        smppMessage.setHeader(SmppConstants.SEQUENCE_NUMBER, alertNotification.getSequenceNumber());
+        smppMessage.setHeader(SmppConstants.COMMAND_ID, alertNotification.getCommandId());
+        smppMessage.setHeader(SmppConstants.COMMAND_STATUS, alertNotification.getCommandStatus());
+        smppMessage.setHeader(SmppConstants.SOURCE_ADDR, alertNotification.getSourceAddr());
+        smppMessage.setHeader(SmppConstants.SOURCE_ADDR_NPI, alertNotification.getSourceAddrNpi());
+        smppMessage.setHeader(SmppConstants.SOURCE_ADDR_TON, alertNotification.getSourceAddrTon());
+        smppMessage.setHeader(SmppConstants.ESME_ADDR, alertNotification.getEsmeAddr());
+        smppMessage.setHeader(SmppConstants.ESME_ADDR_NPI, alertNotification.getEsmeAddrNpi());
+        smppMessage.setHeader(SmppConstants.ESME_ADDR_TON, alertNotification.getEsmeAddrTon());
 
         return smppMessage;
     }
@@ -220,21 +88,21 @@ public class SmppBinding {
         SmppMessage smppMessage = new SmppMessage(deliverSm, configuration);
 
         if (deliverSm.isSmscDeliveryReceipt()) {
-            smppMessage.setHeader(MESSAGE_TYPE, SmppMessageType.DeliveryReceipt.toString());
+            smppMessage.setHeader(SmppConstants.MESSAGE_TYPE, SmppMessageType.DeliveryReceipt.toString());
             DeliveryReceipt smscDeliveryReceipt = deliverSm.getShortMessageAsDeliveryReceipt();
             smppMessage.setBody(smscDeliveryReceipt.getText());
 
-            smppMessage.setHeader(ID, smscDeliveryReceipt.getId());
-            smppMessage.setHeader(DELIVERED, smscDeliveryReceipt.getDelivered());
-            smppMessage.setHeader(DONE_DATE, smscDeliveryReceipt.getDoneDate());
+            smppMessage.setHeader(SmppConstants.ID, smscDeliveryReceipt.getId());
+            smppMessage.setHeader(SmppConstants.DELIVERED, smscDeliveryReceipt.getDelivered());
+            smppMessage.setHeader(SmppConstants.DONE_DATE, smscDeliveryReceipt.getDoneDate());
             if (!"000".equals(smscDeliveryReceipt.getError())) {
-                smppMessage.setHeader(ERROR, smscDeliveryReceipt.getError());
+                smppMessage.setHeader(SmppConstants.ERROR, smscDeliveryReceipt.getError());
             }
-            smppMessage.setHeader(SUBMIT_DATE, smscDeliveryReceipt.getSubmitDate());
-            smppMessage.setHeader(SUBMITTED, smscDeliveryReceipt.getSubmitted());
-            smppMessage.setHeader(FINAL_STATUS, smscDeliveryReceipt.getFinalStatus());
+            smppMessage.setHeader(SmppConstants.SUBMIT_DATE, smscDeliveryReceipt.getSubmitDate());
+            smppMessage.setHeader(SmppConstants.SUBMITTED, smscDeliveryReceipt.getSubmitted());
+            smppMessage.setHeader(SmppConstants.FINAL_STATUS, smscDeliveryReceipt.getFinalStatus());
         } else {
-            smppMessage.setHeader(MESSAGE_TYPE, SmppMessageType.DeliverSm.toString());
+            smppMessage.setHeader(SmppConstants.MESSAGE_TYPE, SmppMessageType.DeliverSm.toString());
             if (deliverSm.getShortMessage() != null) {
                 smppMessage.setBody(String.valueOf(new String(deliverSm.getShortMessage(),
                         configuration.getEncoding())));
@@ -249,13 +117,13 @@ public class SmppBinding {
                 }
             }
 
-            smppMessage.setHeader(SEQUENCE_NUMBER, deliverSm.getSequenceNumber());
-            smppMessage.setHeader(COMMAND_ID, deliverSm.getCommandId());
-            smppMessage.setHeader(SOURCE_ADDR, deliverSm.getSourceAddr());
-            smppMessage.setHeader(DEST_ADDR, deliverSm.getDestAddress());
-            smppMessage.setHeader(SCHEDULE_DELIVERY_TIME, deliverSm.getScheduleDeliveryTime());
-            smppMessage.setHeader(VALIDITY_PERIOD, deliverSm.getValidityPeriod());
-            smppMessage.setHeader(SERVICE_TYPE, deliverSm.getServiceType());
+            smppMessage.setHeader(SmppConstants.SEQUENCE_NUMBER, deliverSm.getSequenceNumber());
+            smppMessage.setHeader(SmppConstants.COMMAND_ID, deliverSm.getCommandId());
+            smppMessage.setHeader(SmppConstants.SOURCE_ADDR, deliverSm.getSourceAddr());
+            smppMessage.setHeader(SmppConstants.DEST_ADDR, deliverSm.getDestAddress());
+            smppMessage.setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, deliverSm.getScheduleDeliveryTime());
+            smppMessage.setHeader(SmppConstants.VALIDITY_PERIOD, deliverSm.getValidityPeriod());
+            smppMessage.setHeader(SmppConstants.SERVICE_TYPE, deliverSm.getServiceType());
         }
 
         return smppMessage;
@@ -264,20 +132,20 @@ 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());
-        smppMessage.setHeader(COMMAND_STATUS, dataSm.getCommandStatus());
-        smppMessage.setHeader(SOURCE_ADDR, dataSm.getSourceAddr());
-        smppMessage.setHeader(SOURCE_ADDR_NPI, dataSm.getSourceAddrNpi());
-        smppMessage.setHeader(SOURCE_ADDR_TON, dataSm.getSourceAddrTon());
-        smppMessage.setHeader(DEST_ADDR, dataSm.getDestAddress());
-        smppMessage.setHeader(DEST_ADDR_NPI, dataSm.getDestAddrNpi());
-        smppMessage.setHeader(DEST_ADDR_TON, dataSm.getDestAddrTon());
-        smppMessage.setHeader(SERVICE_TYPE, dataSm.getServiceType());
-        smppMessage.setHeader(REGISTERED_DELIVERY, dataSm.getRegisteredDelivery());
-        smppMessage.setHeader(DATA_CODING, dataSm.getDataCoding());
+        smppMessage.setHeader(SmppConstants.MESSAGE_TYPE, SmppMessageType.DataSm.toString());
+        smppMessage.setHeader(SmppConstants.ID, smppMessageId);
+        smppMessage.setHeader(SmppConstants.SEQUENCE_NUMBER, dataSm.getSequenceNumber());
+        smppMessage.setHeader(SmppConstants.COMMAND_ID, dataSm.getCommandId());
+        smppMessage.setHeader(SmppConstants.COMMAND_STATUS, dataSm.getCommandStatus());
+        smppMessage.setHeader(SmppConstants.SOURCE_ADDR, dataSm.getSourceAddr());
+        smppMessage.setHeader(SmppConstants.SOURCE_ADDR_NPI, dataSm.getSourceAddrNpi());
+        smppMessage.setHeader(SmppConstants.SOURCE_ADDR_TON, dataSm.getSourceAddrTon());
+        smppMessage.setHeader(SmppConstants.DEST_ADDR, dataSm.getDestAddress());
+        smppMessage.setHeader(SmppConstants.DEST_ADDR_NPI, dataSm.getDestAddrNpi());
+        smppMessage.setHeader(SmppConstants.DEST_ADDR_TON, dataSm.getDestAddrTon());
+        smppMessage.setHeader(SmppConstants.SERVICE_TYPE, dataSm.getServiceType());
+        smppMessage.setHeader(SmppConstants.REGISTERED_DELIVERY, dataSm.getRegisteredDelivery());
+        smppMessage.setHeader(SmppConstants.DATA_CODING, dataSm.getDataCoding());
 
         return smppMessage;
     }
@@ -308,4 +176,4 @@ public class SmppBinding {
     public void setConfiguration(SmppConfiguration configuration) {
         this.configuration = configuration;
     }
-}
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCancelSmCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCancelSmCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCancelSmCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCancelSmCommand.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,112 @@
+/**
+ * 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;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.bean.CancelSm;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.SMPPSession;
+
+public class SmppCancelSmCommand extends AbstractSmppCommand {
+
+    public SmppCancelSmCommand(SMPPSession session, SmppConfiguration config) {
+        super(session, config);
+    }
+
+    @Override
+    public void execute(Exchange exchange) throws SmppException {
+        CancelSm cancelSm = createCancelSm(exchange);
+        
+        log.debug("Canceling a short message for exchange id '{}' and message id '{}'",
+                exchange.getExchangeId(), cancelSm.getMessageId());
+
+        try {
+            session.cancelShortMessage(
+                    cancelSm.getServiceType(),
+                    cancelSm.getMessageId(),
+                    TypeOfNumber.valueOf(cancelSm.getSourceAddrTon()),
+                    NumberingPlanIndicator.valueOf(cancelSm.getSourceAddrNpi()),
+                    cancelSm.getSourceAddr(),
+                    TypeOfNumber.valueOf(cancelSm.getDestAddrTon()),
+                    NumberingPlanIndicator.valueOf(cancelSm.getDestAddrNpi()),
+                    cancelSm.getDestinationAddress());
+        } catch (Exception e) {
+            throw new SmppException(e);
+        }
+
+        log.debug("Cancel a short message for exchange id '{}' and message id '{}'",
+                exchange.getExchangeId(), cancelSm.getMessageId());
+
+        Message message = getResponseMessage(exchange);
+        message.setHeader(SmppConstants.ID, cancelSm.getMessageId());
+    }
+
+    protected CancelSm createCancelSm(Exchange exchange) {
+        Message in = exchange.getIn();
+        CancelSm cancelSm = new CancelSm();
+
+        if (in.getHeaders().containsKey(SmppConstants.ID)) {
+            cancelSm.setMessageId(in.getHeader(SmppConstants.ID, String.class));
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
+            cancelSm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
+        } else {
+            cancelSm.setSourceAddr(config.getSourceAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
+            cancelSm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
+        } else {
+            cancelSm.setSourceAddrTon(config.getSourceAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
+            cancelSm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
+        } else {
+            cancelSm.setSourceAddrNpi(config.getSourceAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR)) {
+            cancelSm.setDestinationAddress(in.getHeader(SmppConstants.DEST_ADDR, String.class));
+        } else {
+            cancelSm.setDestinationAddress(config.getDestAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_TON)) {
+            cancelSm.setDestAddrTon(in.getHeader(SmppConstants.DEST_ADDR_TON, Byte.class));
+        } else {
+            cancelSm.setDestAddrTon(config.getDestAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_NPI)) {
+            cancelSm.setDestAddrNpi(in.getHeader(SmppConstants.DEST_ADDR_NPI, Byte.class));
+        } else {
+            cancelSm.setDestAddrNpi(config.getDestAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SERVICE_TYPE)) {
+            cancelSm.setServiceType(in.getHeader(SmppConstants.SERVICE_TYPE, String.class));
+        } else {
+            cancelSm.setServiceType(config.getServiceType());
+        }
+
+        return cancelSm;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommand.java Wed Oct  5 21:55:46 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;
+
+import org.apache.camel.Exchange;
+
+public interface SmppCommand {
+
+    void execute(Exchange exchange) throws SmppException;
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommandType.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommandType.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommandType.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppCommandType.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,112 @@
+/**
+ * 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;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.session.SMPPSession;
+
+public enum SmppCommandType {
+
+    SUBMIT_SM("SubmitSm") {
+        @Override
+        public SmppSubmitSmCommand createCommand(SMPPSession session, SmppConfiguration config) {
+            return new SmppSubmitSmCommand(session, config);
+        }
+    },
+    REPLACE_SM("ReplaceSm") {
+        @Override
+        public SmppReplaceSmCommand createCommand(SMPPSession session, SmppConfiguration config) {
+            return new SmppReplaceSmCommand(session, config);
+        }
+    },
+    QUERY_SM("QuerySm") {
+        @Override
+        public SmppQuerySmCommand createCommand(SMPPSession session, SmppConfiguration config) {
+            return new SmppQuerySmCommand(session, config);
+        }
+    },
+    SUBMIT_MULTI("SubmitMulti") {
+        @Override
+        public SmppSubmitMultiCommand createCommand(SMPPSession session, SmppConfiguration config) {
+            return new SmppSubmitMultiCommand(session, config);
+        }
+    },
+    CANCEL_SM("CancelSm") {
+        @Override
+        public SmppCancelSmCommand createCommand(SMPPSession session, SmppConfiguration config) {
+            return new SmppCancelSmCommand(session, config);
+        }
+    },
+    DATA_SHORT_MESSAGE("DataSm") {
+        @Override
+        public SmppDataSmCommand createCommand(SMPPSession session, SmppConfiguration config) {
+            return new SmppDataSmCommand(session, config);
+        }
+    };
+
+    private String commandName;
+
+    private SmppCommandType(String commandName) {
+        this.commandName = commandName;
+    }
+
+    public String getCommandName() {
+        return commandName;
+    }
+
+    public abstract SmppCommand createCommand(SMPPSession session, SmppConfiguration config);
+
+    /**
+     * Tries to return an instance of {@link SmppCommandType} using
+     * {@link SmppConstants#COMMAND} header of the incoming message.
+     * <p/>
+     * Returns {@link #SUBMIT_SM} if threre is no {@link SmppConstants#COMMAND}
+     * header in the incoming message or value of such a header cannot be
+     * recognized.
+     * <p/>
+     * The valid values for the {@link SmppConstants#COMMAND} header are: <span
+     * style="font: bold;">SubmitSm</span> <span
+     * style="font: bold;">ReplaceSm</span>, <span
+     * style="font: bold;">QuerySm</span>, <span
+     * style="font: bold;">SubmitMulti</span>, <span
+     * style="font: bold;">CancelSm</span>, <span
+     * style="font: bold;">DataSm</span>.
+     * 
+     * @param exchange
+     *            an exchange to get an incoming message from
+     * @return an instalce of {@link SmppCommandType}
+     */
+    public static SmppCommandType fromExchange(Exchange exchange) {
+        Message in = exchange.getIn();
+
+        String commandName = null;
+        if (in.getHeaders().containsKey(SmppConstants.COMMAND)) {
+            commandName = in.getHeader(SmppConstants.COMMAND, String.class);
+        }
+
+        SmppCommandType commandType = SUBMIT_SM;
+        for (SmppCommandType nextCommandType : values()) {
+            if (nextCommandType.commandName.equals(commandName)) {
+                commandType = nextCommandType;
+                break;
+            }
+        }
+
+        return commandType;
+    }
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java?rev=1179457&r1=1179456&r2=1179457&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java (original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java Wed Oct  5 21:55:46 2011
@@ -19,7 +19,9 @@ package org.apache.camel.component.smpp;
 import java.net.URI;
 
 import org.apache.camel.RuntimeCamelException;
+import org.jsmpp.bean.Alphabet;
 import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.ReplaceIfPresentFlag;
 import org.jsmpp.bean.SMSCDeliveryReceipt;
 import org.jsmpp.bean.TypeOfNumber;
 
@@ -35,12 +37,12 @@ public class SmppConfiguration implement
     private String systemId = "smppclient";
     private String password = "password";
     private String systemType = "cp";
-    private byte dataCoding = (byte) 0;
+    // TODO: document deleting of dataCoding
+    private byte alphabet = Alphabet.ALPHA_DEFAULT.value();
     private String encoding = "ISO-8859-1";
     private Integer enquireLinkTimer = 5000;
     private Integer transactionTimer = 10000;
-    private byte registeredDelivery = SMSCDeliveryReceipt.SUCCESS_FAILURE
-            .value();
+    private byte registeredDelivery = SMSCDeliveryReceipt.SUCCESS_FAILURE.value();
     private String serviceType = "CMT";
     private String sourceAddr = "1616";
     private String destAddr = "1717";
@@ -50,7 +52,7 @@ public class SmppConfiguration implement
     private byte destAddrNpi = NumberingPlanIndicator.UNKNOWN.value();
     private byte protocolId = (byte) 0;
     private byte priorityFlag = (byte) 1;
-    private byte replaceIfPresentFlag = (byte) 0;
+    private byte replaceIfPresentFlag = ReplaceIfPresentFlag.DEFAULT.value();
     private byte typeOfNumber = TypeOfNumber.UNKNOWN.value();
     private byte numberingPlanIndicator = NumberingPlanIndicator.UNKNOWN.value();
     private boolean usingSSL;
@@ -108,12 +110,12 @@ public class SmppConfiguration implement
         return password;
     }
     
-    public byte getDataCoding() {
-        return dataCoding;
+    public byte getAlphabet() {
+        return alphabet;
     }
 
-    public void setDataCoding(byte dataCoding) {
-        this.dataCoding = dataCoding;
+    public void setAlphabet(byte alphabet) {
+        this.alphabet = alphabet;
     }
     
     public String getEncoding() {
@@ -297,7 +299,7 @@ public class SmppConfiguration implement
             + ", port=" + port 
             + ", systemId=" + systemId 
             + ", systemType=" + systemType
-            + ", dataCoding=" + dataCoding
+            + ", alphabet=" + alphabet
             + ", encoding=" + encoding
             + ", transactionTimer=" + transactionTimer
             + ", registeredDelivery=" + registeredDelivery

Added: 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=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,61 @@
+/**
+ * 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;
+
+/**
+ * Constants used in Camel SMPP module
+ *
+ */
+public interface SmppConstants {
+
+    String ALPHABET = "CamelSmppAlphabet";
+    String COMMAND = "CamelSmppCommand";
+    String COMMAND_ID = "CamelSmppCommandId";
+    String COMMAND_STATUS = "CamelSmppCommandStatus";
+    String DATA_CODING = "CamelSmppDataCoding";
+    String DELIVERED = "CamelSmppDelivered";
+    String DEST_ADDR = "CamelSmppDestAddr";
+    String DEST_ADDR_NPI = "CamelSmppDestAddrNpi";
+    String DEST_ADDR_TON = "CamelSmppDestAddrTon";
+    String DONE_DATE = "CamelSmppDoneDate";
+    String ERROR = "CamelSmppError";
+    String ESME_ADDR = "CamelSmppEsmeAddr";
+    String ESME_ADDR_NPI = "CamelSmppEsmeAddrNpi";
+    String ESME_ADDR_TON = "CamelSmppEsmeAddrTon";
+    String FINAL_DATE = "CamelSmppFinalDate";
+    String FINAL_STATUS = "CamelSmppStatus";
+    String ID = "CamelSmppId";
+    String MESSAGE_STATE = "CamelSmppMessageState";
+    String MESSAGE_TYPE = "CamelSmppMessageType";
+    String PRIORITY_FLAG = "CamelSmppPriorityFlag";
+    String PROTOCOL_ID = "CamelSmppProtocolId";
+    String REGISTERED_DELIVERY = "CamelSmppRegisteredDelivery";
+    String REPLACE_IF_PRESENT_FLAG = "CamelSmppReplaceIfPresentFlag";
+    String SCHEDULE_DELIVERY_TIME = "CamelSmppScheduleDeliveryTime";
+    String SENT_MESSAGE_COUNT = "CamelSmppSentMessageCount"; // TODO: document this new property
+    String SEQUENCE_NUMBER = "CamelSmppSequenceNumber";
+    String SERVICE_TYPE = "CamelSmppServiceType";
+    String SOURCE_ADDR = "CamelSmppSourceAddr";
+    String SOURCE_ADDR_NPI = "CamelSmppSourceAddrNpi";
+    String SOURCE_ADDR_TON = "CamelSmppSourceAddrTon";
+    String SUBMITTED = "CamelSmppSubmitted";
+    String SUBMIT_DATE = "CamelSmppSubmitDate";
+    String VALIDITY_PERIOD = "CamelSmppValidityPeriod";
+    
+    String UCS2_ENCODING = "UTF-16BE";
+    byte UNKNOWN_ALPHABET = -1;
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDataSmCommand.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,120 @@
+/**
+ * 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;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.bean.DataSm;
+import org.jsmpp.bean.ESMClass;
+import org.jsmpp.bean.GeneralDataCoding;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.RegisteredDelivery;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.DataSmResult;
+import org.jsmpp.session.SMPPSession;
+
+public class SmppDataSmCommand extends AbstractSmppCommand {
+
+    public SmppDataSmCommand(SMPPSession session, SmppConfiguration config) {
+        super(session, config);
+    }
+
+    @Override
+    public void execute(Exchange exchange) throws SmppException {
+        DataSm dataSm = createDataSm(exchange);
+
+        log.debug("Sending a data short message for exchange id '{}'...", exchange.getExchangeId());
+        
+        DataSmResult result;
+        try {
+            result = session.dataShortMessage(
+                    dataSm.getServiceType(),
+                    TypeOfNumber.valueOf(dataSm.getSourceAddrTon()),
+                    NumberingPlanIndicator.valueOf(dataSm.getSourceAddrNpi()),
+                    dataSm.getSourceAddr(),
+                    TypeOfNumber.valueOf(dataSm.getDestAddrTon()),
+                    NumberingPlanIndicator.valueOf(dataSm.getDestAddrNpi()),
+                    dataSm.getDestAddress(),
+                    new ESMClass(dataSm.getEsmClass()),
+                    new RegisteredDelivery(dataSm.getRegisteredDelivery()),
+                    new GeneralDataCoding(dataSm.getDataCoding()));
+        } catch (Exception e) {
+            throw new SmppException(e);
+        }
+
+        log.debug("Sent a data short message for exchange id '{}' and message id '{}'",
+                exchange.getExchangeId(), result.getMessageId());
+
+        Message message = getResponseMessage(exchange);
+        message.setHeader(SmppConstants.ID, result.getMessageId());
+    }
+
+    protected DataSm createDataSm(Exchange exchange) {
+        Message in = exchange.getIn();
+        DataSm dataSm = new DataSm();
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR)) {
+            dataSm.setDestAddress(in.getHeader(SmppConstants.DEST_ADDR, String.class));
+        } else {
+            dataSm.setDestAddress(config.getDestAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_TON)) {
+            dataSm.setDestAddrTon(in.getHeader(SmppConstants.DEST_ADDR_TON, Byte.class));
+        } else {
+            dataSm.setDestAddrTon(config.getDestAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_NPI)) {
+            dataSm.setDestAddrNpi(in.getHeader(SmppConstants.DEST_ADDR_NPI, Byte.class));
+        } else {
+            dataSm.setDestAddrNpi(config.getDestAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
+            dataSm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
+        } else {
+            dataSm.setSourceAddr(config.getSourceAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
+            dataSm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
+        } else {
+            dataSm.setSourceAddrTon(config.getSourceAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
+            dataSm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
+        } else {
+            dataSm.setSourceAddrNpi(config.getSourceAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SERVICE_TYPE)) {
+            dataSm.setServiceType(in.getHeader(SmppConstants.SERVICE_TYPE, String.class));
+        } else {
+            dataSm.setServiceType(config.getServiceType());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
+            dataSm.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, Byte.class));
+        } else {
+            dataSm.setRegisteredDelivery(config.getRegisteredDelivery());
+        }
+
+        return dataSm;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDefaultSplitter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDefaultSplitter.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDefaultSplitter.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppDefaultSplitter.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,27 @@
+/**
+ * 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 class SmppDefaultSplitter extends SmppSplitter {
+
+    public static final int MAX_MSG_CHAR_SIZE = MAX_MSG_BYTE_LENGTH * 8 / 7;
+    public static final int MAX_SEG_BYTE_SIZE = (MAX_MSG_BYTE_LENGTH - UDHIE_HEADER_REAL_LENGTH) * 8 / 7;
+
+    public SmppDefaultSplitter(int currentLength) {
+        super(MAX_MSG_CHAR_SIZE, MAX_SEG_BYTE_SIZE, currentLength);
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppException.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppException.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppException.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppException.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,34 @@
+/**
+ * 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 class SmppException extends Exception {
+
+    private static final long serialVersionUID = -867341540655702828L;
+
+    public SmppException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public SmppException(String message) {
+        super(message);
+    }
+
+    public SmppException(Throwable cause) {
+        super(cause);
+    }
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java?rev=1179457&r1=1179456&r2=1179457&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java (original)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java Wed Oct  5 21:55:46 2011
@@ -24,14 +24,8 @@ import org.apache.camel.impl.DefaultProd
 import org.jsmpp.DefaultPDUReader;
 import org.jsmpp.DefaultPDUSender;
 import org.jsmpp.SynchronizedPDUSender;
-import org.jsmpp.bean.Alphabet;
 import org.jsmpp.bean.BindType;
-import org.jsmpp.bean.ESMClass;
-import org.jsmpp.bean.GeneralDataCoding;
-import org.jsmpp.bean.MessageClass;
 import org.jsmpp.bean.NumberingPlanIndicator;
-import org.jsmpp.bean.RegisteredDelivery;
-import org.jsmpp.bean.SubmitSm;
 import org.jsmpp.bean.TypeOfNumber;
 import org.jsmpp.extra.SessionState;
 import org.jsmpp.session.BindParameter;
@@ -135,48 +129,13 @@ public class SmppProducer extends Defaul
             }
         }
         
-        LOG.debug("Sending a short message for exchange id '{}'...", exchange.getExchangeId());
-        
         // only possible by trying to reconnect 
         if (this.session == null) {
             throw new IOException("Lost connection to " + getEndpoint().getConnectionString() + " and yet not reconnected");
         }
-
-        SubmitSm submitSm = getEndpoint().getBinding().createSubmitSm(exchange);
-        String messageId = session.submitShortMessage(
-                submitSm.getServiceType(), 
-                TypeOfNumber.valueOf(submitSm.getSourceAddrTon()),
-                NumberingPlanIndicator.valueOf(submitSm.getSourceAddrNpi()),
-                submitSm.getSourceAddr(),
-                TypeOfNumber.valueOf(submitSm.getDestAddrTon()),
-                NumberingPlanIndicator.valueOf(submitSm.getDestAddrNpi()),
-                submitSm.getDestAddress(),
-                new ESMClass(),
-                submitSm.getProtocolId(),
-                submitSm.getPriorityFlag(),
-                submitSm.getScheduleDeliveryTime(),
-                submitSm.getValidityPeriod(),
-                new RegisteredDelivery(submitSm.getRegisteredDelivery()),
-                submitSm.getReplaceIfPresent(),
-                new GeneralDataCoding(
-                        false,
-                        true,
-                        MessageClass.CLASS1,
-                        Alphabet.valueOf(submitSm.getDataCoding())),
-                (byte) 0,
-                submitSm.getShortMessage(),
-                submitSm.getOptionalParametes());
-
-        LOG.debug("Sent a short message for exchange id '{}' and received message id '{}'",
-                exchange.getExchangeId(), messageId);
-
-        if (exchange.getPattern().isOutCapable()) {
-            LOG.debug("Exchange is out capable, setting headers on out exchange...");
-            exchange.getOut().setHeader(SmppBinding.ID, messageId);
-        } else {
-            LOG.debug("Exchange is not out capable, setting headers on in exchange...");
-            exchange.getIn().setHeader(SmppBinding.ID, messageId);
-        }
+        
+        SmppCommand command = getEndpoint().getBinding().createSmppCommand(session, exchange);
+        command.execute(exchange);
     }
 
     @Override
@@ -267,4 +226,4 @@ public class SmppProducer extends Defaul
     public String toString() {
         return "SmppProducer[" + getEndpoint().getConnectionString() + "]";
     }
-}
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppQuerySmCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppQuerySmCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppQuerySmCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppQuerySmCommand.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,89 @@
+/**
+ * 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;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.QuerySm;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.QuerySmResult;
+import org.jsmpp.session.SMPPSession;
+
+public class SmppQuerySmCommand extends AbstractSmppCommand {
+
+    public SmppQuerySmCommand(SMPPSession session, SmppConfiguration config) {
+        super(session, config);
+    }
+
+    @Override
+    public void execute(Exchange exchange) throws SmppException {
+        QuerySm querySm = createQuerySm(exchange);
+
+        log.debug("Querying for a short message for exchange id '{}' and message id '{}'...",
+                exchange.getExchangeId(), querySm.getMessageId());
+        
+        QuerySmResult querySmResult;
+        try {
+            querySmResult = session.queryShortMessage(
+                    querySm.getMessageId(),
+                    TypeOfNumber.valueOf(querySm.getSourceAddrTon()),
+                    NumberingPlanIndicator.valueOf(querySm.getSourceAddrNpi()),
+                    querySm.getSourceAddr());
+        } catch (Exception e) {
+            throw new SmppException(e);
+        }
+
+        log.debug("Query for a short message for exchange id '{}' and message id '{}'",
+                exchange.getExchangeId(), querySm.getMessageId());
+
+        Message message = getResponseMessage(exchange);
+        message.setHeader(SmppConstants.ID, querySm.getMessageId());
+        message.setHeader(SmppConstants.ERROR, querySmResult.getErrorCode());
+        message.setHeader(SmppConstants.FINAL_DATE, SmppUtils.string2Date(querySmResult.getFinalDate()));
+        message.setHeader(SmppConstants.MESSAGE_STATE, querySmResult.getMessageState().name());
+    }
+
+    protected QuerySm createQuerySm(Exchange exchange) {
+        Message in = exchange.getIn();
+        QuerySm querySm = new QuerySm();
+
+        if (in.getHeaders().containsKey(SmppConstants.ID)) {
+            querySm.setMessageId(in.getHeader(SmppConstants.ID, String.class));
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
+            querySm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
+        } else {
+            querySm.setSourceAddr(config.getSourceAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
+            querySm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
+        } else {
+            querySm.setSourceAddrTon(config.getSourceAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
+            querySm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
+        } else {
+            querySm.setSourceAddrNpi(config.getSourceAddrNpi());
+        }
+
+        return querySm;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppReplaceSmCommand.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,120 @@
+/**
+ * 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;
+
+import java.nio.charset.Charset;
+import java.util.Date;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.bean.Alphabet;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.RegisteredDelivery;
+import org.jsmpp.bean.ReplaceSm;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.SMPPSession;
+
+public class SmppReplaceSmCommand extends SmppSmCommand {
+
+    public SmppReplaceSmCommand(SMPPSession session, SmppConfiguration config) {
+        super(session, config);
+    }
+
+    @Override
+    public void execute(Exchange exchange) throws SmppException {
+        String body = exchange.getIn().getBody(String.class);
+
+        byte providedAlphabet = getProvidedAlphabet(exchange);
+        Alphabet determinedAlphabet = determineAlphabet(exchange);
+        Charset charset = determineCharset(providedAlphabet, determinedAlphabet.value());
+
+        byte[] message = null;
+        if (body != null) {
+            message = body.getBytes(charset);
+        }
+
+        ReplaceSm replaceSm = createReplaceSmTempate(exchange);
+        replaceSm.setShortMessage(message);
+        
+        log.debug("Sending replacement command for a short message for exchange id '{}' and message id '{}'",
+                exchange.getExchangeId(), replaceSm.getMessageId());
+
+        try {
+            session.replaceShortMessage(
+                    replaceSm.getMessageId(),
+                    TypeOfNumber.valueOf(replaceSm.getSourceAddrTon()),
+                    NumberingPlanIndicator.valueOf(replaceSm.getSourceAddrNpi()),
+                    replaceSm.getSourceAddr(),
+                    replaceSm.getScheduleDeliveryTime(),
+                    replaceSm.getValidityPeriod(),
+                    new RegisteredDelivery(replaceSm.getRegisteredDelivery()),
+                    replaceSm.getSmDefaultMsgId(),
+                    replaceSm.getShortMessage());
+        } catch (Exception e) {
+            throw new SmppException(e);
+        }
+
+        log.debug("Sent replacement command for a short message for exchange id '{}' and message id '{}'",
+                exchange.getExchangeId(), replaceSm.getMessageId());
+        
+        Message rspMsg = getResponseMessage(exchange);
+        rspMsg.setHeader(SmppConstants.ID, replaceSm.getMessageId());
+    }
+
+    protected ReplaceSm createReplaceSmTempate(Exchange exchange) {
+        Message in = exchange.getIn();
+        ReplaceSm replaceSm = new ReplaceSm();
+
+        if (in.getHeaders().containsKey(SmppConstants.ID)) {
+            replaceSm.setMessageId(in.getHeader(SmppConstants.ID, String.class));
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
+            replaceSm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
+        } else {
+            replaceSm.setSourceAddr(config.getSourceAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
+            replaceSm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
+        } else {
+            replaceSm.setSourceAddrTon(config.getSourceAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
+            replaceSm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
+        } else {
+            replaceSm.setSourceAddrNpi(config.getSourceAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
+            replaceSm.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, Byte.class));
+        } else {
+            replaceSm.setRegisteredDelivery(config.getRegisteredDelivery());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SCHEDULE_DELIVERY_TIME)) {
+            replaceSm.setScheduleDeliveryTime(SmppUtils.formatTime(in.getHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, Date.class)));
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
+            replaceSm.setValidityPeriod(SmppUtils.formatTime(in.getHeader(SmppConstants.VALIDITY_PERIOD, Date.class)));
+        }
+
+        return replaceSm;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,97 @@
+/**
+ * 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;
+
+import java.nio.charset.Charset;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.bean.Alphabet;
+import org.jsmpp.session.SMPPSession;
+
+public abstract class SmppSmCommand extends AbstractSmppCommand {
+
+    protected Charset charset;
+
+    public SmppSmCommand(SMPPSession session, SmppConfiguration config) {
+        super(session, config);
+        this.charset = Charset.forName(config.getEncoding());
+    }
+
+    protected byte getProvidedAlphabet(Exchange exchange) {
+        Message in = exchange.getIn();
+
+        byte alphabet = SmppConstants.UNKNOWN_ALPHABET;
+        if (in.getHeaders().containsKey(SmppConstants.ALPHABET)) {
+            alphabet = in.getHeader(SmppConstants.ALPHABET, Byte.class);
+        } else {
+            alphabet = config.getAlphabet();
+        }
+
+        return alphabet;
+    }
+
+    protected Charset determineCharset(byte providedAlphabet, byte determinedAlphabet) {
+        if (providedAlphabet == SmppConstants.UNKNOWN_ALPHABET && determinedAlphabet == Alphabet.ALPHA_UCS2.value()) {
+            return Charset.forName(SmppConstants.UCS2_ENCODING); // change charset to use multilang messages
+        }
+        
+        return charset;
+    }
+
+    protected Alphabet determineAlphabet(Exchange exchange) {
+        String body = exchange.getIn().getBody(String.class);
+        byte alphabet = getProvidedAlphabet(exchange);
+
+        Alphabet alphabetObj;
+        if (alphabet == SmppConstants.UNKNOWN_ALPHABET) {
+            byte[] message = body.getBytes(charset);
+            if (SmppUtils.isGsm0338Encodeable(message)) {
+                alphabetObj = Alphabet.ALPHA_DEFAULT;
+            } else {
+                alphabetObj = Alphabet.ALPHA_UCS2;
+            }
+        } else {
+            alphabetObj = Alphabet.valueOf(alphabet);
+        }
+
+        return alphabetObj;
+    }
+
+    protected SmppSplitter createSplitter(Exchange exchange) {
+        Alphabet alphabet = determineAlphabet(exchange);
+
+        Message in = exchange.getIn();
+        String body = in.getBody(String.class);
+
+        SmppSplitter splitter;
+        switch (alphabet) {
+        case ALPHA_8_BIT:
+            splitter = new Smpp8BitSplitter(body.length());
+            break;
+        case ALPHA_UCS2:
+            splitter = new SmppUcs2Splitter(body.length());
+            break;
+        case ALPHA_DEFAULT:
+        default:
+            splitter = new SmppDefaultSplitter(body.length());
+            break;
+        }
+
+        return splitter;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplitter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplitter.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplitter.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplitter.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,204 @@
+/**
+ * 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;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SmppSplitter {
+
+    /**
+     * The length of the UDH in bytes.
+     * <p/>
+     * The real length of the header must be 6 bytes, but the first byte that
+     * contains the length of the header must not be counted.
+     */
+    protected static final int UDHIE_HEADER_LENGTH = 0x05;
+
+    /**
+     * The real length of the UDH header.
+     * <p/>
+     * The real length of the UDH header is {@link #UDHIE_HEADER_LENGTH}
+     * {@code + 1}.
+     * 
+     * @see #UDHIE_HEADER_LENGTH
+     */
+    protected static final int UDHIE_HEADER_REAL_LENGTH = UDHIE_HEADER_LENGTH + 1;
+
+    /**
+     * The length of the reference number of the SAR fragmet of the UDH header.
+     * <p/>
+     * The length can be 1 or 2 bytes and is considered to be 1 byte.
+     */
+    protected static final int UDHIE_SAR_REF_NUM_LENGTH = 1;
+
+    /**
+     * The value that identifier length of the SAR fragment.
+     * <p/>
+     * {@code 0x00} value must be used if the legnth of the reference number is
+     * 1 byte.<br/>
+     * {@code 0x08} value must be used if the legnth of the reference number is
+     * 2 bytes.
+     */
+    protected static final byte UDHIE_IDENTIFIER_SAR = 0x00;
+
+    /**
+     * The length of the SAR fragment.
+     * <p/>
+     * {@code 0x03} value must be used if the legnth of the reference number is
+     * 1 byte.<br/>
+     * {@code 0x04} value must be used if the legnth of the reference number is
+     * 2 bytes.
+     */
+    protected static final byte UDHIE_SAR_LENGTH = 0x03;
+
+    /**
+     * The maximum length of the message in bytes.
+     */
+    protected static final int MAX_MSG_BYTE_LENGTH = 140;
+
+    /**
+     * The maximum amount of segments in the multipart message.
+     */
+    protected static final int MAX_SEG_COUNT = 255;
+
+    private static final Logger LOG = LoggerFactory.getLogger(SmppSplitter.class);
+    
+    /**
+     * Current reference number.
+     */
+    private static int refNum;
+
+    private int messageLength;
+    private int segmentLength;
+    private int currentLength;
+
+    protected SmppSplitter(int messageLength, int segmentLength, int currentLength) {
+        this.messageLength = messageLength;
+        this.segmentLength = segmentLength;
+        this.currentLength = currentLength;
+    }
+
+    /**
+     * Returns reference number which length is
+     * {@link #UDHIE_SAR_REF_NUM_LENGTH}.
+     * 
+     * @return the reference number of the multipart message
+     */
+    protected static synchronized byte getReferenceNumber() {
+        refNum++;
+        if (refNum == 256) {
+            refNum = 1;
+        }
+        return (byte) refNum;
+    }
+
+    protected static synchronized byte getCurrentReferenceNumber() {
+        return (byte) refNum;
+    }
+    
+    /**
+     * only needed for the unit tests 
+     */
+    protected static synchronized void resetCurrentReferenceNumber() {
+        SmppSplitter.refNum = 0;
+    }
+
+    public byte[][] split(byte[] message) {
+        if (!isSplitRequired()) {
+            return new byte[][] {message};
+        }
+
+        int segmentLength = getSegmentLength();
+
+        // determine how many messages
+        int segmentNum = message.length / segmentLength;
+        int messageLength = message.length;
+        if (segmentNum > MAX_SEG_COUNT) {
+            // this is too long, can't fit, so chop
+            segmentNum = MAX_SEG_COUNT;
+            messageLength = segmentNum * segmentLength;
+        }
+        if ((messageLength % segmentLength) > 0) {
+            segmentNum++;
+        }
+
+        byte[][] segments = new byte[segmentNum][];
+
+        int lengthOfData;
+        byte refNum = getReferenceNumber();
+        for (int i = 0; i < segmentNum; i++) {
+            LOG.debug("segment number = {}", i);
+            if (segmentNum - i == 1) {
+                lengthOfData = messageLength - i * segmentLength;
+            } else {
+                lengthOfData = segmentLength;
+            }
+            LOG.debug("Length of data = {}", lengthOfData);
+
+            segments[i] = new byte[UDHIE_HEADER_REAL_LENGTH + lengthOfData];
+            LOG.debug("segments[{}].length = {}", i, segments[i].length);
+
+            segments[i][0] = UDHIE_HEADER_LENGTH; // doesn't include itself, is header length
+            // SAR identifier
+            segments[i][1] = UDHIE_IDENTIFIER_SAR;
+            // SAR length
+            segments[i][2] = UDHIE_SAR_LENGTH;
+            // DATAGRAM REFERENCE NUMBER
+            segments[i][3] = refNum;
+            // total number of segments
+            segments[i][4] = (byte) segmentNum;
+            // segment #
+            segments[i][5] = (byte) (i + 1);
+            // now copy the data
+            System.arraycopy(message, i * segmentLength, segments[i], UDHIE_HEADER_REAL_LENGTH, lengthOfData);
+        }
+
+        return segments;
+    }
+
+    protected boolean isSplitRequired() {
+        return getCurrentLength() > getMessageLength();
+    }
+
+    /**
+     * Gets maximum message length.
+     * 
+     * @return maximum message length
+     */
+    public int getMessageLength() {
+        return messageLength;
+    }
+
+    /**
+     * Gets maximum segment length.
+     * 
+     * @return maximum segment length
+     */
+    public int getSegmentLength() {
+        return segmentLength;
+    }
+
+    /**
+     * Gets length of the message to split.
+     * 
+     * @return length of the message to split
+     */
+    public int getCurrentLength() {
+        return currentLength;
+    }
+}
\ No newline at end of file