You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by lh...@apache.org on 2009/02/01 19:46:45 UTC
svn commit: r739812 - in
/servicemix/components/bindings/servicemix-smpp/trunk/src:
main/java/org/apache/servicemix/smpp/
main/java/org/apache/servicemix/smpp/marshaler/
test/java/org/apache/servicemix/smpp/marshaler/
Author: lhein
Date: Sun Feb 1 18:46:45 2009
New Revision: 739812
URL: http://svn.apache.org/viewvc?rev=739812&view=rev
Log:
Applied patches from SM-1623 on behalf of Jean-Baptiste Onofré and Christian Mueller
Modified:
servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppConsumerEndpoint.java
servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppProviderEndpoint.java
servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshaler.java
servicemix/components/bindings/servicemix-smpp/trunk/src/test/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshalerTest.java
Modified: servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppConsumerEndpoint.java?rev=739812&r1=739811&r2=739812&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppConsumerEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppConsumerEndpoint.java Sun Feb 1 18:46:45 2009
@@ -28,7 +28,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.common.endpoints.ConsumerEndpoint;
-import org.apache.servicemix.smpp.marshaler.DefaultSmppMarshaler;
import org.apache.servicemix.smpp.marshaler.SmppMarshalerSupport;
import org.jsmpp.bean.AlertNotification;
import org.jsmpp.bean.BindType;
@@ -65,6 +64,8 @@
private int port;
private String systemId;
private String password;
+ private int enquireLinkTimer = 50000;
+ private int transactionTimer = 100000;
private SmppMarshalerSupport marshaler;
@@ -111,11 +112,21 @@
if (this.systemId == null || this.systemId.trim().length() <= 0) {
throw new IllegalArgumentException("The SMPP system ID is mandatory.");
}
+ // check the enquireLinkTimer
+ if (this.enquireLinkTimer <= 0) {
+ throw new IllegalArgumentException("The enquireLinkTimer value must be greater than 0.");
+ }
+ // check the transactionTimer
+ if (this.transactionTimer <= 0) {
+ throw new IllegalArgumentException("The transactionTimer value must be greater than 0.");
+ }
}
/*
* (non-Javadoc)
- * @see org.apache.servicemix.common.endpoints.AbstractEndpoint#process(javax.jbi.messaging.MessageExchange)
+ * @see
+ * org.apache.servicemix.common.endpoints.AbstractEndpoint#process(javax
+ * .jbi.messaging.MessageExchange)
*/
@Override
public void process(MessageExchange exchange) throws Exception {
@@ -123,7 +134,7 @@
// received DONE for a sent message
return;
} else if (exchange.getStatus() == ExchangeStatus.ERROR) {
- // received ERROR state for a sent message
+ // received ERROR state for a sent message
// there is no real error handling here for now
return;
} else {
@@ -137,11 +148,17 @@
private void connect() {
// create the SMPP session
session = new SMPPSession();
+ // define the enquireLinkTimer
+ session.setEnquireLinkTimer(this.enquireLinkTimer);
+ // define the transactionTimer
+ session.setTransactionTimer(this.transactionTimer);
// define a message receiver listener on the SMPP connection
session.setMessageReceiverListener(new MessageReceiverListener() {
/*
* (non-Javadoc)
- * @see org.jsmpp.session.MessageReceiverListener#onAcceptAlertNotification(org.jsmpp.bean.AlertNotification)
+ * @see
+ * org.jsmpp.session.MessageReceiverListener#onAcceptAlertNotification
+ * (org.jsmpp.bean.AlertNotification)
*/
public void onAcceptAlertNotification(AlertNotification alertNotification) {
// nothing to do
@@ -149,7 +166,9 @@
/*
* (non-Javadoc)
- * @see org.jsmpp.session.MessageReceiverListener#onAcceptDeliverSm(org.jsmpp.bean.DeliverSm)
+ * @see
+ * org.jsmpp.session.MessageReceiverListener#onAcceptDeliverSm(org
+ * .jsmpp.bean.DeliverSm)
*/
public void onAcceptDeliverSm(DeliverSm deliverSm) {
try {
@@ -163,7 +182,7 @@
}
});
-
+
// connect and bind to the SMPP server
try {
session.connectAndBind(this.host, this.port, new BindParameter(BindType.BIND_RX, this.systemId,
@@ -188,18 +207,18 @@
this.session.unbindAndClose();
}
-
public int getPort() {
return port;
}
/**
- * <p>This attribute specifies the port number to use for connecting to the
- * server.<br/><p>
- * <i> The default value is <b>2775</b></i>
+ * <p>
+ * This attribute specifies the port number to use for connecting to the
+ * server.<br/>
+ * <p>
+ * <i> The default value is <b>2775</b></i>
*
- * @param port
- * a <code>int</code> value representing the port number
+ * @param port a <code>int</code> value representing the port number
*/
public void setPort(int port) {
this.port = port;
@@ -210,12 +229,13 @@
}
/**
- * <p>This attribute specifies the host name to use for connecting to the
- * server.<br/><p>
+ * <p>
+ * This attribute specifies the host name to use for connecting to the
+ * server.<br/>
+ * <p>
* <i> The default value is <b>null</b></i>
*
- * @param host
- * a <code>String</code> value representing the host name
+ * @param host a <code>String</code> value representing the host name
*/
public void setHost(String host) {
this.host = host;
@@ -226,12 +246,13 @@
}
/**
- * <p>This attribute specifies the system id to use for connecting to the
- * server.<br/><p>
+ * <p>
+ * This attribute specifies the system id to use for connecting to the
+ * server.<br/>
+ * <p>
* <i> The default value is <b>null</b></i>
*
- * @param systemId
- * a <code>String</code> value representing the system id
+ * @param systemId a <code>String</code> value representing the system id
*/
public void setSystemId(String systemId) {
this.systemId = systemId;
@@ -242,12 +263,13 @@
}
/**
- * <p>This attribute specifies the password to use for connecting to the
- * server.<br/><p>
+ * <p>
+ * This attribute specifies the password to use for connecting to the
+ * server.<br/>
+ * <p>
* <i> The default value is <b>null</b></i>
*
- * @param password
- * a <code>String</code> value representing the password
+ * @param password a <code>String</code> value representing the password
*/
public void setPassword(String password) {
this.password = password;
@@ -258,15 +280,55 @@
}
/**
- * <p>With this method you can specify a marshaler class which provides the
- * logic for converting a sms message into a normalized message. This class has
- * to implement the interface class <code>SmppMarshaler</code>.
- * If you don't specify a marshaler, the <code>DefaultSmppMarshaler</code> will be used.</p>
+ * <p>
+ * With this method you can specify a marshaler class which provides the
+ * logic for converting a sms message into a normalized message. This class
+ * has to implement the interface class <code>SmppMarshaler</code>. If you
+ * don't specify a marshaler, the <code>DefaultSmppMarshaler</code> will be
+ * used.
+ * </p>
*
- * @param marshaler
- * a <code>SmppMarshaler</code> class representing the marshaler
+ * @param marshaler a <code>SmppMarshaler</code> class representing the
+ * marshaler
*/
public void setMarshaler(SmppMarshalerSupport marshaler) {
this.marshaler = marshaler;
}
+
+ public int getEnquireLinkTimer() {
+ return enquireLinkTimer;
+ }
+
+ /**
+ * <p>
+ * This attribute specifies the enquire link timer defining the SMSC time
+ * interval.<br/>
+ * </p>
+ * <i> The default value is <b>50000</b></i>
+ *
+ * @param enquireLinkTimer a <code>int</code> value representing the enquire
+ * link timer
+ */
+ public void setEnquireLinkTimer(int enquireLinkTimer) {
+ this.enquireLinkTimer = enquireLinkTimer;
+ }
+
+ public int getTransactionTimer() {
+ return transactionTimer;
+ }
+
+ /**
+ * <p>
+ * This attribute specifies the transaction timer defining the SMSC timeout.
+ * <br/>
+ * </p>
+ * <i> The default value is <b>100000</b></i>
+ *
+ * @param transactionTimer a <code>int</code> value representing the
+ * transaction timer (timeout)
+ */
+ public void setTransactionTimer(int transactionTimer) {
+ this.transactionTimer = transactionTimer;
+ }
+
}
Modified: servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppProviderEndpoint.java?rev=739812&r1=739811&r2=739812&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppProviderEndpoint.java (original)
+++ servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/SmppProviderEndpoint.java Sun Feb 1 18:46:45 2009
@@ -75,6 +75,8 @@
private int port;
private String systemId;
private String password;
+ private int enquireLinkTimer = 50000;
+ private int transactionTimer = 100000;
private SmppMarshalerSupport marshaler;
@@ -125,10 +127,18 @@
if (this.password == null || this.password.trim().length() <= 0) {
throw new IllegalArgumentException("The SMPP system password is mandatory.");
}
- // check the marshaler
- if (this.getMarshaler() == null) {
- this.setMarshaler(new DefaultSmppMarshaler());
- }
+ // check the marshaler
+ if (this.getMarshaler() == null) {
+ this.setMarshaler(new DefaultSmppMarshaler());
+ }
+ // check the enquire link timer
+ if (this.enquireLinkTimer <= 0) {
+ throw new IllegalArgumentException("The enquireLinkTimer value must be greater than 0.");
+ }
+ // check the transaction timer
+ if (this.transactionTimer <= 0) {
+ throw new IllegalArgumentException("The transactionTimer value must be greater than 0.");
+ }
}
/**
@@ -137,6 +147,10 @@
private void connect() {
// create the SMPPSession
session = new SMPPSession();
+ // define the enquireLinkTimer
+ session.setEnquireLinkTimer(this.enquireLinkTimer);
+ // define the transationTimer
+ session.setTransactionTimer(this.transactionTimer);
// connect and bind to the SMPP server
try {
session.connectAndBind(this.host, this.port, new BindParameter(BindType.BIND_TX, this.systemId,
@@ -182,7 +196,8 @@
* javax.jbi.messaging.NormalizedMessage)
*/
@Override
- protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception {
+ protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
+ throws Exception {
// we are reading the source of the NormalizedMessage multiple times
// (else we receive a IOException: Stream closed)
MessageUtil.enableContentRereadability(in);
@@ -202,7 +217,8 @@
* @throws TransformerException on transformation errors
* @throws MessagingException on messaging errors
*/
- private void process(MessageExchange exchange, NormalizedMessage in) throws TransformerException, MessagingException {
+ private void process(MessageExchange exchange, NormalizedMessage in) throws TransformerException,
+ MessagingException {
// let the marshaler create a SM content
MessageRequest sm = marshaler.fromNMS(exchange, in);
@@ -243,12 +259,13 @@
}
/**
- * <p>This attribute specifies the host name to use for connecting to the
- * server.<br/><p>
+ * <p>
+ * This attribute specifies the host name to use for connecting to the
+ * server.<br/>
+ * <p>
* <i> The default value is <b>null</b></i>
*
- * @param host
- * a <code>String</code> value representing the host name
+ * @param host a <code>String</code> value representing the host name
*/
public void setHost(String host) {
this.host = host;
@@ -267,12 +284,13 @@
}
/**
- * <p>This attribute specifies the system id to use for connecting to the
- * server.<br/><p>
+ * <p>
+ * This attribute specifies the system id to use for connecting to the
+ * server.<br/>
+ * <p>
* <i> The default value is <b>null</b></i>
*
- * @param systemId
- * a <code>String</code> value representing the system id
+ * @param systemId a <code>String</code> value representing the system id
*/
public void setSystemId(String systemId) {
this.systemId = systemId;
@@ -283,12 +301,13 @@
}
/**
- * <p>This attribute specifies the password to use for connecting to the
- * server.<br/><p>
+ * <p>
+ * This attribute specifies the password to use for connecting to the
+ * server.<br/>
+ * <p>
* <i> The default value is <b>null</b></i>
*
- * @param password
- * a <code>String</code> value representing the password
+ * @param password a <code>String</code> value representing the password
*/
public void setPassword(String password) {
this.password = password;
@@ -299,15 +318,55 @@
}
/**
- * <p>With this method you can specify a marshaler class which provides the
- * logic for converting a sms message into a normalized message. This class has
- * to implement the interface class <code>SmppMarshaler</code>.
- * If you don't specify a marshaler, the <code>DefaultSmppMarshaler</code> will be used.</p>
+ * <p>
+ * With this method you can specify a marshaler class which provides the
+ * logic for converting a sms message into a normalized message. This class
+ * has to implement the interface class <code>SmppMarshaler</code>. If you
+ * don't specify a marshaler, the <code>DefaultSmppMarshaler</code> will be
+ * used.
+ * </p>
*
- * @param marshaler
- * a <code>SmppMarshaler</code> class representing the marshaler
+ * @param marshaler a <code>SmppMarshaler</code> class representing the
+ * marshaler
*/
public void setMarshaler(SmppMarshalerSupport marshaler) {
this.marshaler = marshaler;
}
+
+ public int getEnquireLinkTimer() {
+ return enquireLinkTimer;
+ }
+
+ /**
+ * <p>
+ * This attribute specifies the enquire link timer defining the resend time
+ * interval.<br/>
+ * </p>
+ * <i> The default value is <b>50000</b> milliseconds</i>
+ *
+ * @param enquireLinkTimer a <code>int</code> value representing the enquire
+ * link timer
+ */
+ public void setEnquireLinkTimer(int enquireLinkTimer) {
+ this.enquireLinkTimer = enquireLinkTimer;
+ }
+
+ public int getTransactionTimer() {
+ return transactionTimer;
+ }
+
+ /**
+ * <p>
+ * This attribute specifies the transaction timer defining the maximum
+ * lifetime of a message.<br/>
+ * </p>
+ * <i> The default value is <b>100000</b> milliseconds</i>
+ *
+ * @param transactionTimer a <code>int</code> value representing the
+ * transaction timer
+ */
+ public void setTransactionTimer(int transactionTimer) {
+ this.transactionTimer = transactionTimer;
+ }
+
}
Modified: servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshaler.java?rev=739812&r1=739811&r2=739812&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshaler.java (original)
+++ servicemix/components/bindings/servicemix-smpp/trunk/src/main/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshaler.java Sun Feb 1 18:46:45 2009
@@ -27,6 +27,7 @@
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.jsmpp.bean.MessageRequest;
import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.SMSCDeliveryReceipt;
import org.jsmpp.bean.SubmitSm;
import org.jsmpp.bean.TypeOfNumber;
import org.w3c.dom.Document;
@@ -37,19 +38,21 @@
*
* @author jbonofre
* @author lhein
+ * @author mullerc
*/
public class DefaultSmppMarshaler implements SmppMarshalerSupport {
- // logging facility
private static final transient Log log = LogFactory.getLog(DefaultSmppMarshaler.class);
- // message tags
private final static String TAG_MESSAGE = "message";
private final static String TAG_SOURCE = "source";
private final static String TAG_DESTINATION = "destination";
private final static String TAG_TEXT = "text";
private final static String TAG_TON = "ton";
private final static String TAG_NPI = "npi";
+ private final static String TAG_REGISTERED_DELIVERY = "registeredDelivery";
+ private final static String TAG_SCHEDULE_DELIVERY_TIME = "scheduleDeliveryTime";
+ private final static String TAG_VALIDITY_PERIOD = "validityPeriod";
private final static String TAG_MESSAGE_OPEN = "<" + TAG_MESSAGE + ">";
private final static String TAG_MESSAGE_CLOSE = "</" + TAG_MESSAGE + ">";
@@ -63,86 +66,100 @@
private final static String TAG_TON_CLOSE = "</" + TAG_TON + ">";
private final static String TAG_NPI_OPEN = "<" + TAG_NPI + ">";
private final static String TAG_NPI_CLOSE = "</" + TAG_NPI + ">";
-
- // source transformer
+ private final static String TAG_REGISTERED_DELIVERY_OPEN = "<" + TAG_REGISTERED_DELIVERY + ">";
+ private final static String TAG_REGISTERED_DELIVERY_CLOSE = "</" + TAG_REGISTERED_DELIVERY + ">";
+ private final static String TAG_SCHEDULE_DELIVERY_TIME_OPEN = "<" + TAG_SCHEDULE_DELIVERY_TIME + ">";
+ private final static String TAG_SCHEDULE_DELIVERY_TIME_CLOSE = "</" + TAG_SCHEDULE_DELIVERY_TIME + ">";
+ private final static String TAG_VALIDITY_PERIOD_OPEN = "<" + TAG_VALIDITY_PERIOD + ">";
+ private final static String TAG_VALIDITY_PERIOD_CLOSE = "</" + TAG_VALIDITY_PERIOD + ">";
+
private SourceTransformer transformer = new SourceTransformer();
/*
* (non-Javadoc)
* @see org.apache.servicemix.smpp.marshaler.SmppMarshalerSupport#fromNMS(javax.jbi.messaging.MessageExchange, javax.jbi.messaging.NormalizedMessage)
*/
- public MessageRequest fromNMS(MessageExchange exchange, NormalizedMessage message)
- throws TransformerException {
+ public MessageRequest fromNMS(MessageExchange exchange, NormalizedMessage message) throws TransformerException {
SubmitSm sm = new SubmitSm();
String ton = null;
String npi = null;
+
try {
- log.debug("Convert normalized message content to DOM document");
Document document = transformer.toDOMDocument(message);
- log.debug("Normalize test representation");
document.getDocumentElement().normalize();
- log.debug("Get the normalized message source");
- NodeList node = document.getElementsByTagName(TAG_SOURCE);
- if (node != null && node.getLength() > 0) {
- log.debug("The source exists in the normalized message");
- sm.setSourceAddr(node.item(0).getChildNodes().item(0).getNodeValue());
+ NodeList node = null;
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_SOURCE)) != null) {
+ sm.setSourceAddr(getFirstNodeValue(node));
log.debug(TAG_SOURCE + ": " + sm.getSourceAddr());
}
- log.debug("Get the normalized message destination");
- node = document.getElementsByTagName(TAG_DESTINATION);
- if (node != null && node.getLength() > 0) {
- log.debug("The destination exists in the normalized message");
- sm.setDestAddress(node.item(0).getChildNodes().item(0).getNodeValue());
- log.debug(TAG_DESTINATION + ": " + sm.getDestAddress());
- }
- log.debug("Get the normalized message text");
- node = document.getElementsByTagName(TAG_TEXT);
- if (node != null && node.getLength() > 0) {
- log.debug("The text exists in the normalized message");
- sm.setShortMessage(node.item(0).getChildNodes().item(0).getNodeValue().getBytes());
- log.debug(TAG_TEXT + ": " + new String(sm.getShortMessage()));
- }
- log.debug("Get the normalized message TON");
- node = document.getElementsByTagName(TAG_TON);
- if (node != null && node.getLength() > 0) {
- log.debug("The TON exists in the normalized message");
- ton = node.item(0).getChildNodes().item(0).getNodeValue();
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_DESTINATION)) != null) {
+ sm.setDestAddress(getFirstNodeValue(node));
+ log.debug(TAG_DESTINATION + ": " + sm.getDestAddress());
+ }
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_TEXT)) != null) {
+ sm.setShortMessage(getFirstNodeValue(node).getBytes());
+ log.debug(TAG_TEXT + ": " + new String(sm.getShortMessage()));
+ }
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_TON)) != null) {
+ ton = getFirstNodeValue(node);
sm.setDestAddrTon(TypeOfNumber.valueOf(ton).value());
sm.setSourceAddrTon(TypeOfNumber.valueOf(ton).value());
log.debug(TAG_TON + ": " + ton);
}
- log.debug("Get the normalized message NPI");
- node = document.getElementsByTagName(TAG_NPI);
- if (node != null && node.getLength() > 0) {
- log.debug("The NPI exists in the normalized message");
- npi = node.item(0).getChildNodes().item(0).getNodeValue();
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_NPI)) != null) {
+ npi = getFirstNodeValue(node);
sm.setDestAddrNpi(NumberingPlanIndicator.valueOf(npi).value());
sm.setSourceAddrNpi(NumberingPlanIndicator.valueOf(npi).value());
log.debug(TAG_NPI + ": " + npi);
}
-
- log.debug("Check the mandatory attribute 'source'");
- if (sm.getSourceAddr() == null) {
- throw new TransformerException("Invalid message content. Missing tag: " + TAG_SOURCE);
- }
- log.debug("Check the mandatory attribute 'destination'");
- if (sm.getDestAddress() == null) {
- throw new TransformerException("Invalid message content. Missing tag: " + TAG_DESTINATION);
- }
- log.debug("Check the mandatory attribute 'ton'");
- if (ton == null) {
- throw new TransformerException("Invalid message content. Missing tag: " + TAG_TON);
- }
- if (npi == null) {
- throw new TransformerException("Invalid message content. Missing tag: " + TAG_NPI);
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_REGISTERED_DELIVERY)) != null) {
+ String registeredDelivery = getFirstNodeValue(node);
+ sm.setRegisteredDelivery(SMSCDeliveryReceipt.valueOf(registeredDelivery).value());
+ log.debug(TAG_REGISTERED_DELIVERY + ": " + registeredDelivery);
+ } else {
+ sm.setRegisteredDelivery(SMSCDeliveryReceipt.DEFAULT.value());
+ log.debug(TAG_REGISTERED_DELIVERY + ": DEFAULT");
+ }
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_SCHEDULE_DELIVERY_TIME)) != null) {
+ sm.setScheduleDeliveryTime(getFirstNodeValue(node));
+ log.debug(TAG_SCHEDULE_DELIVERY_TIME + ": " + sm.getScheduleDeliveryTime());
+ }
+
+ if ((node = getNotEmptyNodeListOrNull(document, TAG_VALIDITY_PERIOD)) != null) {
+ sm.setValidityPeriod(getFirstNodeValue(node));
+ log.debug(TAG_VALIDITY_PERIOD + ": " + sm.getValidityPeriod());
}
} catch (Exception exception) {
throw new TransformerException(exception);
}
+
+ if (sm.getSourceAddr() == null) {
+ throw new TransformerException("Invalid message content. Missing tag: " + TAG_SOURCE);
+ }
+
+ if (sm.getDestAddress() == null) {
+ throw new TransformerException("Invalid message content. Missing tag: " + TAG_DESTINATION);
+ }
+
+ if (ton == null) {
+ throw new TransformerException("Invalid message content. Missing tag: " + TAG_TON);
+ }
+
+ if (npi == null) {
+ throw new TransformerException("Invalid message content. Missing tag: " + TAG_NPI);
+ }
+
return sm;
}
- /*
+ /*
* (non-Javadoc)
* @see org.apache.servicemix.smpp.marshaler.SmppMarshalerSupport#toNMS(javax.jbi.messaging.NormalizedMessage, org.jsmpp.bean.MessageRequest)
*/
@@ -150,76 +167,115 @@
if (message == null) {
throw new MessagingException("The NormalizedMessage is null");
}
+
if (mr == null) {
throw new MessagingException("The MessageRequest is null");
}
- log.debug("Check if the MessageRequest is valid");
- log.debug("Check the MessageRequest source address");
if (mr.getSourceAddr() == null || mr.getSourceAddr().trim().length() < 1) {
log.error("The MessageRequest source address is not defined");
throw new MessagingException("The MessageRequest source address is not defined");
}
- log.debug("Check the MessageRequest destination address");
+
if (mr.getDestAddress() == null || mr.getDestAddress().trim().length() < 1) {
log.error("The MessageRequest destination address is not defined");
throw new MessagingException("The MessageRequest destination address is not defined");
}
- log.debug("Check the MessageRequest destination numbering plan indicator");
+
try {
NumberingPlanIndicator.valueOf(mr.getDestAddrNpi());
} catch (IllegalArgumentException illegalArgumentException) {
log.error("The MessageRequest destination numbering plan indicator is not valid");
- throw new MessagingException(
- "The MessageRequest destination numbering plan indicator is not valid");
+ throw new MessagingException("The MessageRequest destination numbering plan indicator is not valid");
}
- log.debug("Check the MessageRequest destination type of numbner");
+
try {
TypeOfNumber.valueOf(mr.getDestAddrTon());
} catch (IllegalArgumentException illegalArgumentException) {
log.error("The MessageRequest destination type of number is not valid");
throw new MessagingException("The MessageRequest destination type of number is not valid");
}
-
- String text = null;
+
try {
- text = new String(mr.getShortMessage());
- } catch (NullPointerException exception) {
- log.warn("The MessageRequest Short Message is null");
+ determineSMSCDeliveryReceipt(mr.getRegisteredDelivery());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ log.error("The MessageRequest registered delivery is not valid");
+ throw new MessagingException("The MessageRequest registered delivery is not valid");
}
-
- if (text != null && text.trim().length() > 0) {
- StringBuffer data = new StringBuffer();
-
- // build the message content
- data.append(TAG_MESSAGE_OPEN);
-
- data.append(TAG_SOURCE_OPEN);
- data.append(mr.getSourceAddr());
- data.append(TAG_SOURCE_CLOSE);
-
- data.append(TAG_DESTINATION_OPEN);
- data.append(mr.getDestAddress());
- data.append(TAG_DESTINATION_CLOSE);
-
- data.append(TAG_TEXT_OPEN);
- data.append(text);
- data.append(TAG_TEXT_CLOSE);
-
- data.append(TAG_NPI_OPEN);
- data.append(NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
- data.append(TAG_NPI_CLOSE);
-
- data.append(TAG_TON_OPEN);
- data.append(TypeOfNumber.valueOf(mr.getDestAddrTon()).toString());
- data.append(TAG_TON_CLOSE);
-
- data.append(TAG_MESSAGE_CLOSE);
-
- // put the content to message body
- message.setContent(new StringSource(data.toString()));
- } else {
- log.debug("Received message without text content. Ignore the message");
+
+ if (mr.getShortMessage() == null || mr.getShortMessage().length == 0) {
+ log.warn("Received message without text content. Ignore the message");
+ return;
+ }
+
+ StringBuffer data = new StringBuffer();
+ data.append(TAG_MESSAGE_OPEN);
+
+ data.append(TAG_SOURCE_OPEN);
+ data.append(mr.getSourceAddr());
+ data.append(TAG_SOURCE_CLOSE);
+
+ data.append(TAG_DESTINATION_OPEN);
+ data.append(mr.getDestAddress());
+ data.append(TAG_DESTINATION_CLOSE);
+
+ data.append(TAG_TEXT_OPEN);
+ data.append(new String(mr.getShortMessage()));
+ data.append(TAG_TEXT_CLOSE);
+
+ data.append(TAG_NPI_OPEN);
+ data.append(NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
+ data.append(TAG_NPI_CLOSE);
+
+ data.append(TAG_TON_OPEN);
+ data.append(TypeOfNumber.valueOf(mr.getDestAddrTon()).toString());
+ data.append(TAG_TON_CLOSE);
+
+ data.append(TAG_REGISTERED_DELIVERY_OPEN);
+ data.append(determineSMSCDeliveryReceipt(mr.getRegisteredDelivery()).toString());
+ data.append(TAG_REGISTERED_DELIVERY_CLOSE);
+
+ if (mr.getScheduleDeliveryTime() != null && mr.getScheduleDeliveryTime().trim().length() > 0) {
+ data.append(TAG_SCHEDULE_DELIVERY_TIME_OPEN);
+ data.append(mr.getScheduleDeliveryTime());
+ data.append(TAG_SCHEDULE_DELIVERY_TIME_CLOSE);
+ }
+
+ if (mr.getValidityPeriod() != null && mr.getValidityPeriod().trim().length() > 0) {
+ data.append(TAG_VALIDITY_PERIOD_OPEN);
+ data.append(mr.getValidityPeriod());
+ data.append(TAG_VALIDITY_PERIOD_CLOSE);
}
+
+ data.append(TAG_MESSAGE_CLOSE);
+
+ message.setContent(new StringSource(data.toString()));
}
-}
+
+ private String getFirstNodeValue(NodeList node) {
+ return node.item(0).getChildNodes().item(0).getNodeValue();
+ }
+
+ private NodeList getNotEmptyNodeListOrNull(Document document, String nodeName) {
+ NodeList node = document.getElementsByTagName(nodeName);
+ return (node != null && node.getLength() > 0) ? node : null;
+ }
+
+ /**
+ * Get the <tt>SMSCDeliveryReceipt</tt> based on the specified byte value
+ * representation.
+ *
+ * @param value is the byte value representation.
+ * @return is the enum const related to the specified byte value.
+ * @throws IllegalArgumentException if there is no enum const associated
+ * with specified byte value.
+ */
+ private SMSCDeliveryReceipt determineSMSCDeliveryReceipt(byte value) {
+ for (SMSCDeliveryReceipt val : SMSCDeliveryReceipt.values()) {
+ if (val.value() == value)
+ return val;
+ }
+
+ throw new IllegalArgumentException("No enum const SMSCDeliveryReceipt with value " + value);
+ }
+}
\ No newline at end of file
Modified: servicemix/components/bindings/servicemix-smpp/trunk/src/test/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshalerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-smpp/trunk/src/test/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshalerTest.java?rev=739812&r1=739811&r2=739812&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-smpp/trunk/src/test/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshalerTest.java (original)
+++ servicemix/components/bindings/servicemix-smpp/trunk/src/test/java/org/apache/servicemix/smpp/marshaler/DefaultSmppMarshalerTest.java Sun Feb 1 18:46:45 2009
@@ -16,14 +16,12 @@
*/
package org.apache.servicemix.smpp.marshaler;
-import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessageExchangeFactory;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
-import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import junit.framework.TestCase;
@@ -33,171 +31,230 @@
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.messaging.MessageExchangeFactoryImpl;
-import org.apache.servicemix.smpp.marshaler.DefaultSmppMarshaler;
-import org.apache.servicemix.smpp.marshaler.SmppMarshalerSupport;
import org.jsmpp.bean.MessageRequest;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.SubmitSm;
import org.jsmpp.bean.TypeOfNumber;
-import org.xml.sax.SAXException;
/**
* Unit tests on the SMPP marshaler
*
* @author jbonofre
+ * @author mullerc
*/
public class DefaultSmppMarshalerTest extends TestCase {
-
+
private static final String SOURCE = "0123456789";
private static final String DESTINATION = "9876543210";
private static final String TEXT = "This is a SMPP test ...";
private static final String NPI = "NATIONAL";
private static final String TON = "INTERNATIONAL";
-
- private static final String MSG_VALID = "<message><source>" + SOURCE + "</source><destination>"
- + DESTINATION + "</destination><text>" + TEXT + "</text><npi>"
- + NPI + "</npi><ton>" + TON + "</ton></message>";
+ private static final String REGISTERED_DELIVERY = "SUCCESS_FAILURE";
+ private static final String SCHEDULE_DELIVERY_TIME = "091231143301300+";
+ private static final String VALIDITY_PERIOD = "091231153301300+";
+
+ private static final String MSG_VALID_MIN_ATTR =
+ "<message>" +
+ "<source>" + SOURCE + "</source>" +
+ "<destination>" + DESTINATION + "</destination>" +
+ "<text>" + TEXT + "</text>" +
+ "<npi>" + NPI + "</npi>" +
+ "<ton>" + TON + "</ton>" +
+ "</message>";
+
+ private static final String MSG_VALID_MAX_ATTR =
+ "<message>" +
+ "<source>" + SOURCE + "</source>" +
+ "<destination>" + DESTINATION + "</destination>" +
+ "<text>" + TEXT + "</text>" +
+ "<npi>" + NPI + "</npi>" +
+ "<ton>" + TON + "</ton>" +
+ "<registeredDelivery>" + REGISTERED_DELIVERY + "</registeredDelivery>" +
+ "<scheduleDeliveryTime>" + SCHEDULE_DELIVERY_TIME + "</scheduleDeliveryTime>" +
+ "<validityPeriod>" + VALIDITY_PERIOD + "</validityPeriod>" +
+ "</message>";
+
+ private static final String MSG_VALID_MAX_DEF_ATTR =
+ "<message>" +
+ "<source>" + SOURCE + "</source>" +
+ "<destination>" + DESTINATION + "</destination>" +
+ "<text>" + TEXT + "</text>" +
+ "<npi>" + NPI + "</npi>" +
+ "<ton>" + TON + "</ton>" +
+ "<registeredDelivery>DEFAULT</registeredDelivery>" +
+ "</message>";
+
private static final String MSG_INVALID = "Test breaker ...";
- private static final String MSG_INVALID_DEST = "<message><source>" + SOURCE + "</source><text>" + TEXT
- + "</text><npi>" + NPI + "</npi><ton>" + TON
- + "</ton></message>";
- private static final String MSG_INVALID_TON = "<message><source>" + SOURCE + "</source><destination>"
- + DESTINATION + "</destination><text>" + TEXT
- + "</text><npi>" + NPI + "</npi></message>";
- private static final String MSG_INVALID_NPI = "<message><source>" + SOURCE + "</source><destination>"
- + DESTINATION + "</destination><text>" + TEXT
- + "</text><ton>" + TON + "</ton></message>";
+
+ private static final String MSG_INVALID_DEST =
+ "<message>" +
+ "<source>" + SOURCE + "</source>" +
+ "<text>" + TEXT + "</text>" +
+ "<npi>" + NPI + "</npi>" +
+ "<ton>" + TON + "</ton>" +
+ "</message>";
+
+ private static final String MSG_INVALID_TON =
+ "<message>" +
+ "<source>" + SOURCE + "</source>" +
+ "<destination>" + DESTINATION + "</destination>" +
+ "<text>" + TEXT + "</text>" +
+ "<npi>" + NPI + "</npi>" +
+ "</message>";
+
+ private static final String MSG_INVALID_NPI =
+ "<message>" +
+ "<source>" + SOURCE + "</source>" +
+ "<destination>" + DESTINATION + "</destination>" +
+ "<text>" + TEXT + "</text>" +
+ "<ton>" + TON + "</ton>" +
+ "</message>";
+
+ private static final String MSG_INVALID_REGISTERED_DELIVERY =
+ "<message>" +
+ "<source>" + SOURCE + "</source>" +
+ "<destination>" + DESTINATION + "</destination>" +
+ "<text>" + TEXT + "</text>" +
+ "<npi>" + NPI + "</npi>" +
+ "<ton>" + TON + "</ton>" +
+ "<registeredDelivery>xxx</registeredDelivery>" +
+ "</message>";
private SmppMarshalerSupport marshaler;
private MessageExchangeFactory factory;
- /**
- * @see junit.framework.TestCase#setUp()
- */
public void setUp() throws Exception {
this.marshaler = new DefaultSmppMarshaler();
this.factory = new MessageExchangeFactoryImpl(new IdGenerator(), new AtomicBoolean(false));
}
- /**
- * @see junit.framework.TestCase#tearDown()
- */
- public void tearDown() {
- this.marshaler = null;
- this.factory = null;
- }
-
// UNIT TESTS
- public void testFromNMSValid() {
- try {
- // construct the MessageExchange and NormalizedMessage
- MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
- NormalizedMessage message = exchange.createMessage();
- message.setContent(new StringSource(MSG_VALID));
- exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
- assertEquals("The message text is not the same: ", TEXT, new String(mr.getShortMessage()));
- assertEquals("The destination address is not the same: ", mr.getDestAddress(), DESTINATION);
- assertEquals("The source address is not the same: ", SOURCE, mr.getSourceAddr());
- assertEquals("The destination type of number is not the same: ", TON, TypeOfNumber
- .valueOf(mr.getDestAddrTon()).toString());
- assertEquals("The source type of number is not the same: ", TON, TypeOfNumber
- .valueOf(mr.getSourceAddrTon()).toString());
- assertEquals("The destination numbering plan indicator is not the same: ", NPI,
- NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
- assertEquals("The source numbering plan indicator is not the same: ", NPI, NumberingPlanIndicator
- .valueOf(mr.getSourceAddrNpi()).toString());
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs when constructing the exchange and the normalized message : "
- + messagingException.getMessage());
- } catch (TransformerException transformerException) {
- fail("Transformer exception occurs while using the marshaler to converts the normalized message to the message request : "
- + transformerException.getMessage());
- }
+ public void testFromNMSValidMinAttr() throws Exception {
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ message.setContent(new StringSource(MSG_VALID_MIN_ATTR));
+ exchange.setMessage(message, "in");
+
+ MessageRequest mr = this.marshaler.fromNMS(exchange, message);
+
+ assertEquals(TEXT, new String(mr.getShortMessage()));
+ assertEquals(mr.getDestAddress(), DESTINATION);
+ assertEquals(SOURCE, mr.getSourceAddr());
+ assertEquals(TON, TypeOfNumber.valueOf(mr.getDestAddrTon()).toString());
+ assertEquals(TON, TypeOfNumber.valueOf(mr.getSourceAddrTon()).toString());
+ assertEquals(NPI, NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
+ assertEquals(NPI, NumberingPlanIndicator.valueOf(mr.getSourceAddrNpi()).toString());
+ assertEquals((byte)0x00, mr.getRegisteredDelivery());
+ assertNull(mr.getScheduleDeliveryTime());
+ assertNull(mr.getValidityPeriod());
+ }
+
+ public void testFromNMSValidMaxAttr() throws Exception {
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ message.setContent(new StringSource(MSG_VALID_MAX_ATTR));
+ exchange.setMessage(message, "in");
+
+ MessageRequest mr = this.marshaler.fromNMS(exchange, message);
+
+ assertEquals(TEXT, new String(mr.getShortMessage()));
+ assertEquals(mr.getDestAddress(), DESTINATION);
+ assertEquals(SOURCE, mr.getSourceAddr());
+ assertEquals(TON, TypeOfNumber.valueOf(mr.getDestAddrTon()).toString());
+ assertEquals(TON, TypeOfNumber.valueOf(mr.getSourceAddrTon()).toString());
+ assertEquals(NPI, NumberingPlanIndicator.valueOf(mr.getDestAddrNpi()).toString());
+ assertEquals(NPI, NumberingPlanIndicator.valueOf(mr.getSourceAddrNpi()).toString());
+ assertEquals((byte)0x01, mr.getRegisteredDelivery());
+ assertEquals(SCHEDULE_DELIVERY_TIME, mr.getScheduleDeliveryTime());
+ assertEquals(VALIDITY_PERIOD, mr.getValidityPeriod());
}
-
+
public void testFromNMSNullExchange() {
try {
- marshaler.fromNMS(null, null);
+ this.marshaler.fromNMS(null, null);
fail("Seems we processed a message with null exchange...");
} catch (TransformerException transformerException) {
- // fine
+ // expected
}
}
- public void testFromNMSInvalid() {
+ public void testFromNMSInvalid() throws Exception {
try {
MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
NormalizedMessage message = exchange.createMessage();
message.setContent(new StringSource(MSG_INVALID));
exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
+
+ this.marshaler.fromNMS(exchange, message);
+
fail("Seems we processed a invalid message...");
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs : " + messagingException.getMessage());
} catch (TransformerException transformerException) {
- // fine
+ // expected
}
}
- public void testFromNMSInvalidDest() {
+ public void testFromNMSInvalidDest() throws Exception {
try {
MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
NormalizedMessage message = exchange.createMessage();
message.setContent(new StringSource(MSG_INVALID_DEST));
exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
+
+ this.marshaler.fromNMS(exchange, message);
+
fail("Seems we processed a message with a invalid destination...");
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs : " + messagingException.getMessage());
} catch (TransformerException transformerException) {
- // fine
+ // expected
}
}
- public void testFromNMSInvalidTon() {
+ public void testFromNMSInvalidTon() throws Exception {
try {
MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
NormalizedMessage message = exchange.createMessage();
message.setContent(new StringSource(MSG_INVALID_TON));
exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
+
+ this.marshaler.fromNMS(exchange, message);
+
fail("Seems we processed a message with a invlid type of number...");
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs : " + messagingException.getMessage());
} catch (TransformerException transformerException) {
- // fine
+ // expected
}
}
- public void testFromNMSInvalidNpi() {
+ public void testFromNMSInvalidNpi() throws Exception {
try {
MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
NormalizedMessage message = exchange.createMessage();
message.setContent(new StringSource(MSG_INVALID_NPI));
exchange.setMessage(message, "in");
- // use the marshaler to converts the NormalizedMessage to a
- // MessageRequest
- MessageRequest mr = marshaler.fromNMS(exchange, message);
+
+ this.marshaler.fromNMS(exchange, message);
+
fail("Seems we processed a message with a invlid numbering plan indicator...");
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs : " + messagingException.getMessage());
} catch (TransformerException transformerException) {
- // fine
+ // expected
+ }
+ }
+
+ public void testFromNMSInvalidRegisteredDelivery() throws MessagingException {
+ try {
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ message.setContent(new StringSource(MSG_INVALID_REGISTERED_DELIVERY));
+ exchange.setMessage(message, "in");
+
+ this.marshaler.fromNMS(exchange, message);
+
+ fail("Seems we processed a message with a invlid registered delivery value...");
+ } catch (TransformerException transformerException) {
+ // expected
}
}
- public void testToNMSValid() {
- // constructs the MessageRequest
+ public void testToNMSValidMinAttr() throws Exception {
MessageRequest mr = new SubmitSm();
mr.setDestAddress(DESTINATION);
mr.setDestAddrNpi(NumberingPlanIndicator.valueOf(NPI).value());
@@ -206,68 +263,80 @@
mr.setSourceAddrNpi(NumberingPlanIndicator.valueOf(NPI).value());
mr.setSourceAddrTon(TypeOfNumber.valueOf(TON).value());
mr.setShortMessage(TEXT.getBytes());
- try {
- MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
- NormalizedMessage message = exchange.createMessage();
- exchange.setMessage(message, "in");
- marshaler.toNMS(message, mr);
- SourceTransformer sourceTransformer = new SourceTransformer();
- assertEquals("Message not correct: ", MSG_VALID, sourceTransformer.contentToString(message));
- } catch (MessagingException messagingException) {
- fail("Messaging exception occurs during the construction of the MessageExchange and NormalizedMessage: "
- + messagingException.getMessage());
- } catch (TransformerException transformerException) {
- fail("Transformer exception occurs using the marshaler: " + transformerException.getMessage());
- } catch (ParserConfigurationException parserConfigurationException) {
- fail("Parser configuration exception occurs using the SourceTransformer: "
- + parserConfigurationException.getMessage());
- } catch (SAXException saxException) {
- fail("SAX exception occurs using the SourceTransformer: " + saxException.getMessage());
- } catch (IOException ioException) {
- fail("IO exception occurs using the SourceTransformer: " + ioException.getMessage());
- }
+
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setMessage(message, "in");
+
+ this.marshaler.toNMS(message, mr);
+
+ assertEquals(MSG_VALID_MAX_DEF_ATTR, new SourceTransformer().contentToString(message));
+ }
+
+ public void testToNMSValidMaxAttr() throws Exception {
+ MessageRequest mr = new SubmitSm();
+ mr.setDestAddress(DESTINATION);
+ mr.setDestAddrNpi(NumberingPlanIndicator.valueOf(NPI).value());
+ mr.setDestAddrTon(TypeOfNumber.valueOf(TON).value());
+ mr.setSourceAddr(SOURCE);
+ mr.setSourceAddrNpi(NumberingPlanIndicator.valueOf(NPI).value());
+ mr.setSourceAddrTon(TypeOfNumber.valueOf(TON).value());
+ mr.setShortMessage(TEXT.getBytes());
+ mr.setRegisteredDelivery((byte)0x01);
+ mr.setScheduleDeliveryTime(SCHEDULE_DELIVERY_TIME);
+ mr.setValidityPeriod(VALIDITY_PERIOD);
+
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setMessage(message, "in");
+
+ this.marshaler.toNMS(message, mr);
+
+ assertEquals(MSG_VALID_MAX_ATTR, new SourceTransformer().contentToString(message));
}
- public void testToNMSInvalid() {
- // constructs a invalid MessageRequest (without destination, source,
- // NPI, TON)
+ public void testToNMSInvalid() throws Exception {
MessageRequest mr = new SubmitSm();
mr.setShortMessage(TEXT.getBytes());
+
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setMessage(message, "in");
+
try {
- MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
- NormalizedMessage message = exchange.createMessage();
- exchange.setMessage(message, "in");
- marshaler.toNMS(message, mr);
+ this.marshaler.toNMS(message, mr);
+
fail("Seems we processed an invalid MessageRequest...");
} catch (MessagingException messagingException) {
- // fine
+ // expected
}
}
- public void testToNMSNullMessageRequest() {
+ public void testToNMSNullMessageRequest() throws Exception {
MessageRequest mr = null;
+ MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setMessage(message, "in");
+
try {
- MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
- NormalizedMessage message = exchange.createMessage();
- exchange.setMessage(message, "in");
- marshaler.toNMS(message, mr);
+ this.marshaler.toNMS(message, mr);
+
fail("Seems we processed a Null MessageRequest...");
} catch (MessagingException messagingException) {
- // fine
+ // expected
}
}
public void testToNMSNullMessage() {
- // constructs a invalid MessageRequest (without destination, source,
- // NPI, TON)
MessageRequest mr = new SubmitSm();
mr.setShortMessage(TEXT.getBytes());
+
try {
marshaler.toNMS(null, mr);
+
fail("Seems we processed a MessageRequest with a Null NormalizedMessage...");
} catch (MessagingException messagingException) {
- // fine
+ // expected
}
}
-
-}
+}
\ No newline at end of file