Author: davsclaus
Date: Thu Dec 10 07:30:17 2009
New Revision: 889123
URL: http://svn.apache.org/viewvc?rev=889123&view=rev
Log:
CAMEL-1921: Applied encoding patch. Thanks again Christian
Modified:
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java
Modified:
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java?rev=889123&r1=889122&r2=889123&view=diff
==============================================================================
---
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
(original)
+++
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppBinding.java
Thu Dec 10 07:30:17 2009
@@ -85,7 +85,7 @@
Message in = exchange.getIn();
SubmitSm submitSm = new SubmitSm();
-
submitSm.setShortMessage(exchange.getIn().getBody(String.class).getBytes("ISO-8859-1"));
+
submitSm.setShortMessage(exchange.getIn().getBody(String.class).getBytes(configuration.getEncoding()));
if (in.getHeaders().containsKey(DEST_ADDR)) {
submitSm.setDestAddress((String) in.getHeader(DEST_ADDR));
@@ -170,7 +170,7 @@
* Create a new SmppMessage from the inbound alert notification
*/
public SmppMessage createSmppMessage(AlertNotification alertNotification) {
- SmppMessage smppMessage = new SmppMessage(alertNotification);
+ SmppMessage smppMessage = new SmppMessage(alertNotification,
configuration);
smppMessage.setHeader(SEQUENCE_NUMBER,
alertNotification.getSequenceNumber());
smppMessage.setHeader(COMMAND_ID, alertNotification.getCommandId());
@@ -189,7 +189,7 @@
* Create a new SmppMessage from the inbound deliver sm or deliver receipt
*/
public SmppMessage createSmppMessage(DeliverSm deliverSm) throws Exception
{
- SmppMessage smppMessage = new SmppMessage(deliverSm);
+ SmppMessage smppMessage = new SmppMessage(deliverSm, configuration);
if (deliverSm.isSmscDeliveryReceipt()) {
DeliveryReceipt smscDeliveryReceipt =
deliverSm.getShortMessageAsDeliveryReceipt();
Modified:
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java?rev=889123&r1=889122&r2=889123&view=diff
==============================================================================
---
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
(original)
+++
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppEndpoint.java
Thu Dec 10 07:30:17 2009
@@ -23,8 +23,6 @@
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.jsmpp.bean.AlertNotification;
import org.jsmpp.bean.DeliverSm;
@@ -36,8 +34,6 @@
*/
public class SmppEndpoint extends DefaultEndpoint {
- private static final transient Log LOG =
LogFactory.getLog(SmppEndpoint.class);
-
private SmppBinding binding;
private SmppConfiguration configuration;
Modified:
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java?rev=889123&r1=889122&r2=889123&view=diff
==============================================================================
---
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
(original)
+++
camel/trunk/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppMessage.java
Thu Dec 10 07:30:17 2009
@@ -33,21 +33,25 @@
public class SmppMessage extends DefaultMessage {
private Command command;
+ private SmppConfiguration configuration;
- public SmppMessage() {
+ public SmppMessage(SmppConfiguration configuration) {
+ this.configuration = configuration;
}
- public SmppMessage(AlertNotification command) {
+ public SmppMessage(AlertNotification command, SmppConfiguration
configuration) {
this.command = command;
+ this.configuration = configuration;
}
- public SmppMessage(DeliverSm command) {
+ public SmppMessage(DeliverSm command, SmppConfiguration configuration) {
this.command = command;
+ this.configuration = configuration;
}
@Override
public SmppMessage newInstance() {
- return new SmppMessage();
+ return new SmppMessage(this.configuration);
}
@Override
@@ -55,7 +59,7 @@
if (command instanceof MessageRequest) {
byte[] shortMessage = ((MessageRequest) command).getShortMessage();
try {
- return new String(shortMessage, "ISO-8859-1");
+ return new String(shortMessage, configuration.getEncoding());
} catch (UnsupportedEncodingException e) {
return new String(shortMessage);
}
Modified:
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java?rev=889123&r1=889122&r2=889123&view=diff
==============================================================================
---
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java
(original)
+++
camel/trunk/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppMessageTest.java
Thu Dec 10 07:30:17 2009
@@ -16,16 +16,15 @@
*/
package org.apache.camel.component.smpp;
-import org.jsmpp.bean.AlertNotification;
-import org.jsmpp.bean.DeliverSm;
-import org.junit.Before;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.jsmpp.bean.AlertNotification;
+import org.jsmpp.bean.DeliverSm;
+import org.junit.Test;
+
/**
* JUnit test class for
<code>org.apache.camel.component.smpp.SmppMessage</code>
*
@@ -36,13 +35,10 @@
private SmppMessage message;
- @Before
- public void setUp() {
- message = new SmppMessage();
- }
-
@Test
public void emptyConstructorShouldReturnAnInstanceWithoutACommand() {
+ message = new SmppMessage(new SmppConfiguration());
+
assertNull(message.getCommand());
assertTrue(message.getHeaders().isEmpty());
}
@@ -50,7 +46,7 @@
@Test
public void
alertNotificationConstructorShouldReturnAnInstanceWithACommandAndHeaderAttributes()
{
AlertNotification command = new AlertNotification();
- message = new SmppMessage(command);
+ message = new SmppMessage(command, new SmppConfiguration());
assertTrue(message.getCommand() instanceof AlertNotification);
assertTrue(message.getHeaders().isEmpty());
@@ -59,7 +55,7 @@
@Test
public void testSmppMessageDeliverSm() {
DeliverSm command = new DeliverSm();
- message = new SmppMessage(command);
+ message = new SmppMessage(command, new SmppConfiguration());
assertTrue(message.getCommand() instanceof DeliverSm);
assertTrue(message.getHeaders().isEmpty());
@@ -67,6 +63,7 @@
@Test
public void newInstanceShouldReturnAnInstanceWithoutACommand() {
+ message = new SmppMessage(new SmppConfiguration());
SmppMessage msg = message.newInstance();
assertNotNull(msg);
@@ -76,13 +73,15 @@
@Test
public void createBodyShouldReturnNullIfTheCommandIsNull() {
+ message = new SmppMessage(new SmppConfiguration());
+
assertNull(message.createBody());
}
@Test
public void createBodyShouldReturnNullIfTheCommandIsNotAMessageRequest() {
AlertNotification command = new AlertNotification();
- message = new SmppMessage(command);
+ message = new SmppMessage(command, new SmppConfiguration());
assertNull(message.createBody());
}
@@ -91,13 +90,15 @@
public void
createBodyShouldReturnTheShortMessageIfTheCommandIsAMessageRequest() {
DeliverSm command = new DeliverSm();
command.setShortMessage("Hello SMPP world!".getBytes());
- message = new SmppMessage(command);
+ message = new SmppMessage(command, new SmppConfiguration());
assertEquals("Hello SMPP world!", message.createBody());
}
@Test
public void toStringShouldReturnTheBodyIfTheCommandIsNull() {
+ message = new SmppMessage(new SmppConfiguration());
+
assertEquals("SmppMessage: null", message.toString());
}
@@ -105,7 +106,7 @@
public void toStringShouldReturnTheShortMessageIfTheCommandIsNotNull() {
DeliverSm command = new DeliverSm();
command.setShortMessage("Hello SMPP world!".getBytes());
- message = new SmppMessage(command);
+ message = new SmppMessage(command, new SmppConfiguration());
assertEquals("SmppMessage: PDUHeader(0, 00000000, 00000000, 0)",
message.toString());
}