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/05/05 05:34:23 UTC
git commit: CAMEL-7225 camel-smpp - should check
Exchange.CHARSET_NAME header with thanks to Radsaggi
Repository: camel
Updated Branches:
refs/heads/master 2b1da7b86 -> 2b0513dfb
CAMEL-7225 camel-smpp - should check Exchange.CHARSET_NAME header with thanks to Radsaggi
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2b0513df
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2b0513df
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2b0513df
Branch: refs/heads/master
Commit: 2b0513dfb1cc3e0768f198762f4faae0a2c2d480
Parents: 2b1da7b
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon May 5 11:33:31 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon May 5 11:33:31 2014 +0800
----------------------------------------------------------------------
.../camel/component/smpp/SmppConfiguration.java | 8 +++++++
.../camel/component/smpp/SmppMessage.java | 24 ++++++++++++++------
2 files changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2b0513df/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 141283e..ec77a04 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
@@ -17,6 +17,7 @@
package org.apache.camel.component.smpp;
import java.net.URI;
+import java.nio.charset.Charset;
import org.apache.camel.RuntimeCamelException;
import org.jsmpp.bean.Alphabet;
@@ -25,6 +26,8 @@ import org.jsmpp.bean.ReplaceIfPresentFlag;
import org.jsmpp.bean.SMSCDeliveryReceipt;
import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.session.SessionStateListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Contains the SMPP component configuration properties</a>
@@ -32,6 +35,7 @@ import org.jsmpp.session.SessionStateListener;
* @version
*/
public class SmppConfiguration implements Cloneable {
+ private static final Logger LOG = LoggerFactory.getLogger(SmppConfiguration.class);
private String host = "localhost";
private Integer port = Integer.valueOf(2775);
@@ -67,6 +71,7 @@ public class SmppConfiguration implements Cloneable {
private String httpProxyPassword;
private SessionStateListener sessionStateListener;
+
/**
* A POJO which contains all necessary configuration parameters for the SMPP connection
*
@@ -138,6 +143,9 @@ public class SmppConfiguration implements Cloneable {
}
public void setEncoding(String encoding) {
+ if (!Charset.isSupported(encoding)) {
+ LOG.warn("Unsupported encoding \"{}\" is being set.", encoding);
+ }
this.encoding = encoding;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2b0513df/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
----------------------------------------------------------------------
diff --git a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
index 92c5c8d..3ffd445 100644
--- a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
+++ b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
@@ -20,21 +20,27 @@ import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import org.apache.camel.impl.DefaultMessage;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
import org.jsmpp.bean.AlertNotification;
import org.jsmpp.bean.Alphabet;
import org.jsmpp.bean.Command;
import org.jsmpp.bean.DataSm;
import org.jsmpp.bean.DeliverSm;
import org.jsmpp.bean.MessageRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Represents a {@link org.apache.camel.Message} for working with SMPP
*/
public class SmppMessage extends DefaultMessage {
-
+ private static final Logger LOG = LoggerFactory.getLogger(SmppMessage.class);
private Command command;
private SmppConfiguration configuration;
+
+
public SmppMessage(SmppConfiguration configuration) {
this.configuration = configuration;
}
@@ -85,12 +91,16 @@ public class SmppMessage extends DefaultMessage {
}
if (SmppUtils.parseAlphabetFromDataCoding(msgRequest.getDataCoding()) == Alphabet.ALPHA_8_BIT) {
return shortMessage;
- } else if (Charset.isSupported(configuration.getEncoding())) {
- try {
- return new String(shortMessage, configuration.getEncoding());
- } catch (UnsupportedEncodingException e) {
- // ignore
- }
+ }
+
+ String encoding = IOHelper.getCharsetName(getExchange(), false);
+ if (ObjectHelper.isEmpty(encoding) || !Charset.isSupported(encoding)) {
+ encoding = configuration.getEncoding();
+ }
+ try {
+ return new String(shortMessage, encoding);
+ } catch (UnsupportedEncodingException e) {
+ LOG.info("Unsupported encoding \"{}\". Using system default encoding.", encoding);
}
return new String(shortMessage);
}