camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1179457 [2/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/
Date Wed, 05 Oct 2011 21:55:48 GMT
Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,249 @@
+/**
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.bean.Address;
+import org.jsmpp.bean.Alphabet;
+import org.jsmpp.bean.DataCoding;
+import org.jsmpp.bean.ESMClass;
+import org.jsmpp.bean.GSMSpecificFeature;
+import org.jsmpp.bean.GeneralDataCoding;
+import org.jsmpp.bean.MessageClass;
+import org.jsmpp.bean.MessageMode;
+import org.jsmpp.bean.MessageType;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.OptionalParameter;
+import org.jsmpp.bean.RegisteredDelivery;
+import org.jsmpp.bean.ReplaceIfPresentFlag;
+import org.jsmpp.bean.SubmitMulti;
+import org.jsmpp.bean.SubmitMultiResult;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.bean.UnsuccessDelivery;
+import org.jsmpp.session.SMPPSession;
+
+public class SmppSubmitMultiCommand extends SmppSmCommand {
+
+    public SmppSubmitMultiCommand(SMPPSession session, SmppConfiguration config) {
+        super(session, config);
+    }
+
+    @Override
+    public void execute(Exchange exchange) throws SmppException {
+        SubmitMulti[] submitMulties = createSubmitMulti(exchange);
+        List<SubmitMultiResult> results = new ArrayList<SubmitMultiResult>(submitMulties.length);
+        
+        for (int i = 0; i < submitMulties.length; i++) {
+            SubmitMulti submitMulti = submitMulties[i];
+            SubmitMultiResult result;
+            log.debug("Sending multiple short messages for exchange id '{}'...", exchange.getExchangeId());
+            
+            try {
+                result = session.submitMultiple(
+                        submitMulti.getServiceType(),
+                        TypeOfNumber.valueOf(submitMulti.getSourceAddrTon()),
+                        NumberingPlanIndicator.valueOf(submitMulti.getSourceAddrNpi()),
+                        submitMulti.getSourceAddr(),
+                        (Address[]) submitMulti.getDestAddresses(),
+                        new ESMClass(submitMulti.getEsmClass()),
+                        submitMulti.getProtocolId(),
+                        submitMulti.getPriorityFlag(),
+                        submitMulti.getScheduleDeliveryTime(),
+                        submitMulti.getValidityPeriod(),
+                        new RegisteredDelivery(submitMulti.getRegisteredDelivery()),
+                        new ReplaceIfPresentFlag(submitMulti.getReplaceIfPresentFlag()),
+                        new GeneralDataCoding(submitMulti.getDataCoding()),
+                        submitMulti.getSmDefaultMsgId(),
+                        submitMulti.getShortMessage(),
+                        new OptionalParameter[0]);
+                results.add(result);
+            } catch (Exception e) {
+                throw new SmppException(e);
+            }
+        }
+
+        log.debug("Sent multiple short messages for exchange id '{}' and received results '{}'", exchange.getExchangeId(), results);
+
+        List<String> messageIDs = new ArrayList<String>(results.size());
+        // {messageID : [{destAddr : address, error : errorCode}]}
+        Map<String, List<Map<String, Object>>> errors = new HashMap<String, List<Map<String, Object>>>();
+        
+        for (SubmitMultiResult result : results) {
+            UnsuccessDelivery[] deliveries = result.getUnsuccessDeliveries();
+            
+            if (deliveries != null) {
+                List<Map<String, Object>> undelivered = new ArrayList<Map<String, Object>>();
+                
+                for (UnsuccessDelivery delivery : deliveries) {
+                    Map<String, Object> error = new HashMap<String, Object>();
+                    error.put(SmppConstants.DEST_ADDR, delivery.getDestinationAddress().getAddress());
+                    error.put(SmppConstants.ERROR, delivery.getErrorStatusCode());
+                    undelivered.add(error);
+                }
+                
+                if (!undelivered.isEmpty()) {
+                    errors.put(result.getMessageId(), undelivered);
+                }
+            }
+
+            messageIDs.add(result.getMessageId());
+        }
+
+        Message message = getResponseMessage(exchange);
+        message.setHeader(SmppConstants.ID, messageIDs);
+        message.setHeader(SmppConstants.SENT_MESSAGE_COUNT, messageIDs.size());
+        if (!errors.isEmpty()) {
+            message.setHeader(SmppConstants.ERROR, errors);
+        }
+    }
+
+    protected SubmitMulti[] createSubmitMulti(Exchange exchange) {
+        String body = exchange.getIn().getBody(String.class);
+
+        byte providedAlphabet = getProvidedAlphabet(exchange);
+        Alphabet determinedAlphabet = determineAlphabet(exchange);
+        SmppSplitter splitter = createSplitter(exchange);
+        Charset charset = determineCharset(providedAlphabet, determinedAlphabet.value());
+
+        byte[][] segments = splitter.split(body.getBytes(charset));
+
+        DataCoding dataCoding = new GeneralDataCoding(false, true, MessageClass.CLASS1, determinedAlphabet);
+        ESMClass esmClass;
+
+        // multipart message
+        if (segments.length > 1) {
+            esmClass = new ESMClass(MessageMode.DEFAULT, MessageType.DEFAULT, GSMSpecificFeature.UDHI);
+        } else {
+            esmClass = new ESMClass();
+        }
+
+        SubmitMulti template = createSubmitMultiTemplate(exchange);
+        SubmitMulti[] submitMulties = new SubmitMulti[segments.length];
+        
+        for (int i = 0; i < segments.length; i++) {
+            SubmitMulti submitMulti = SmppUtils.copySubmitMulti(template);
+            submitMulti.setEsmClass(esmClass.value());
+            submitMulti.setDataCoding(dataCoding.value());
+            submitMulti.setShortMessage(segments[i]);
+            submitMulties[i] = submitMulti;
+        }
+
+        return submitMulties;
+    }
+
+    @SuppressWarnings("unchecked")
+    protected SubmitMulti createSubmitMultiTemplate(Exchange exchange) {
+        Message in = exchange.getIn();
+        SubmitMulti submitMulti = new SubmitMulti();
+
+        byte destAddrTon;
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_TON)) {
+            destAddrTon = in.getHeader(SmppConstants.DEST_ADDR_TON, Byte.class);
+        } else {
+            destAddrTon = config.getDestAddrTon();
+        }
+
+        byte destAddrNpi;
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_NPI)) {
+            destAddrNpi = in.getHeader(SmppConstants.DEST_ADDR_NPI, Byte.class);
+        } else {
+            destAddrNpi = config.getDestAddrNpi();
+        }
+
+        List<String> destAddresses;
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR)) {
+            destAddresses = in.getHeader(SmppConstants.DEST_ADDR, List.class);
+        } else {
+            destAddresses = Arrays.asList(config.getDestAddr());
+        }
+
+        Address[] addresses = new Address[destAddresses.size()];
+        int addrNum = 0;
+        for (String destAddr : destAddresses) {
+            Address addr = new Address(destAddrTon, destAddrNpi, destAddr);
+            addresses[addrNum++] = addr;
+        }
+        submitMulti.setDestAddresses(addresses);
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
+            submitMulti.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
+        } else {
+            submitMulti.setSourceAddr(config.getSourceAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
+            submitMulti.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
+        } else {
+            submitMulti.setSourceAddrTon(config.getSourceAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
+            submitMulti.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
+        } else {
+            submitMulti.setSourceAddrNpi(config.getSourceAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SERVICE_TYPE)) {
+            submitMulti.setServiceType(in.getHeader(SmppConstants.SERVICE_TYPE, String.class));
+        } else {
+            submitMulti.setServiceType(config.getServiceType());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
+            submitMulti.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, Byte.class));
+        } else {
+            submitMulti.setRegisteredDelivery(config.getRegisteredDelivery());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.PROTOCOL_ID)) {
+            submitMulti.setProtocolId(in.getHeader(SmppConstants.PROTOCOL_ID, Byte.class));
+        } else {
+            submitMulti.setProtocolId(config.getProtocolId());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.PRIORITY_FLAG)) {
+            submitMulti.setPriorityFlag(in.getHeader(SmppConstants.PRIORITY_FLAG, Byte.class));
+        } else {
+            submitMulti.setPriorityFlag(config.getPriorityFlag());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SCHEDULE_DELIVERY_TIME)) {
+            submitMulti.setScheduleDeliveryTime(SmppUtils.formatTime(in.getHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, Date.class)));
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
+            submitMulti.setValidityPeriod(SmppUtils.formatTime(in.getHeader(SmppConstants.VALIDITY_PERIOD, Date.class)));
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.REPLACE_IF_PRESENT_FLAG)) {
+            submitMulti.setReplaceIfPresentFlag(in.getHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, Byte.class));
+        } else {
+            submitMulti.setReplaceIfPresentFlag(config.getReplaceIfPresentFlag());
+        }
+
+        return submitMulti;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,201 @@
+/**
+ * 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.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.jsmpp.bean.Alphabet;
+import org.jsmpp.bean.ESMClass;
+import org.jsmpp.bean.GSMSpecificFeature;
+import org.jsmpp.bean.GeneralDataCoding;
+import org.jsmpp.bean.MessageClass;
+import org.jsmpp.bean.MessageMode;
+import org.jsmpp.bean.MessageType;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.RegisteredDelivery;
+import org.jsmpp.bean.SubmitSm;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.SMPPSession;
+
+public class SmppSubmitSmCommand extends SmppSmCommand {
+
+    public SmppSubmitSmCommand(SMPPSession session, SmppConfiguration config) {
+        super(session, config);
+    }
+
+    @Override
+    public void execute(Exchange exchange) throws SmppException {
+        SubmitSm[] submitSms = createSubmitSm(exchange);
+        List<String> messageIDs = new ArrayList<String>(submitSms.length);
+        
+        for (int i = 0; i < submitSms.length; i++) {
+            SubmitSm submitSm = submitSms[i];
+            String messageID;
+            log.debug("Sending short message {} for exchange id '{}'...", i, exchange.getExchangeId());
+            
+            try {
+                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.getEsmClass()),
+                        submitSm.getProtocolId(),
+                        submitSm.getPriorityFlag(),
+                        submitSm.getScheduleDeliveryTime(),
+                        submitSm.getValidityPeriod(),
+                        new RegisteredDelivery(submitSm.getRegisteredDelivery()),
+                        submitSm.getReplaceIfPresent(),
+                        new GeneralDataCoding(submitSm.getDataCoding()),
+                        (byte) 0,
+                        submitSm.getShortMessage(),
+                        submitSm.getOptionalParametes());
+            } catch (Exception e) {
+                throw new SmppException(e);
+            }
+            
+            messageIDs.add(messageID);
+        }
+
+        log.debug("Sent short message for exchange id '{}' and received message ids '{}'",
+                exchange.getExchangeId(), messageIDs);
+
+        Message message = getResponseMessage(exchange);
+        message.setHeader(SmppConstants.ID, messageIDs);
+        message.setHeader(SmppConstants.SENT_MESSAGE_COUNT, messageIDs.size());
+    }
+
+    protected SubmitSm[] createSubmitSm(Exchange exchange) {
+        String body = exchange.getIn().getBody(String.class);
+
+        byte providedAlphabet = getProvidedAlphabet(exchange);
+        Alphabet determinedAlphabet = determineAlphabet(exchange);
+        Charset charset = determineCharset(providedAlphabet, determinedAlphabet.value());
+        byte[] shortMessage = body.getBytes(charset);
+        
+        SubmitSm template = createSubmitSmTemplate(exchange);
+        SmppSplitter splitter = createSplitter(exchange);
+        byte[][] segments = splitter.split(shortMessage);
+
+        template.setDataCoding(new GeneralDataCoding(false, true, MessageClass.CLASS1, determinedAlphabet).value());
+        
+        // multipart message
+        if (segments.length > 1) {
+            template.setEsmClass(new ESMClass(MessageMode.DEFAULT, MessageType.DEFAULT, GSMSpecificFeature.UDHI).value());
+        }
+
+        SubmitSm[] submitSms = new SubmitSm[segments.length];
+        for (int i = 0; i < segments.length; i++) {
+            SubmitSm submitSm = SmppUtils.copySubmitSm(template);
+            submitSm.setShortMessage(segments[i]);
+            submitSms[i] = submitSm;
+        }
+
+        return submitSms;
+    }
+
+    protected SubmitSm createSubmitSmTemplate(Exchange exchange) {
+        Message in = exchange.getIn();
+        SubmitSm submitSm = new SubmitSm();
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR)) {
+            submitSm.setDestAddress(in.getHeader(SmppConstants.DEST_ADDR, String.class));
+        } else {
+            submitSm.setDestAddress(config.getDestAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_TON)) {
+            submitSm.setDestAddrTon(in.getHeader(SmppConstants.DEST_ADDR_TON, Byte.class));
+        } else {
+            submitSm.setDestAddrTon(config.getDestAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_NPI)) {
+            submitSm.setDestAddrNpi(in.getHeader(SmppConstants.DEST_ADDR_NPI, Byte.class));
+        } else {
+            submitSm.setDestAddrNpi(config.getDestAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
+            submitSm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
+        } else {
+            submitSm.setSourceAddr(config.getSourceAddr());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
+            submitSm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
+        } else {
+            submitSm.setSourceAddrTon(config.getSourceAddrTon());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
+            submitSm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
+        } else {
+            submitSm.setSourceAddrNpi(config.getSourceAddrNpi());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SERVICE_TYPE)) {
+            submitSm.setServiceType(in.getHeader(SmppConstants.SERVICE_TYPE, String.class));
+        } else {
+            submitSm.setServiceType(config.getServiceType());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
+            submitSm.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, Byte.class));
+        } else {
+            submitSm.setRegisteredDelivery(config.getRegisteredDelivery());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.PROTOCOL_ID)) {
+            submitSm.setProtocolId(in.getHeader(SmppConstants.PROTOCOL_ID, Byte.class));
+        } else {
+            submitSm.setProtocolId(config.getProtocolId());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.PRIORITY_FLAG)) {
+            submitSm.setPriorityFlag(in.getHeader(SmppConstants.PRIORITY_FLAG, Byte.class));
+        } else {
+            submitSm.setPriorityFlag(config.getPriorityFlag());
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.SCHEDULE_DELIVERY_TIME)) {
+            submitSm.setScheduleDeliveryTime(SmppUtils.formatTime(in.getHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, Date.class)));
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
+            submitSm.setValidityPeriod(SmppUtils.formatTime(in.getHeader(SmppConstants.VALIDITY_PERIOD, Date.class)));
+        }
+
+        if (in.getHeaders().containsKey(SmppConstants.REPLACE_IF_PRESENT_FLAG)) {
+            submitSm.setReplaceIfPresent(in.getHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, Byte.class));
+        } else {
+            submitSm.setReplaceIfPresent(config.getReplaceIfPresentFlag());
+        }
+        
+        submitSm.setEsmClass(new ESMClass().value());
+
+        return submitSm;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUcs2Splitter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUcs2Splitter.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUcs2Splitter.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUcs2Splitter.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,35 @@
+/**
+ * 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 SmppUcs2Splitter extends SmppSplitter {
+
+    /**
+     * The maximum length in chars of the unicode messages.
+     * <p/>
+     * Each letter requires 2 bytes.
+     */
+    public static final int MAX_MSG_CHAR_SIZE = MAX_MSG_BYTE_LENGTH / 2;
+
+    // ( / 2 * 2) is required because UDHIE_HEADER_REAL_LENGTH might be equal to 0x07 so the length of the segment
+    // is 133 = (70 * 2 - 7)and the last letter in the unicode will be damaged.
+    public static final int MAX_SEG_BYTE_SIZE = (MAX_MSG_CHAR_SIZE * 2 - UDHIE_HEADER_REAL_LENGTH) / 2 * 2;
+
+    public SmppUcs2Splitter(int segmentLength) {
+        super(MAX_MSG_CHAR_SIZE, MAX_SEG_BYTE_SIZE, segmentLength);
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUtils.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUtils.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUtils.java (added)
+++ camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppUtils.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,262 @@
+/**
+ * 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.util.Calendar;
+import java.util.Date;
+
+import org.jsmpp.bean.Alphabet;
+import org.jsmpp.bean.DataSm;
+import org.jsmpp.bean.SubmitMulti;
+import org.jsmpp.bean.SubmitSm;
+import org.jsmpp.util.AbsoluteTimeFormatter;
+import org.jsmpp.util.TimeFormatter;
+
+public final class SmppUtils {
+
+    /**
+     * See http://unicode.org/Public/MAPPINGS/ETSI/GSM0338.TXT
+     */
+    public static final short[] ISO_GSM_0338 = {
+        64,     163,    36,     165,    232,    233,    249,    236,
+        242,    199,    10,     216,    248,    13,     197,    229,
+        0,      95,     0,      0,      0,      0,      0,      0,
+        0,      0,      0,      0,      198,    230,    223,    201,
+        32,     33,     34,     35,     164,    37,     38,     39,
+        40,     41,     42,     43,     44,     45,     46,     47,
+        48,     49,     50,     51,     52,     53,     54,     55,
+        56,     57,     58,     59,     60,     61,     62,     63,
+        161,    65,     66,     67,     68,     69,     70,     71,
+        72,     73,     74,     75,     76,     77,     78,     79,
+        80,     81,     82,     83,     84,     85,     86,     87,
+        88,     89,     90,     196,    214,    209,    220,    167,
+        191,    97,     98,     99,     100,    101,    102,    103,
+        104,    105,    106,    107,    108,    109,    110,    111,
+        112,    113,    114,    115,    116,    117,    118,    119,
+        120,    121,    122,    228,    246,    241,    252,    224
+    };
+
+    /**
+     * See http://unicode.org/Public/MAPPINGS/ETSI/GSM0338.TXT
+     */
+    public static final short[][] ISO_GSM_0338_EXT = {
+        {10, 12},   {20, 94},   {40, 123},  {41, 125},  {47, 92},
+        {60, 91},   {61, 126},  {62, 93},   {64, 124},  {101, 164}
+    };
+    
+    private static final TimeFormatter TIME_FORMATTER = new AbsoluteTimeFormatter();
+
+    private SmppUtils() {
+    }
+    
+    public static String formatTime(Date date) {
+        return TIME_FORMATTER.format(date);
+    }
+
+    /**
+     * YYMMDDhhmmSS where:
+     * <ul>
+     * <li>YY = last two digits of the year (00-99)</li>
+     * <li>MM = month (01-12)</li>
+     * <li>DD = day (01-31)</li>
+     * <li>hh = hour (00-23)</li>
+     * <li>mm = minute (00-59)</li>
+     * <li>SS = second (00-59)</li>
+     * </ul>
+     *
+     * Java format is (yyMMddHHmmSS).
+     *
+     * @param date in <tt>String</tt> format.
+     * @return
+     * @throws NumberFormatException if there is contains non number on
+     *         <code>date</code> parameter.
+     * @throws IndexOutOfBoundsException if the date length in <tt>String</tt>
+     *         format is less than 10.
+     */
+    public static Date string2Date(String date) {
+        if (date == null) {
+            return null;
+        }
+
+        int year = Integer.parseInt(date.substring(0, 2));
+        int month = Integer.parseInt(date.substring(2, 4));
+        int day = Integer.parseInt(date.substring(4, 6));
+        int hour = Integer.parseInt(date.substring(6, 8));
+        int minute = Integer.parseInt(date.substring(8, 10));
+        int second = Integer.parseInt(date.substring(10, 12));
+        Calendar cal = Calendar.getInstance();
+        cal.set(convertTwoDigitYear(year), month - 1, day, hour, minute, second);
+        cal.set(Calendar.MILLISECOND, 0);
+        return cal.getTime();
+    }
+
+    private static int convertTwoDigitYear(int year) {
+        if (year >= 0 && year <= 37) {
+            return 2000 + year;
+        } else if (year >= 38 && year <= 99) {
+            return 1900 + year;
+        } else {
+            // should never happen
+            return year;
+        }
+    }
+
+    public static Alphabet parseAlphabetFromDataCoding(byte dataCoding) {
+        return Alphabet.valueOf((byte) (dataCoding & Alphabet.MASK_ALPHABET));
+    }
+
+    public static boolean isGsm0338Encodeable(byte[] aMessage) {
+    outer:
+        for (int i = 0; i < aMessage.length; i++) {
+            for (int j = 0; j < ISO_GSM_0338.length; j++) {
+                if (ISO_GSM_0338[j] == aMessage[i]) {
+                    continue outer;
+                }
+            }
+            for (int j = 0; j < ISO_GSM_0338_EXT.length; j++) {
+                if (ISO_GSM_0338_EXT[j][1] == aMessage[i]) {
+                    continue outer;
+                }
+            }
+            return false;
+        }
+        return true;
+    }
+    
+    public static SubmitSm copySubmitSm(SubmitSm src) {
+        SubmitSm dest = new SubmitSm();
+        dest.setCommandId(src.getCommandId());
+        dest.setCommandLength(src.getCommandLength());
+        dest.setCommandStatus(src.getCommandStatus());
+        dest.setDataCoding(src.getDataCoding());
+        dest.setDestAddress(src.getDestAddress());
+        dest.setDestAddrNpi(src.getDestAddrNpi());
+        dest.setDestAddrTon(src.getDestAddrTon());
+        dest.setEsmClass(src.getEsmClass());
+        dest.setOptionalParametes(src.getOptionalParametes());
+        dest.setPriorityFlag(src.getPriorityFlag());
+        dest.setProtocolId(src.getProtocolId());
+        dest.setRegisteredDelivery(src.getRegisteredDelivery());
+        dest.setReplaceIfPresent(src.getReplaceIfPresent());
+        dest.setScheduleDeliveryTime(src.getScheduleDeliveryTime());
+        dest.setSequenceNumber(src.getSequenceNumber());
+        dest.setServiceType(src.getServiceType());
+        dest.setShortMessage(src.getShortMessage());
+        dest.setSmDefaultMsgId(src.getSmDefaultMsgId());
+        dest.setSourceAddr(src.getSourceAddr());
+        dest.setSourceAddrNpi(src.getSourceAddrNpi());
+        dest.setSourceAddrTon(src.getSourceAddrTon());
+        dest.setValidityPeriod(src.getValidityPeriod());
+        if (src.isDatagramMode()) {
+            dest.setDatagramMode();
+        }
+        if (src.isDefaultMessageType()) {
+            dest.setDefaultMessageType();
+        }
+        if (src.isDefaultMode()) {
+            dest.setDefaultMode();
+        }
+        if (src.isEsmeDeliveryAcknowledgement()) {
+            dest.setEsmeDelivertAcknowledgement();
+        }
+        if (src.isEsmeManualAcknowledgement()) {
+            dest.setEsmeManualAcknowledgement();
+        }
+        if (src.isForwardMode()) {
+            dest.setForwardMode();
+        }
+        if (src.isReplyPath()) {
+            dest.setReplyPath();
+        }
+        if (src.isSmscDelReceiptFailureRequested()) {
+            dest.setSmscDelReceiptFailureRequested();
+        }
+        if (src.isSmscDelReceiptNotRequested()) {
+            dest.setSmscDelReceiptNotRequested();
+        }
+        if (src.isSmscDelReceiptSuccessAndFailureRequested()) {
+            dest.setSmscDelReceiptSuccessAndFailureRequested();
+        }
+        if (src.isStoreAndForwardMode()) {
+            dest.setStoreAndForwardMode();
+        }
+        if (src.isUdhi()) {
+            dest.setUdhi();
+        }
+        if (src.isUdhiAndReplyPath()) {
+            dest.setUdhiAndReplyPath();
+        }
+        return dest;
+    }
+
+    public static SubmitMulti copySubmitMulti(SubmitMulti src) {
+        SubmitMulti dest = new SubmitMulti();
+        dest.setCommandId(src.getCommandId());
+        dest.setCommandLength(src.getCommandLength());
+        dest.setCommandStatus(src.getCommandStatus());
+        dest.setDataCoding(src.getDataCoding());
+        dest.setDestAddresses(src.getDestAddresses());
+        dest.setEsmClass(src.getEsmClass());
+        dest.setOptionalParameters(src.getOptionalParameters());
+        dest.setPriorityFlag(src.getPriorityFlag());
+        dest.setProtocolId(src.getProtocolId());
+        dest.setRegisteredDelivery(src.getRegisteredDelivery());
+        dest.setReplaceIfPresentFlag(src.getReplaceIfPresentFlag());
+        dest.setScheduleDeliveryTime(src.getScheduleDeliveryTime());
+        dest.setSequenceNumber(src.getSequenceNumber());
+        dest.setServiceType(src.getServiceType());
+        dest.setShortMessage(src.getShortMessage());
+        dest.setSmDefaultMsgId(src.getSmDefaultMsgId());
+        dest.setSourceAddr(src.getSourceAddr());
+        dest.setSourceAddrNpi(src.getSourceAddrNpi());
+        dest.setSourceAddrTon(src.getSourceAddrTon());
+        dest.setValidityPeriod(src.getValidityPeriod());
+        return dest;
+    }
+
+    public static DataSm copyDataSm(DataSm src) {
+        DataSm dest = new DataSm();
+        dest.setCommandId(src.getCommandId());
+        dest.setCommandLength(src.getCommandLength());
+        dest.setCommandStatus(src.getCommandStatus());
+        dest.setDataCoding(src.getDataCoding());
+        dest.setDestAddress(src.getDestAddress());
+        dest.setDestAddrNpi(src.getDestAddrNpi());
+        dest.setDestAddrTon(src.getDestAddrTon());
+        dest.setEsmClass(src.getEsmClass());
+        dest.setOptionalParametes(src.getOptionalParametes());
+        dest.setRegisteredDelivery(src.getRegisteredDelivery());
+        dest.setSequenceNumber(src.getSequenceNumber());
+        dest.setServiceType(src.getServiceType());
+        dest.setSourceAddr(src.getSourceAddr());
+        dest.setSourceAddrNpi(src.getSourceAddrNpi());
+        dest.setSourceAddrTon(src.getSourceAddrTon());
+        if (src.isDefaultMessageType()) {
+            dest.setDefaultMessageType();
+        }
+        if (src.isReplyPath()) {
+            dest.setReplyPath();
+        }
+        if (src.isUdhi()) {
+            dest.setUdhi();
+        }
+        if (src.isUdhiAndReplyPath()) {
+            dest.setUdhiAndReplyPath();
+        }
+        return dest;
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/AbstractSmppCommandTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/AbstractSmppCommandTest.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/AbstractSmppCommandTest.java (added)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/AbstractSmppCommandTest.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;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.jsmpp.session.SMPPSession;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+
+public class AbstractSmppCommandTest {
+    
+    private SMPPSession session = new SMPPSession();
+    private SmppConfiguration config = new SmppConfiguration();
+    private AbstractSmppCommand command;
+    
+    @Before
+    public void setUp() {
+        session = new SMPPSession();
+        config = new SmppConfiguration();
+        
+        command = new AbstractSmppCommand(session, config) {
+            @Override
+            public void execute(Exchange exchange) throws SmppException {
+            }
+        };
+    }
+    
+    @Test
+    public void constructor() {
+        assertSame(session, command.session);
+        assertSame(config, command.config);
+    }
+    
+    @Test
+    public void getResponseMessage() {
+        Exchange inOnlyExchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOnly);
+        Exchange inOutExchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
+        
+        assertSame(inOnlyExchange.getIn(), command.getResponseMessage(inOnlyExchange));
+        assertSame(inOutExchange.getOut(), command.getResponseMessage(inOutExchange));
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/Smpp8BitSplitterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/Smpp8BitSplitterTest.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/Smpp8BitSplitterTest.java (added)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/Smpp8BitSplitterTest.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,66 @@
+/**
+ * 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.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+public class Smpp8BitSplitterTest {
+
+    @Test
+    public void splitShortMessageWith160Character() {
+        String message = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
+                + "123456789012345678901234567890123456789012345678901234567890";
+
+        Smpp8BitSplitter splitter = new Smpp8BitSplitter(message.length());
+        Smpp8BitSplitter.resetCurrentReferenceNumber();
+        byte[][] result = splitter.split(message.getBytes());
+        
+        assertEquals(1, result.length);
+        assertArrayEquals(new byte[]{49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53,
+            54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48}, result[0]);
+
+        assertEquals(message, new String(result[0]));
+    }
+
+    @Test
+    public void splitShortMessageWith161Character() {
+        String message = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
+                + "12345678901234567890123456789012345678901234567890123456789012345678901";
+
+        Smpp8BitSplitter splitter = new Smpp8BitSplitter(message.length());
+        Smpp8BitSplitter.resetCurrentReferenceNumber();
+        byte[][] result = splitter.split(message.getBytes());
+        
+        assertEquals(2, result.length);
+        assertArrayEquals(new byte[]{SmppSplitter.UDHIE_HEADER_LENGTH, SmppSplitter.UDHIE_IDENTIFIER_SAR, SmppSplitter.UDHIE_SAR_LENGTH, 1, 2, 1, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51,
+            52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56,
+            57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51,
+            52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52}, result[0]);
+        assertArrayEquals(new byte[]{SmppSplitter.UDHIE_HEADER_LENGTH, SmppSplitter.UDHIE_IDENTIFIER_SAR, SmppSplitter.UDHIE_SAR_LENGTH, 1, 2, 2, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54,
+            55, 56, 57, 48, 49}, result[1]);
+
+        String firstShortMessage = new String(result[0], SmppSplitter.UDHIE_HEADER_REAL_LENGTH, result[0].length - SmppSplitter.UDHIE_HEADER_REAL_LENGTH);
+        String secondShortMessage = new String(result[1], SmppSplitter.UDHIE_HEADER_REAL_LENGTH, result[1].length - SmppSplitter.UDHIE_HEADER_REAL_LENGTH);
+
+        assertEquals(message, firstShortMessage + secondShortMessage);
+    }
+}
\ No newline at end of file

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=1179457&r1=1179456&r2=1179457&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 Wed Oct  5 21:55:46 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.smpp;
 
-import java.io.UnsupportedEncodingException;
 import java.util.Date;
 
 import org.apache.camel.Exchange;
@@ -28,17 +27,17 @@ import org.jsmpp.bean.DeliverSm;
 import org.jsmpp.bean.NumberingPlanIndicator;
 import org.jsmpp.bean.OptionalParameter;
 import org.jsmpp.bean.OptionalParameter.OctetString;
-import org.jsmpp.bean.SubmitSm;
 import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.SMPPSession;
 import org.jsmpp.util.DeliveryReceiptState;
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
 /**
  * JUnit test class for <code>org.apache.camel.component.smpp.SmppBinding</code>
@@ -72,109 +71,6 @@ public class SmppBindingTest {
     }
 
     @Test
-    public void createSubmitSmShouldCreateASubmitSmFromDefaults() throws UnsupportedEncodingException {
-        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
-        exchange.getIn().setBody("Hello SMPP world!");
-        SubmitSm submitSm = binding.createSubmitSm(exchange);
-        
-        assertEquals("Hello SMPP world!", new String(submitSm.getShortMessage()));
-        assertEquals("1717", submitSm.getDestAddress());
-        assertEquals(0x00, submitSm.getDestAddrNpi());
-        assertEquals(0x00, submitSm.getDestAddrTon());
-        assertEquals(0x01, submitSm.getPriorityFlag());
-        assertEquals(0x00, submitSm.getProtocolId());
-        assertEquals(0x01, submitSm.getRegisteredDelivery());
-        assertEquals(0x00, submitSm.getReplaceIfPresent());
-        // To avoid the test failure when running in different TimeZone
-        //assertEquals("090830230627004+", submitSm.getScheduleDeliveryTime());
-        assertEquals("CMT", submitSm.getServiceType());
-        assertEquals("1616", submitSm.getSourceAddr());
-        assertEquals(0x00, submitSm.getSourceAddrNpi());
-        assertEquals(0x00, submitSm.getSourceAddrTon());
-        assertNull(submitSm.getValidityPeriod());
-        // not relevant
-        //assertEquals(0, submitSm.getCommandId());
-        //assertEquals(0, submitSm.getCommandStatus());
-        //assertEquals(0, submitSm.getSequenceNumber());
-    }
-
-    @Test
-    public void createSubmitSmWithDifferentEncoding() throws UnsupportedEncodingException {
-        binding.getConfiguration().setEncoding("UTF-16");
-        
-        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
-        exchange.getIn().setBody("Hello SMPP world!");
-        SubmitSm submitSm = binding.createSubmitSm(exchange);
-
-        assertArrayEquals("Hello SMPP world!".getBytes("UTF-16"), submitSm.getShortMessage());
-    }
-
-    @Test
-    public void createSubmitSmShouldCreateASubmitSmFromHeaders() throws UnsupportedEncodingException {
-        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
-        exchange.getIn().setBody("Hello SMPP world!");
-        exchange.getIn().setHeader(SmppBinding.DEST_ADDR, "1919");
-        exchange.getIn().setHeader(SmppBinding.DEST_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
-        exchange.getIn().setHeader(SmppBinding.DEST_ADDR_TON, TypeOfNumber.NATIONAL.value());
-        exchange.getIn().setHeader(SmppBinding.PRIORITY_FLAG, (byte) 0);
-        exchange.getIn().setHeader(SmppBinding.PROTOCOL_ID, (byte) 1);
-        exchange.getIn().setHeader(SmppBinding.REGISTERED_DELIVERY, (byte) 0);
-        exchange.getIn().setHeader(SmppBinding.REPLACE_IF_PRESENT_FLAG, (byte) 1);
-        exchange.getIn().setHeader(SmppBinding.SCHEDULE_DELIVERY_TIME, new Date(1251753000000L));
-        exchange.getIn().setHeader(SmppBinding.SERVICE_TYPE, "XXX");
-        exchange.getIn().setHeader(SmppBinding.VALIDITY_PERIOD, new Date(1251753600000L));
-        exchange.getIn().setHeader(SmppBinding.SOURCE_ADDR, "1818");
-        exchange.getIn().setHeader(SmppBinding.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
-        exchange.getIn().setHeader(SmppBinding.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
-        SubmitSm submitSm = binding.createSubmitSm(exchange);
-        
-        assertEquals("Hello SMPP world!", new String(submitSm.getShortMessage()));
-        assertEquals("1919", submitSm.getDestAddress());
-        assertEquals(0x08, submitSm.getDestAddrNpi());
-        assertEquals(0x02, submitSm.getDestAddrTon());
-        assertEquals(0x00, submitSm.getPriorityFlag());
-        assertEquals(0x01, submitSm.getProtocolId());
-        assertEquals(0x00, submitSm.getRegisteredDelivery());
-        assertEquals(0x01, submitSm.getReplaceIfPresent());
-        // To avoid the test failure when running in different TimeZone
-        //assertEquals("090831231000004+", submitSm.getScheduleDeliveryTime());
-        assertEquals("XXX", submitSm.getServiceType());
-        assertEquals("1818", submitSm.getSourceAddr());
-        assertEquals(0x08, submitSm.getSourceAddrNpi());
-        assertEquals(0x02, submitSm.getSourceAddrTon());
-        //assertEquals("090831232000004+", submitSm.getValidityPeriod());
-        // not relevant
-        //assertEquals(0, submitSm.getCommandId());
-        //assertEquals(0, submitSm.getCommandStatus());
-        //assertEquals(0, submitSm.getSequenceNumber());
-    }
-    
-    @Test
-    public void createSubmitSmWithLongMessageBody() throws UnsupportedEncodingException {
-        String payload = "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "
-            + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "
-            + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "; // 270 chars
-        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
-        exchange.getIn().setBody(payload);
-        SubmitSm submitSm = binding.createSubmitSm(exchange);
-
-        assertArrayEquals(new byte[0], submitSm.getShortMessage());
-        
-        OptionalParameter[] optionalParametes = submitSm.getOptionalParametes();
-        assertEquals(1, optionalParametes.length);
-        
-        OptionalParameter messagePayloadTLV = optionalParametes[0];
-        assertEquals(OptionalParameter.Tag.MESSAGE_PAYLOAD.code(), messagePayloadTLV.tag);
-        byte[] expectedTLV = new byte[274];
-        expectedTLV[0] = 4;
-        expectedTLV[1] = 36;
-        expectedTLV[2] = 1;
-        expectedTLV[3] = 14;
-        System.arraycopy(payload.getBytes(), 0, expectedTLV, 4, 270);
-        assertArrayEquals(expectedTLV, messagePayloadTLV.serialize());
-    }
-
-    @Test
     public void createSmppMessageFromAlertNotificationShouldReturnASmppMessage() {
         AlertNotification alertNotification = new AlertNotification();
         alertNotification.setCommandId(1);
@@ -189,16 +85,16 @@ public class SmppBindingTest {
         
         assertNull(smppMessage.getBody());
         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));
-        assertEquals("1616", smppMessage.getHeader(SmppBinding.SOURCE_ADDR));
-        assertEquals((byte) 8, smppMessage.getHeader(SmppBinding.SOURCE_ADDR_NPI));
-        assertEquals((byte) 2, smppMessage.getHeader(SmppBinding.SOURCE_ADDR_TON));
-        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));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.SEQUENCE_NUMBER));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.COMMAND_ID));
+        assertEquals(0, smppMessage.getHeader(SmppConstants.COMMAND_STATUS));
+        assertEquals("1616", smppMessage.getHeader(SmppConstants.SOURCE_ADDR));
+        assertEquals((byte) 8, smppMessage.getHeader(SmppConstants.SOURCE_ADDR_NPI));
+        assertEquals((byte) 2, smppMessage.getHeader(SmppConstants.SOURCE_ADDR_TON));
+        assertEquals("1717", smppMessage.getHeader(SmppConstants.ESME_ADDR));
+        assertEquals((byte) 8, smppMessage.getHeader(SmppConstants.ESME_ADDR_NPI));
+        assertEquals((byte) 2, smppMessage.getHeader(SmppConstants.ESME_ADDR_TON));
+        assertEquals(SmppMessageType.AlertNotification.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
     }
 
     @Test
@@ -210,15 +106,15 @@ public class SmppBindingTest {
         
         assertEquals("Hello SMPP world!", smppMessage.getBody());
         assertEquals(8, smppMessage.getHeaders().size());
-        assertEquals("2", smppMessage.getHeader(SmppBinding.ID));
-        assertEquals(1, smppMessage.getHeader(SmppBinding.DELIVERED));
+        assertEquals("2", smppMessage.getHeader(SmppConstants.ID));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.DELIVERED));
         // To avoid the test failure when running in different TimeZone
-        //assertEquals(new Date(1251753060000L), smppMessage.getHeader(SmppBinding.DONE_DATE));
-        assertEquals("xxx", smppMessage.getHeader(SmppBinding.ERROR));
-        //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));
+        //assertEquals(new Date(1251753060000L), smppMessage.getHeader(SmppConstants.DONE_DATE));
+        assertEquals("xxx", smppMessage.getHeader(SmppConstants.ERROR));
+        //assertEquals(new Date(1251753000000L), smppMessage.getHeader(SmppConstants.SUBMIT_DATE));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.SUBMITTED));
+        assertEquals(DeliveryReceiptState.DELIVRD, smppMessage.getHeader(SmppConstants.FINAL_STATUS));
+        assertEquals(SmppMessageType.DeliveryReceipt.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
     }
     
     @Test
@@ -236,14 +132,14 @@ public class SmppBindingTest {
         
         assertEquals("Hello SMPP world!", smppMessage.getBody());
         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));
-        assertEquals("1919", smppMessage.getHeader(SmppBinding.DEST_ADDR));
-        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));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.SEQUENCE_NUMBER));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.COMMAND_ID));
+        assertEquals("1818", smppMessage.getHeader(SmppConstants.SOURCE_ADDR));
+        assertEquals("1919", smppMessage.getHeader(SmppConstants.DEST_ADDR));
+        assertEquals("090831230627004+", smppMessage.getHeader(SmppConstants.SCHEDULE_DELIVERY_TIME));
+        assertEquals("090901230627004+", smppMessage.getHeader(SmppConstants.VALIDITY_PERIOD));
+        assertEquals("WAP", smppMessage.getHeader(SmppConstants.SERVICE_TYPE));
+        assertEquals(SmppMessageType.DeliverSm.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
     }
     
     @Test
@@ -261,14 +157,14 @@ public class SmppBindingTest {
         
         assertEquals("Hello SMPP world!", smppMessage.getBody());
         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));
-        assertEquals("1919", smppMessage.getHeader(SmppBinding.DEST_ADDR));
-        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));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.SEQUENCE_NUMBER));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.COMMAND_ID));
+        assertEquals("1818", smppMessage.getHeader(SmppConstants.SOURCE_ADDR));
+        assertEquals("1919", smppMessage.getHeader(SmppConstants.DEST_ADDR));
+        assertEquals("090831230627004+", smppMessage.getHeader(SmppConstants.SCHEDULE_DELIVERY_TIME));
+        assertEquals("090901230627004+", smppMessage.getHeader(SmppConstants.VALIDITY_PERIOD));
+        assertEquals("WAP", smppMessage.getHeader(SmppConstants.SERVICE_TYPE));
+        assertEquals(SmppMessageType.DeliverSm.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
     }
     
     @Test
@@ -289,20 +185,20 @@ public class SmppBindingTest {
         
         assertNull(smppMessage.getBody());
         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));
-        assertEquals(0, smppMessage.getHeader(SmppBinding.COMMAND_STATUS));
-        assertEquals("1818", smppMessage.getHeader(SmppBinding.SOURCE_ADDR));
-        assertEquals((byte) 8, smppMessage.getHeader(SmppBinding.SOURCE_ADDR_NPI));
-        assertEquals((byte) 2, smppMessage.getHeader(SmppBinding.SOURCE_ADDR_TON));
-        assertEquals("1919", smppMessage.getHeader(SmppBinding.DEST_ADDR));
-        assertEquals((byte) 8, smppMessage.getHeader(SmppBinding.DEST_ADDR_NPI));
-        assertEquals((byte) 2, smppMessage.getHeader(SmppBinding.DEST_ADDR_TON));
-        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));
+        assertEquals("1", smppMessage.getHeader(SmppConstants.ID));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.SEQUENCE_NUMBER));
+        assertEquals(1, smppMessage.getHeader(SmppConstants.COMMAND_ID));
+        assertEquals(0, smppMessage.getHeader(SmppConstants.COMMAND_STATUS));
+        assertEquals("1818", smppMessage.getHeader(SmppConstants.SOURCE_ADDR));
+        assertEquals((byte) 8, smppMessage.getHeader(SmppConstants.SOURCE_ADDR_NPI));
+        assertEquals((byte) 2, smppMessage.getHeader(SmppConstants.SOURCE_ADDR_TON));
+        assertEquals("1919", smppMessage.getHeader(SmppConstants.DEST_ADDR));
+        assertEquals((byte) 8, smppMessage.getHeader(SmppConstants.DEST_ADDR_NPI));
+        assertEquals((byte) 2, smppMessage.getHeader(SmppConstants.DEST_ADDR_TON));
+        assertEquals("WAP", smppMessage.getHeader(SmppConstants.SERVICE_TYPE));
+        assertEquals((byte) 0, smppMessage.getHeader(SmppConstants.REGISTERED_DELIVERY));
+        assertEquals((byte) 0, smppMessage.getHeader(SmppConstants.DATA_CODING));
+        assertEquals(SmppMessageType.DataSm.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
     }
 
     @Test
@@ -312,4 +208,69 @@ public class SmppBindingTest {
         
         assertSame(configuration, binding.getConfiguration());
     }
+    
+    @Test
+    public void createSmppSubmitSmCommand() {
+        SMPPSession session = new SMPPSession();
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        
+        SmppCommand command = binding.createSmppCommand(session, exchange);
+        
+        assertTrue(command instanceof SmppSubmitSmCommand);
+    }
+    
+    @Test
+    public void createSmppSubmitMultiCommand() {
+        SMPPSession session = new SMPPSession();
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
+        
+        SmppCommand command = binding.createSmppCommand(session, exchange);
+        
+        assertTrue(command instanceof SmppSubmitMultiCommand);
+    }
+    
+    @Test
+    public void createSmppDataSmCommand() {
+        SMPPSession session = new SMPPSession();
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
+        
+        SmppCommand command = binding.createSmppCommand(session, exchange);
+        
+        assertTrue(command instanceof SmppDataSmCommand);
+    }
+    
+    @Test
+    public void createSmppReplaceSmCommand() {
+        SMPPSession session = new SMPPSession();
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "ReplaceSm");
+        
+        SmppCommand command = binding.createSmppCommand(session, exchange);
+        
+        assertTrue(command instanceof SmppReplaceSmCommand);
+    }
+    
+    @Test
+    public void createSmppQuerySmCommand() {
+        SMPPSession session = new SMPPSession();
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "QuerySm");
+        
+        SmppCommand command = binding.createSmppCommand(session, exchange);
+        
+        assertTrue(command instanceof SmppQuerySmCommand);
+    }
+    
+    @Test
+    public void createSmppCancelSmCommand() {
+        SMPPSession session = new SMPPSession();
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "CancelSm");
+        
+        SmppCommand command = binding.createSmppCommand(session, exchange);
+        
+        assertTrue(command instanceof SmppCancelSmCommand);
+    }
 }
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCancelSmCommandTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCancelSmCommandTest.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCancelSmCommandTest.java (added)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCancelSmCommandTest.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,86 @@
+/**
+ * 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.ExchangePattern;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.session.SMPPSession;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+public class SmppCancelSmCommandTest {
+
+    private SMPPSession session;
+    private SmppConfiguration config;
+    private SmppCancelSmCommand command;
+    
+    @Before
+    public void setUp() {
+        session = createMock(SMPPSession.class);
+        config = new SmppConfiguration();
+        
+        command = new SmppCancelSmCommand(session, config);
+    }
+    
+    @Test
+    public void executeWithConfigurationData() throws Exception {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "CancelSm");
+        exchange.getIn().setHeader(SmppConstants.ID, "1");
+        session.cancelShortMessage("CMT", "1", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1616", TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1717");
+        
+        replay(session);
+        
+        command.execute(exchange);
+        
+        verify(session);
+        
+        assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
+    }
+    
+    @Test
+    public void execute() throws Exception {
+        Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "CancelSm");
+        exchange.getIn().setHeader(SmppConstants.ID, "1");
+        exchange.getIn().setHeader(SmppConstants.SERVICE_TYPE, "XXX");
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
+        exchange.getIn().setHeader(SmppConstants.DEST_ADDR, "1919");
+        session.cancelShortMessage("XXX", "1", TypeOfNumber.NATIONAL, NumberingPlanIndicator.NATIONAL, "1818", TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.INTERNET, "1919");
+        
+        replay(session);
+        
+        command.execute(exchange);
+        
+        verify(session);
+        
+        assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
+    }
+}
\ No newline at end of file

Added: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCommandTypeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCommandTypeTest.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCommandTypeTest.java (added)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppCommandTypeTest.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,75 @@
+/**
+ * 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.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+
+public class SmppCommandTypeTest {
+    
+    private Exchange exchange;
+
+    @Before
+    public void setUp() {
+        exchange = new DefaultExchange(new DefaultCamelContext());
+    }
+
+    @Test
+    public void createSmppSubmitSmCommand() {
+        assertSame(SmppCommandType.SUBMIT_SM, SmppCommandType.fromExchange(exchange));
+    }
+    
+    @Test
+    public void createSmppSubmitMultiCommand() {
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
+        
+        assertSame(SmppCommandType.SUBMIT_MULTI, SmppCommandType.fromExchange(exchange));
+    }
+    
+    @Test
+    public void createSmppDataSmCommand() {
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
+        
+        assertSame(SmppCommandType.DATA_SHORT_MESSAGE, SmppCommandType.fromExchange(exchange));
+    }
+    
+    @Test
+    public void createSmppReplaceSmCommand() {
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "ReplaceSm");
+        
+        assertSame(SmppCommandType.REPLACE_SM, SmppCommandType.fromExchange(exchange));
+    }
+    
+    @Test
+    public void createSmppQuerySmCommand() {
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "QuerySm");
+        
+        assertSame(SmppCommandType.QUERY_SM, SmppCommandType.fromExchange(exchange));
+    }
+    
+    @Test
+    public void createSmppCancelSmCommand() {
+        exchange.getIn().setHeader(SmppConstants.COMMAND, "CancelSm");
+        
+        assertSame(SmppCommandType.CANCEL_SM, SmppCommandType.fromExchange(exchange));
+    }
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java?rev=1179457&r1=1179456&r2=1179457&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java (original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConfigurationTest.java Wed Oct  5 21:55:46 2011
@@ -150,7 +150,7 @@ public class SmppConfigurationTest {
                 + "port=2775, "
                 + "systemId=smppclient, "
                 + "systemType=cp, "
-                + "dataCoding=0, "
+                + "alphabet=0, "
                 + "encoding=ISO-8859-1, "
                 + "transactionTimer=10000, "
                 + "registeredDelivery=1, "

Added: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDefaultSplitterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDefaultSplitterTest.java?rev=1179457&view=auto
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDefaultSplitterTest.java (added)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppDefaultSplitterTest.java Wed Oct  5 21:55:46 2011
@@ -0,0 +1,67 @@
+/**
+ * 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.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+public class SmppDefaultSplitterTest {
+    
+    @Test
+    public void splitShortMessageWith160Character() {
+        String message = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
+                + "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
+
+        SmppDefaultSplitter splitter = new SmppDefaultSplitter(message.length());
+        SmppDefaultSplitter.resetCurrentReferenceNumber();
+        byte[][] result = splitter.split(message.getBytes());
+        
+        assertEquals(1, result.length);
+        assertArrayEquals(new byte[]{49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53,
+            54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
+            49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48}, result[0]);
+
+        assertEquals(message, new String(result[0]));
+    }
+
+    @Test
+    public void splitShortMessageWith161Character() {
+        String message = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
+                + "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901";
+
+        SmppDefaultSplitter splitter = new SmppDefaultSplitter(message.length());
+        SmppDefaultSplitter.resetCurrentReferenceNumber();
+        byte[][] result = splitter.split(message.getBytes());
+        
+        assertEquals(2, result.length);
+        assertArrayEquals(new byte[]{SmppSplitter.UDHIE_HEADER_LENGTH, SmppSplitter.UDHIE_IDENTIFIER_SAR, SmppSplitter.UDHIE_SAR_LENGTH, 1, 2, 1, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51,
+            52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56,
+            57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51,
+            52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56,
+            57, 48, 49, 50, 51}, result[0]);
+        assertArrayEquals(new byte[]{SmppSplitter.UDHIE_HEADER_LENGTH, SmppSplitter.UDHIE_IDENTIFIER_SAR, SmppSplitter.UDHIE_SAR_LENGTH, 1, 2, 2, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54,
+            55, 56, 57, 48, 49}, result[1]);
+
+        String firstShortMessage = new String(result[0], SmppSplitter.UDHIE_HEADER_REAL_LENGTH, result[0].length - SmppSplitter.UDHIE_HEADER_REAL_LENGTH);
+        String secondShortMessage = new String(result[1], SmppSplitter.UDHIE_HEADER_REAL_LENGTH, result[1].length - SmppSplitter.UDHIE_HEADER_REAL_LENGTH);
+
+        assertEquals(message, firstShortMessage + secondShortMessage);
+    }
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java?rev=1179457&r1=1179456&r2=1179457&view=diff
==============================================================================
--- camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java (original)
+++ camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerLazySessionCreationTest.java Wed Oct  5 21:55:46 2011
@@ -17,18 +17,8 @@
 package org.apache.camel.component.smpp;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Message;
-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.OptionalParameter;
-import org.jsmpp.bean.RegisteredDelivery;
-import org.jsmpp.bean.SMSCDeliveryReceipt;
-import org.jsmpp.bean.SubmitSm;
 import org.jsmpp.bean.TypeOfNumber;
 import org.jsmpp.session.BindParameter;
 import org.jsmpp.session.SMPPSession;
@@ -36,8 +26,6 @@ import org.jsmpp.session.SessionStateLis
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.easymock.EasyMock.aryEq;
-import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.isA;
 import static org.easymock.classextension.EasyMock.createMock;
@@ -70,26 +58,6 @@ public class SmppProducerLazySessionCrea
         };
     }
 
-    private void submitSmExpectations(Exchange exchange, SmppBinding binding, SubmitSm submitSm) throws Exception {
-        expect(submitSm.getServiceType()).andReturn("CMT");
-        expect(submitSm.getSourceAddrTon()).andReturn(TypeOfNumber.UNKNOWN.value());
-        expect(submitSm.getSourceAddrNpi()).andReturn(NumberingPlanIndicator.UNKNOWN.value());
-        expect(submitSm.getSourceAddr()).andReturn("1616");
-        expect(submitSm.getDestAddrTon()).andReturn(TypeOfNumber.UNKNOWN.value());
-        expect(submitSm.getDestAddrNpi()).andReturn(NumberingPlanIndicator.UNKNOWN.value());
-        expect(submitSm.getDestAddress()).andReturn("1717");
-        expect(submitSm.getProtocolId()).andReturn((byte) 0);
-        expect(submitSm.getPriorityFlag()).andReturn((byte) 1);
-        expect(submitSm.getScheduleDeliveryTime()).andReturn("090830230627004+");
-        expect(submitSm.getValidityPeriod()).andReturn("090831232000004+");
-        expect(submitSm.getRegisteredDelivery())
-            .andReturn(SMSCDeliveryReceipt.SUCCESS_FAILURE.value());
-        expect(submitSm.getReplaceIfPresent()).andReturn((byte) 0);
-        expect(submitSm.getDataCoding()).andReturn((byte) 0);
-        expect(submitSm.getShortMessage()).andReturn("Hello SMPP world!".getBytes("ISO-8859-1"));
-        expect(submitSm.getOptionalParametes()).andReturn(new OptionalParameter[]{});
-    }
-
     @Test
     public void doStartShouldNotCreateTheSmppSession() throws Exception {
         expect(endpoint.getConnectionString()).andReturn("smpp://smppclient@localhost:2775");
@@ -123,45 +91,16 @@ public class SmppProducerLazySessionCrea
         expect(endpoint.getConnectionString()).andReturn("smpp://smppclient@localhost:2775");
         SmppBinding binding = createMock(SmppBinding.class);
         Exchange exchange = createMock(Exchange.class);
-        Message message = createMock(Message.class);
-        SubmitSm submitSm = createMock(SubmitSm.class);
-        expect(exchange.getExchangeId()).andReturn("ID-muellerc-macbookpro/3690-1214458315718/2-0");
+        SmppCommand command = createMock(SmppCommand.class);
         expect(endpoint.getBinding()).andReturn(binding);
-        expect(binding.createSubmitSm(exchange)).andReturn(submitSm);
-        submitSmExpectations(exchange, binding, submitSm);
-        expect(session.submitShortMessage(
-                eq("CMT"),
-                eq(TypeOfNumber.UNKNOWN),
-                eq(NumberingPlanIndicator.UNKNOWN),
-                eq("1616"),
-                eq(TypeOfNumber.UNKNOWN),
-                eq(NumberingPlanIndicator.UNKNOWN),
-                eq("1717"),
-                isA(ESMClass.class),
-                eq((byte) 0),
-                eq((byte) 1),
-                eq("090830230627004+"),
-                eq("090831232000004+"),
-                eq(new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE)),
-                eq((byte) 0),
-                eq(new GeneralDataCoding(
-                        false,
-                        true,
-                        MessageClass.CLASS1,
-                        Alphabet.ALPHA_DEFAULT)),
-                eq((byte) 0),
-                aryEq("Hello SMPP world!".getBytes("ISO-8859-1"))))
-            .andReturn("1");
-        expect(exchange.getPattern()).andReturn(ExchangePattern.InOnly);
-        expect(exchange.getIn()).andReturn(message);
-        message.setHeader(SmppBinding.ID, "1"); // expectation without return value
-        expect(exchange.getExchangeId()).andReturn("ID-muellerc-macbookpro/3690-1214458315718/2-0");
+        expect(binding.createSmppCommand(session, exchange)).andReturn(command);
+        command.execute(exchange);
         
-        replay(session, endpoint, binding, exchange, message, submitSm);
+        replay(session, endpoint, binding, exchange, command);
         
         producer.doStart();
         producer.process(exchange);
         
-        verify(session, endpoint, binding, exchange, message, submitSm);
+        verify(session, endpoint, binding, exchange, command);
     }
 }
\ No newline at end of file



Mime
View raw message