This is an automated email from the ASF dual-hosted git repository. billblough pushed a commit to branch transport in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-transports.git
commit 2e0b3dcf21bfd196f94dde78be67f52c48b3a58a Author: Ruwan Linton <ru...@apache.org> AuthorDate: Tue Oct 6 16:20:27 2009 +0000 Committing for Charith (WSCOMMONS-503) --- .../sms/DefaultSMSMessageBuilderImpl.java | 41 +++++++------ .../sms/DefaultSMSMessageFormatterImpl.java | 29 ++++++--- .../org/apache/axis2/transport/sms/SMSManager.java | 39 ++++++++---- .../org/apache/axis2/transport/sms/SMSMessage.java | 30 +++++++++- .../axis2/transport/sms/SMSMessageBuilder.java | 16 ++--- .../axis2/transport/sms/SMSTransportConstents.java | 9 +++ .../axis2/transport/sms/smpp/SMPPDispatcher.java | 6 +- .../axis2/transport/sms/smpp/SMPPImplManager.java | 70 ++++++++++++++++++++-- .../axis2/transport/sms/smpp/SMPPListener.java | 18 +++++- 1.0.0/pom.xml | 1 + 10 files changed, 207 insertions(+), 52 deletions(-) diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/DefaultSMSMessageBuilderImpl.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/DefaultSMSMessageBuilderImpl.java index 03a1b3f..3790369 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/DefaultSMSMessageBuilderImpl.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/DefaultSMSMessageBuilderImpl.java @@ -20,6 +20,7 @@ package org.apache.axis2.transport.sms; import org.apache.axis2.context.MessageContext; import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.AbstractContext; import org.apache.axis2.engine.AxisConfiguration; import org.apache.axis2.description.*; import org.apache.axis2.AxisFault; @@ -52,17 +53,12 @@ public class DefaultSMSMessageBuilderImpl implements SMSMessageBuilder { /** the reference to the actual commons logger to be used for log messages */ protected Log log = LogFactory.getLog(this.getClass()); - /** - * - * @param message the content of the SMS - * @param sender senders phone number - * @param configurationContext axis2 configuration Context - * @return Returns the MessageContext built from the SMS - * @throws InvalidMessageFormatException - */ - public MessageContext buildMessaage(String message, String sender,String receiver ,ConfigurationContext configurationContext) - throws InvalidMessageFormatException { + public MessageContext buildMessaage(SMSMessage msg,ConfigurationContext configurationContext) + throws InvalidMessageFormatException { + String message = msg.getContent(); + String sender = msg.getSender(); + String receiver = msg.getReceiver(); String[] parts = message.split(":"); @@ -100,17 +96,13 @@ public class DefaultSMSMessageBuilderImpl implements SMSMessageBuilder { SOAPEnvelope soapEnvelope = createSoapEnvelope(messageContext , params); messageContext.setServerSide(true); messageContext.setEnvelope(soapEnvelope); - Parameter sendBack = new Parameter(); - sendBack.setName(SMSTransportConstents.SEND_TO); - sendBack.setValue(sender); - Parameter axis2Phone = new Parameter(); - axis2Phone.setName(SMSTransportConstents.DESTINATION); - axis2Phone.setValue(receiver); TransportInDescription in = configurationContext.getAxisConfiguration().getTransportIn("sms"); TransportOutDescription out = configurationContext.getAxisConfiguration().getTransportOut("sms"); - out.addParameter(sendBack); + messageContext.setProperty(SMSTransportConstents.SEND_TO , sender); + messageContext.setProperty(SMSTransportConstents.DESTINATION , receiver); messageContext.setTransportIn(in); messageContext.setTransportOut(out); + handleSMSProperties(msg , messageContext); return messageContext; } @@ -126,6 +118,21 @@ public class DefaultSMSMessageBuilderImpl implements SMSMessageBuilder { return null; } + /** + * this will add the SMSMessage properties to the Axis2MessageContext + * @param msg + * @param messageContext + */ + protected void handleSMSProperties(SMSMessage msg , MessageContext messageContext) { + + Iterator<String> it = msg.getProperties().keySet().iterator(); + while (it.hasNext()) { + String key = it.next(); + messageContext.setProperty(key , msg.getProperties().get(key)); + } + + + } private SOAPEnvelope createSoapEnvelope(MessageContext messageContext , Map params) { SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory(); SOAPEnvelope inEnvlope = soapFactory.getDefaultEnvelope(); diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/DefaultSMSMessageFormatterImpl.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/DefaultSMSMessageFormatterImpl.java index 57d201a..fa589f1 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/DefaultSMSMessageFormatterImpl.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/DefaultSMSMessageFormatterImpl.java @@ -24,6 +24,8 @@ import org.apache.axis2.transport.sms.smpp.SMPPTransportOutDetails; import org.apache.axis2.description.Parameter; import org.apache.axiom.om.OMElement; +import java.util.Iterator; + public class DefaultSMSMessageFormatterImpl implements SMSMessageFormatter{ @@ -31,12 +33,12 @@ public class DefaultSMSMessageFormatterImpl implements SMSMessageFormatter{ String sendTo; //phone number set at the Transport configuration get the precidence String axis2PhoneNumber = SMPPTransportOutDetails.getInstence().getPhoneNumber() ; - Parameter param = messageContext.getTransportOut().getParameter(SMSTransportConstents.SEND_TO); - if (param != null) { - sendTo = (String)param.getValue(); + Object s= messageContext.getProperty(SMSTransportConstents.SEND_TO); + if (s != null) { + sendTo = (String)s; } else { - sendTo = SMSTransportUtils.getPhoneNumber(messageContext.getTo()); + sendTo = SMSTransportUtils.getPhoneNumber(messageContext.getTo()); } OMElement elem = messageContext.getEnvelope().getBody(); String content = "Empty responce"; @@ -57,13 +59,26 @@ public class DefaultSMSMessageFormatterImpl implements SMSMessageFormatter{ //if not configured in the Transport configuration if("0000".equals(axis2PhoneNumber)) { - Parameter axisPhone = messageContext.getTransportOut().getParameter(SMSTransportConstents.DESTINATION); + String axisPhone = (String)messageContext.getProperty(SMSTransportConstents.DESTINATION); if(axisPhone != null) { - axis2PhoneNumber = (String)axisPhone.getValue(); + axis2PhoneNumber = axisPhone; } } + SMSMessage sms = new SMSMessage( axis2PhoneNumber, sendTo , content ,SMSMessage.OUT_MESSAGE); + handleMessageContextProperties(sms,messageContext); + return sms; + + } + + private void handleMessageContextProperties(SMSMessage sms , MessageContext messageContext) { + + Iterator<String> it = messageContext.getPropertyNames(); + + while(it.hasNext()) { + String key = it.next(); + sms.addProperty(key , messageContext.getProperty(key)); + } - return new SMSMessage( axis2PhoneNumber, sendTo , content ,SMSMessage.OUT_MESSAGE); } diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSManager.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSManager.java index c11a7f9..c1dc158 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSManager.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSManager.java @@ -26,6 +26,7 @@ import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.MessageContext; import org.apache.axis2.transport.sms.smpp.SMPPImplManager; import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.engine.AxisEngine; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -39,12 +40,12 @@ import java.util.ArrayList; public class SMSManager { private SMSImplManager currentImplimentation; - private ArrayList<Parameter> transportParameters; private boolean inited; private ConfigurationContext configurationContext; private SMSMessageBuilder messageBuilder; private SMSMessageFormatter messageFormatter; private String phoneNumber = null; + private boolean invertSourceAndDestination = true; /** the reference to the actual commons logger to be used for log messages */ protected Log log = LogFactory.getLog(this.getClass()); @@ -112,6 +113,21 @@ public class SMSManager { } } currentImplimentation.setTransportOutDetails(transportOutDescription); + + Parameter invertS_n_D = transportOutDescription.getParameter( + SMSTransportConstents.INVERT_SOURCE_AND_DESTINATION); + if(invertS_n_D != null) { + String val = (String)invertS_n_D.getValue(); + if("false".equals(val)) { + invertSourceAndDestination = false; + } else if("true".equals(val)) { + invertSourceAndDestination = true; + } else { + log.warn("Invalid parameter value set to the parameter invert_source_and_destination," + + "setting the default value :true "); + invertSourceAndDestination = true; + } + } inited = true; } @@ -137,13 +153,12 @@ public class SMSManager { } /** * Dispatch the SMS message to Axis2 Engine - * @param message - * @param sender + * @param sms */ public void dispatchToAxis2(SMSMessage sms) { try { - MessageContext msgctx = messageBuilder.buildMessaage(sms.getContent() , sms.getSender() ,sms.getReceiver(), - configurationContext); + MessageContext msgctx = messageBuilder.buildMessaage(sms,configurationContext); + msgctx.setReplyTo(new EndpointReference("sms://"+sms.getSender()+"/")); AxisEngine.receive(msgctx); } catch (InvalidMessageFormatException e) { log.debug("Invalid message format " + e); @@ -163,6 +178,7 @@ public class SMSManager { public void sendSMS(MessageContext messageContext) { try { SMSMessage sms = messageFormatter.formatSMS(messageContext); + sms.addProperty(SMSTransportConstents.INVERT_SOURCE_AND_DESTINATION ,"" + invertSourceAndDestination); currentImplimentation.sendSMS(sms); } catch (Exception e) { log.error("Error while sending the SMS " , e); @@ -177,11 +193,6 @@ public class SMSManager { public void sentInfo(SMSMessage sms) { currentImplimentation.sendSMS(sms); } - public ArrayList<Parameter> getTransportParameters() { - return transportParameters; - } - - public SMSImplManager getCurrentImplimentation() { return currentImplimentation; @@ -206,4 +217,12 @@ public class SMSManager { public String getPhoneNumber() { return phoneNumber; } + + public boolean isInvertSourceAndDestination() { + return invertSourceAndDestination; + } + + public void setInvertSourceAndDestination(boolean invertSourceAndDestination) { + this.invertSourceAndDestination = invertSourceAndDestination; + } } diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSMessage.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSMessage.java index 4dfdc17..ba0fb49 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSMessage.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSMessage.java @@ -22,11 +22,16 @@ import org.apache.axis2.AxisFault; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.Properties; +import java.util.Map; +import java.util.HashMap; + /** * SMS message is a atomic object wich carries a SMS * SMS has can be either a IN message or a OUT message - * which will have the details sender , receiver and Content + * which will have the details sender , receiver ,Content and properties * sender , receiver has a implied meaning with the Message direction + * <br> * eg: * in a IN_MESSAGE sender : the phone number of the phone that sms has been sent to axis2 * receiver : the phone number given from the SMSC to the Axis2 @@ -40,12 +45,14 @@ public class SMSMessage { private String receiver; private String content; private int direction; + private Map<String ,Object> properties = new HashMap<String , Object>(); + public static int IN_MESSAGE =1; public static int OUT_MESSAGE =2; /** - * + * * @param sender * @param reciever * @param content @@ -98,4 +105,23 @@ public class SMSMessage { public int getDirection() { return direction; } + + /** + * add the Implementation level properties that properties will be add to the Axis2 Message Context + * @param key + * @param value + */ + public void addProperty(String key, Object value) { + if(key != null && value != null) { + properties.put(key,value); + } + } + + /** + * Return the properties of the SMS message + * @return + */ + public Map<String , Object> getProperties() { + return properties; + } } diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSMessageBuilder.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSMessageBuilder.java index 12a1e03..65720f2 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSMessageBuilder.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSMessageBuilder.java @@ -30,15 +30,15 @@ import org.apache.axis2.context.ConfigurationContext; public interface SMSMessageBuilder { /** - * Build the Axis2 MessageContext from the given message Coming - * @param message the content of the SMS - * @param configurationContext axis2 configuration Context - * @param sener senders phone number - * @param receiver receivers phone number - * @return the Axis2 Message Context build - * @throws InvalidMessageFormatException if Message is not in correct format + * Build the Axis2 Message Context form the SMSMessage.This is respnsible for handling <br> + * the content comming with the SMSMessage, handling the sender receiver details and handling the <br> + * and handling the SMSMessage properties to buld the Axis2 Message Context appropriately + * @param msg + * @param configurationContext + * @return + * @throws InvalidMessageFormatException */ - public MessageContext buildMessaage(String message ,String sener,String receiver, ConfigurationContext configurationContext) + public MessageContext buildMessaage(SMSMessage msg, ConfigurationContext configurationContext) throws InvalidMessageFormatException; } diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java index d4265b0..20ec931 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/SMSTransportConstents.java @@ -39,6 +39,15 @@ public class SMSTransportConstents { public static String FORMATTER_CLASS ="formatterClass"; public static String SEND_TO="sms_sender"; public static String DESTINATION = "sms_destination"; + /** + * if this paprameter is set true in the Transport sender configuration. + * sender will use message source specific parameters as destination parameters when sending the message + * the default value is true. + * + * eg: in a SMPP Transport message + * SOURCE_ADDRESS_TON will be used as the DESTINATION_ADDRESS_TON is this parameter is not set to false. + */ + public static String INVERT_SOURCE_AND_DESTINATION = "invert_source_and_destination"; public static String PHONE_NUMBER = "phoneNumber"; /** diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPDispatcher.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPDispatcher.java index b1fca8e..dbc7c7b 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPDispatcher.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPDispatcher.java @@ -22,6 +22,8 @@ import org.apache.axis2.AxisFault; import org.apache.axis2.transport.sms.SMSManager; import org.apache.axis2.transport.sms.SMSMessage; +import java.util.Map; + /** * Dispatch the SMS message taken frpm the SMPP PDU to the Axis2 */ @@ -35,11 +37,11 @@ public class SMPPDispatcher{ this.manager = manager; } - void dispatch(String source , String receiver,String message) throws AxisFault { + void dispatch(String source , String receiver,String message , Map<String , Object> properties) throws AxisFault { synchronized (this){ smsMessage = new SMSMessage(source ,receiver, message , SMSMessage.IN_MESSAGE); - + smsMessage.getProperties().putAll(properties); } manager.dispatchToAxis2(smsMessage); } diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPImplManager.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPImplManager.java index 5c703ba..8953346 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPImplManager.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPImplManager.java @@ -54,6 +54,18 @@ public class SMPPImplManager implements SMSImplManager { private SMPPSession outSession; private static TimeFormatter timeFormatter = new AbsoluteTimeFormatter(); + + /** + * SMPP implementation Constents + */ + public static String SOURCE_ADDRESS_TON = "source_address_ton"; + public static String SOURCE_ADDRESS_NPI = "source_address_npi"; + + public static String DESTINATION_ADDRESS_TON = "destination_address_ton"; + public static String DESTINATION_ADDRESS_NPI = "destination_address_npi"; + + + public void start() { inSession = new SMPPSession(); try { @@ -167,6 +179,11 @@ public class SMPPImplManager implements SMSImplManager { } public void sendSMS(SMSMessage sm) { + TypeOfNumber sourceTon =TypeOfNumber.UNKNOWN; + NumberingPlanIndicator sourceNpi = NumberingPlanIndicator.UNKNOWN; + + TypeOfNumber destTon = TypeOfNumber.UNKNOWN; + NumberingPlanIndicator destNpi = NumberingPlanIndicator.UNKNOWN; try { if (outSession == null) { outSession = new SMPPSession(); @@ -177,17 +194,60 @@ public class SMPPImplManager implements SMSImplManager { smppTransportOutDetails.getPassword(), smppTransportOutDetails.getSystemType(), TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null)); + log.debug("Conected and bind to " + smppTransportOutDetails.getHost()); + } + + boolean invert = true; + + if("false".equals(sm.getProperties().get(SMSTransportConstents.INVERT_SOURCE_AND_DESTINATION))){ + invert = false; + } + + if(invert) { + if(sm.getProperties().get(DESTINATION_ADDRESS_NPI) != null) { + sourceNpi = NumberingPlanIndicator.valueOf((String)sm.getProperties().get(DESTINATION_ADDRESS_NPI)); + } + + if(sm.getProperties().get(DESTINATION_ADDRESS_TON) != null) { + sourceTon = TypeOfNumber.valueOf((String)sm.getProperties().get(DESTINATION_ADDRESS_TON)); + } + if(sm.getProperties().get(SOURCE_ADDRESS_NPI) != null) { + destNpi = NumberingPlanIndicator.valueOf((String)sm.getProperties().get(SOURCE_ADDRESS_NPI)); + } + if(sm.getProperties().get(SOURCE_ADDRESS_TON) != null) { + destTon = TypeOfNumber.valueOf((String)sm.getProperties().get(SOURCE_ADDRESS_TON)); + } + + + } else { + + if(sm.getProperties().get(DESTINATION_ADDRESS_NPI) != null) { + destNpi = NumberingPlanIndicator.valueOf((String)sm.getProperties().get(DESTINATION_ADDRESS_NPI)); + } + + if(sm.getProperties().get(DESTINATION_ADDRESS_TON) != null) { + destTon = TypeOfNumber.valueOf((String)sm.getProperties().get(DESTINATION_ADDRESS_TON)); + } + + if(sm.getProperties().get(SOURCE_ADDRESS_NPI) != null) { + sourceNpi = NumberingPlanIndicator.valueOf((String)sm.getProperties().get(SOURCE_ADDRESS_NPI)); + } + + if(sm.getProperties().get(SOURCE_ADDRESS_TON) != null) { + sourceTon = TypeOfNumber.valueOf((String)sm.getProperties().get(SOURCE_ADDRESS_TON)); + } } - log.debug("Conected and bind to " + smppTransportOutDetails.getHost()); + + String messageId = outSession.submitShortMessage( "CMT", - TypeOfNumber.UNKNOWN, - NumberingPlanIndicator.UNKNOWN, + sourceTon, + sourceNpi, sm.getSender(), - TypeOfNumber.UNKNOWN, - NumberingPlanIndicator.UNKNOWN, + destTon, + destNpi, sm.getReceiver(), new ESMClass(), (byte) 0, diff --git a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPListener.java b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPListener.java index 1f3ad49..f2d3bae 100644 --- a/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPListener.java +++ b/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/smpp/SMPPListener.java @@ -29,6 +29,9 @@ import org.apache.axis2.transport.sms.SMSManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.HashMap; +import java.util.Map; + /** * Listen for the incomming SMPP messages and Start processing them */ @@ -65,9 +68,22 @@ public class SMPPListener implements MessageReceiverListener{ } } else { + Map<String , Object> properties = new HashMap<String,Object>(); + + properties.put(SMPPImplManager.SOURCE_ADDRESS_TON , + TypeOfNumber.valueOf(deliverSm.getSourceAddrTon()).toString()); + + properties.put(SMPPImplManager.SOURCE_ADDRESS_NPI , + NumberingPlanIndicator.valueOf(deliverSm.getSourceAddrNpi()).toString()); + + properties.put(SMPPImplManager.DESTINATION_ADDRESS_TON , + TypeOfNumber.valueOf(deliverSm.getDestAddrTon()).toString()); + properties.put(SMPPImplManager.DESTINATION_ADDRESS_NPI , + NumberingPlanIndicator.valueOf(deliverSm.getDestAddrNpi()).toString()); try { - new SMPPDispatcher(smsManeger).dispatch(deliverSm.getSourceAddr() ,deliverSm.getDestAddress() ,new String(deliverSm.getShortMessage())); + new SMPPDispatcher(smsManeger).dispatch(deliverSm.getSourceAddr() ,deliverSm.getDestAddress() , + new String(deliverSm.getShortMessage()), properties); } catch (AxisFault axisFault) { log.debug("Error while dispatching SMPP message" , axisFault); diff --git a/1.0.0/pom.xml b/1.0.0/pom.xml index dcd8810..76a0ece 100644 --- a/1.0.0/pom.xml +++ b/1.0.0/pom.xml @@ -43,6 +43,7 @@ <module>modules/xmpp</module> <module>modules/mail</module> <module>modules/jms</module> + <module>modules/sms</module> <module>modules/testkit</module> </modules>