use of org.apache.axis2.transport.sms.SMSMessage in project wso2-axis2-transports by wso2.
the class SMSManager method dispatchToAxis2.
/**
* Dispatch the SMS message to Axis2 Engine
* @param sms
*/
public void dispatchToAxis2(SMSMessage sms) {
try {
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);
} catch (AxisFault axisFault) {
log.debug(axisFault);
} catch (Throwable e) {
log.debug("Unknown Exception ", e);
}
}
use of org.apache.axis2.transport.sms.SMSMessage in project wso2-axis2-transports by wso2.
the class GSMDispatcher method run.
public void run() {
while (keepPolling) {
List<InboundMessage> arrayList = new ArrayList<InboundMessage>();
try {
service.readMessages(arrayList, InboundMessage.MessageClasses.UNREAD);
for (InboundMessage msg : arrayList) {
SMSMessage sms = null;
synchronized (this) {
sms = new SMSMessage(msg.getOriginator(), null, msg.getText(), SMSMessage.IN_MESSAGE);
}
smsManager.dispatchToAxis2(sms);
// delete the message form inbox
service.deleteMessage(msg);
}
} catch (Exception ex) {
log.error("Error Occured while reading messages", ex);
}
try {
Thread.sleep(pollInterval);
} catch (InterruptedException e) {
}
}
}
use of org.apache.axis2.transport.sms.SMSMessage in project wso2-axis2-transports by wso2.
the class SMPPImplManager method sendSMS.
public void sendSMS(SMSMessage sm) throws AxisFault {
TypeOfNumber sourceTon = TypeOfNumber.UNKNOWN;
NumberingPlanIndicator sourceNpi = NumberingPlanIndicator.UNKNOWN;
TypeOfNumber destTon = TypeOfNumber.UNKNOWN;
NumberingPlanIndicator destNpi = NumberingPlanIndicator.UNKNOWN;
try {
if (outSession == null) {
outSession = new SMPPSession();
outSession.setEnquireLinkTimer(smppTransportOutDetails.getEnquireLinkTimer());
outSession.setTransactionTimer(smppTransportOutDetails.getTransactionTimer());
outSession.connectAndBind(smppTransportOutDetails.getHost(), smppTransportOutDetails.getPort(), new BindParameter(BindType.BIND_TX, smppTransportOutDetails.getSystemId(), 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));
}
}
String messageId = outSession.submitShortMessage("CMT", sourceTon, sourceNpi, sm.getSender(), destTon, destNpi, sm.getReceiver(), new ESMClass(), (byte) 0, (byte) 1, timeFormatter.format(new Date()), null, new RegisteredDelivery(SMSCDeliveryReceipt.DEFAULT), (byte) 0, new GeneralDataCoding(false, false, MessageClass.CLASS1, Alphabet.ALPHA_DEFAULT), (byte) 0, sm.getContent().getBytes());
log.debug("Message Submited with id" + messageId);
} catch (Exception e) {
this.outSession = null;
throw new AxisFault(e.getMessage(), e);
}
}
use of org.apache.axis2.transport.sms.SMSMessage in project wso2-axis2-transports by wso2.
the class DefaultSMSMessageBuilderImpl method buildMessaage.
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(":");
// may be can add feature to send message format for a request like ????
if (parts.length < 2) {
throw new InvalidMessageFormatException("format must be \"service_name \" : \"opration_name\" : " + "\"parm_1=val_1\" :..:\"param_n = val_n\"");
} else {
AxisConfiguration repo = configurationContext.getAxisConfiguration();
MessageContext messageContext = configurationContext.createMessageContext();
parts = trimSplited(parts);
try {
AxisService axisService = repo.getService(parts[0]);
if (axisService == null) {
throw new InvalidMessageFormatException("Service : " + parts[0] + "does not exsist");
} else {
messageContext.setAxisService(axisService);
AxisOperation axisOperation = axisService.getOperation(new QName(parts[1]));
if (axisOperation == null) {
throw new InvalidMessageFormatException("Operation: " + parts[1] + " does not exsist");
}
messageContext.setAxisOperation(axisOperation);
messageContext.setAxisMessage(axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
Map params = getParams(parts, 2);
SOAPEnvelope soapEnvelope = createSoapEnvelope(messageContext, params);
messageContext.setServerSide(true);
messageContext.setEnvelope(soapEnvelope);
TransportInDescription in = configurationContext.getAxisConfiguration().getTransportIn("sms");
TransportOutDescription out = configurationContext.getAxisConfiguration().getTransportOut("sms");
messageContext.setIncomingTransportName("sms");
messageContext.setProperty(SMSTransportConstents.SEND_TO, sender);
messageContext.setProperty(SMSTransportConstents.DESTINATION, receiver);
messageContext.setTransportIn(in);
messageContext.setTransportOut(out);
handleSMSProperties(msg, messageContext);
return messageContext;
}
} catch (AxisFault axisFault) {
log.debug("[DefaultSMSMessageBuilderImpl] Error while extracting the axis2Service \n" + axisFault);
}
}
return null;
}
use of org.apache.axis2.transport.sms.SMSMessage in project wso2-axis2-transports by wso2.
the class SMSManager method sendSMS.
/**
* send a SMS form the message comming form the Axis2 Engine
* @param messageContext that is comming form the Axis2
*/
public void sendSMS(MessageContext messageContext) throws AxisFault {
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);
throw new AxisFault(e.getMessage(), e);
}
}
Aggregations