You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/03 19:41:01 UTC

[2/6] camel git commit: SMPP: Add support for message splitting policies

SMPP: Add support for message splitting policies


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

Branch: refs/heads/master
Commit: b5a3518b553a613048adef4a93ad1d4f4d79ffd4
Parents: ea3e107
Author: Daniel Pocock <da...@pocock.pro>
Authored: Mon Nov 24 20:52:08 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 19:34:39 2014 +0100

----------------------------------------------------------------------
 .../camel/component/smpp/SmppConfiguration.java | 10 +++++
 .../camel/component/smpp/SmppConstants.java     |  3 +-
 .../camel/component/smpp/SmppSmCommand.java     | 38 ++++++++++++++++++-
 .../component/smpp/SmppSplittingPolicy.java     | 40 ++++++++++++++++++++
 .../component/smpp/SmppSubmitMultiCommand.java  |  5 +--
 .../component/smpp/SmppSubmitSmCommand.java     |  8 ++--
 6 files changed, 94 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b5a3518b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
index 5756025..7f9b63d 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConfiguration.java
@@ -70,6 +70,7 @@ public class SmppConfiguration implements Cloneable {
     private String httpProxyUsername;
     private String httpProxyPassword;
     private SessionStateListener sessionStateListener;
+    private SmppSplittingPolicy splittingPolicy = SmppSplittingPolicy.ALLOW;
 
     
     /**
@@ -361,6 +362,14 @@ public class SmppConfiguration implements Cloneable {
         this.addressRange = addressRange;
     }
 
+    public SmppSplittingPolicy getSplittingPolicy() {
+        return splittingPolicy;
+    }
+
+    public void setSplittingPolicy(SmppSplittingPolicy splittingPolicy) {
+        this.splittingPolicy = splittingPolicy;
+    }
+
     @Override
     public String toString() {
         return "SmppConfiguration[usingSSL=" + usingSSL 
@@ -395,6 +404,7 @@ public class SmppConfiguration implements Cloneable {
             + ", httpProxyPort=" + httpProxyPort
             + ", httpProxyUsername=" + httpProxyUsername
             + ", httpProxyPassword=" + httpProxyPassword
+            + ", splittingPolicy=" + splittingPolicy
             + "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b5a3518b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
index d469359..e2551f1 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConstants.java
@@ -59,7 +59,8 @@ public interface SmppConstants {
     String VALIDITY_PERIOD = "CamelSmppValidityPeriod";
     String OPTIONAL_PARAMETERS = "CamelSmppOptionalParameters";
     String OPTIONAL_PARAMETER = "CamelSmppOptionalParameter";
+    String SPLITTING_POLICY = "CamelSmppSplittingPolicy";
 
     String UCS2_ENCODING = "UTF-16BE";
     byte UNKNOWN_ALPHABET = -1;
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b5a3518b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
index f38a57d..c1ee661 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSmCommand.java
@@ -20,13 +20,15 @@ import java.nio.charset.Charset;
 
 import org.apache.camel.Message;
 import org.jsmpp.bean.Alphabet;
+import org.jsmpp.extra.NegativeResponseException;
 import org.jsmpp.session.SMPPSession;
 
 public abstract class SmppSmCommand extends AbstractSmppCommand {
 
+    public static final int SMPP_NEG_RESPONSE_MSG_TOO_LONG = 1;
+
     protected Charset ascii = Charset.forName("US-ASCII");
     protected Charset latin1 = Charset.forName("ISO-8859-1");
-
     protected Charset charset;
 
     public SmppSmCommand(SMPPSession session, SmppConfiguration config) {
@@ -34,6 +36,40 @@ public abstract class SmppSmCommand extends AbstractSmppCommand {
         this.charset = Charset.forName(config.getEncoding());
     }
 
+    protected byte[][] splitBody(Message message) throws SmppException {
+        byte[] shortMessage = getShortMessage(message);
+        SmppSplitter splitter = createSplitter(message);
+        byte[][] segments = splitter.split(shortMessage);
+        if(segments.length > 1) {
+            // Message body is split into multiple parts,
+            // check if this is permitted
+            SmppSplittingPolicy policy = getSplittingPolicy(message);
+            switch(policy) {
+            case ALLOW:
+                return segments;
+            case TRUNCATE:
+                return new byte[][] { segments[0] };
+            case REJECT:
+                // FIXME - JSMPP needs to have an enum of the negative response
+                // codes instead of just using them like this
+                NegativeResponseException nre = new NegativeResponseException(SMPP_NEG_RESPONSE_MSG_TOO_LONG);
+                throw new SmppException(nre);
+            default:
+                throw new SmppException("Unknown splitting policy: " + policy);
+            }
+        } else {
+            return segments;
+        }
+    }
+
+    private SmppSplittingPolicy getSplittingPolicy(Message message) throws SmppException {
+        if(message.getHeaders().containsKey(SmppConstants.SPLITTING_POLICY)) {
+            String policyName = message.getHeader(SmppConstants.SPLITTING_POLICY, String.class);
+            return SmppSplittingPolicy.fromString(policyName);
+        }
+        return config.getSplittingPolicy();
+    }
+
     protected SmppSplitter createSplitter(Message message) {
         Alphabet alphabet = determineAlphabet(message);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b5a3518b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplittingPolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplittingPolicy.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplittingPolicy.java
new file mode 100644
index 0000000..c2bcffe
--- /dev/null
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSplittingPolicy.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.smpp;
+
+public enum SmppSplittingPolicy {
+
+    ALLOW,
+    REJECT,
+    TRUNCATE;
+
+    public static SmppSplittingPolicy fromString(String policyName) throws SmppException {
+
+        if(policyName == null) {
+            throw new SmppException("policyName must not be null");
+        }
+
+        for (SmppSplittingPolicy nextPolicy : values()) {
+            if (nextPolicy.name().equals(policyName)) {
+                return nextPolicy;
+            }
+        }
+
+        throw new SmppException("Unrecognised SmppSplittingPolicy: " + policyName);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b5a3518b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
index d7e302a..3188ce4 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitMultiCommand.java
@@ -119,9 +119,8 @@ public class SmppSubmitMultiCommand extends SmppSmCommand {
         }
     }
 
-    protected SubmitMulti[] createSubmitMulti(Exchange exchange) {
-        SmppSplitter splitter = createSplitter(exchange.getIn());
-        byte[][] segments = splitter.split(getShortMessage(exchange.getIn()));
+    protected SubmitMulti[] createSubmitMulti(Exchange exchange) throws SmppException {
+        byte[][] segments = splitBody(exchange.getIn());
 
         ESMClass esmClass;
         // multipart message

http://git-wip-us.apache.org/repos/asf/camel/blob/b5a3518b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
index ac5f4f1..c02697a 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppSubmitSmCommand.java
@@ -90,12 +90,10 @@ public class SmppSubmitSmCommand extends SmppSmCommand {
         message.setHeader(SmppConstants.SENT_MESSAGE_COUNT, messageIDs.size());
     }
 
-    protected SubmitSm[] createSubmitSm(Exchange exchange) {
-        byte[] shortMessage = getShortMessage(exchange.getIn());
+    protected SubmitSm[] createSubmitSm(Exchange exchange) throws SmppException {
 
         SubmitSm template = createSubmitSmTemplate(exchange);
-        SmppSplitter splitter = createSplitter(exchange.getIn());
-        byte[][] segments = splitter.split(shortMessage);
+        byte[][] segments = splitBody(exchange.getIn());
 
         // multipart message
         if (segments.length > 1) {
@@ -222,4 +220,4 @@ public class SmppSubmitSmCommand extends SmppSmCommand {
 
         return submitSm;
     }
-}
\ No newline at end of file
+}