Search in sources :

Example 1 with SMSMessage

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);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 2 with SMSMessage

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) {
        }
    }
}
Also used : SMSMessage(org.apache.axis2.transport.sms.SMSMessage) ArrayList(java.util.ArrayList)

Example 3 with SMSMessage

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);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) BindParameter(org.jsmpp.session.BindParameter) SMPPSession(org.jsmpp.session.SMPPSession) Date(java.util.Date) NegativeResponseException(org.jsmpp.extra.NegativeResponseException) IOException(java.io.IOException) ResponseTimeoutException(org.jsmpp.extra.ResponseTimeoutException) InvalidResponseException(org.jsmpp.InvalidResponseException) PDUException(org.jsmpp.PDUException)

Example 4 with SMSMessage

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;
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) QName(javax.xml.namespace.QName) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MessageContext(org.apache.axis2.context.MessageContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with SMSMessage

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);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault)

Aggregations

AxisFault (org.apache.axis2.AxisFault)5 MessageContext (org.apache.axis2.context.MessageContext)2 SMSMessage (org.apache.axis2.transport.sms.SMSMessage)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)1 InvalidResponseException (org.jsmpp.InvalidResponseException)1 PDUException (org.jsmpp.PDUException)1 NegativeResponseException (org.jsmpp.extra.NegativeResponseException)1 ResponseTimeoutException (org.jsmpp.extra.ResponseTimeoutException)1 BindParameter (org.jsmpp.session.BindParameter)1 SMPPSession (org.jsmpp.session.SMPPSession)1 SerialModemGateway (org.smslib.modem.SerialModemGateway)1