You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/12/05 04:26:59 UTC

[5/6] camel git commit: CAMEL-8001: only try to use SmppUtils.isGsm0338Encodeable for content that can already be ISO-8859-1 encoded

CAMEL-8001: only try to use SmppUtils.isGsm0338Encodeable for content that can already be ISO-8859-1 encoded


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

Branch: refs/heads/camel-2.13.x
Commit: daacf791e04533ca091fd9c69cf122ad53ed73d2
Parents: 8a033a9
Author: Daniel Pocock <da...@pocock.pro>
Authored: Mon Nov 24 19:12:34 2014 +0100
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Dec 5 11:26:27 2014 +0800

----------------------------------------------------------------------
 .../camel/component/smpp/SmppSmCommand.java     | 21 +++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/daacf791/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 175ac9c..a9d8456 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
@@ -24,6 +24,9 @@ import org.jsmpp.session.SMPPSession;
 
 public abstract class SmppSmCommand extends AbstractSmppCommand {
 
+    protected Charset ascii = Charset.forName("US-ASCII");
+    protected Charset latin1 = Charset.forName("ISO-8859-1");
+
     protected Charset charset;
 
     public SmppSmCommand(SMPPSession session, SmppConfiguration config) {
@@ -100,11 +103,12 @@ public abstract class SmppSmCommand extends AbstractSmppCommand {
 
         Alphabet alphabetObj;
         if (alphabet == SmppConstants.UNKNOWN_ALPHABET) {
-            byte[] messageBytes = body.getBytes(charset);
-            if (SmppUtils.isGsm0338Encodeable(messageBytes)) {
-                alphabetObj = Alphabet.ALPHA_DEFAULT;
-            } else {
-                alphabetObj = Alphabet.ALPHA_UCS2;
+            alphabetObj = Alphabet.ALPHA_UCS2;
+            if(isLatin1Compatible(charset)) {
+                byte[] messageBytes = body.getBytes(charset);
+                if (SmppUtils.isGsm0338Encodeable(messageBytes)) {
+                    alphabetObj = Alphabet.ALPHA_DEFAULT;
+                }
             }
         } else {
             alphabetObj = Alphabet.valueOf(alphabet);
@@ -112,4 +116,11 @@ public abstract class SmppSmCommand extends AbstractSmppCommand {
 
         return alphabetObj;
     }
+
+    private boolean isLatin1Compatible(Charset c) {
+        if(c.equals(ascii) || c.equals(latin1)) {
+            return true;
+        }
+        return false;
+    }
 }