Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EA81211C2E for ; Mon, 5 May 2014 03:34:31 +0000 (UTC) Received: (qmail 55377 invoked by uid 500); 5 May 2014 03:34:31 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 55285 invoked by uid 500); 5 May 2014 03:34:28 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 55005 invoked by uid 99); 5 May 2014 03:34:24 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 May 2014 03:34:24 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8E9C690D4A4; Mon, 5 May 2014 03:34:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: CAMEL-7225 camel-smpp - should check Exchange.CHARSET_NAME header with thanks to Radsaggi Date: Mon, 5 May 2014 03:34:23 +0000 (UTC) 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 Authored: Mon May 5 11:33:31 2014 +0800 Committer: Willem Jiang 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 @@ -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); }