Search in sources :

Example 76 with Response

use of javax.sip.message.Response in project jain-sip.ha by RestComm.

the class SimpleStatefulProxy method forwardResponse.

/**
 * @param responseEvent
 * @throws InvalidArgumentException
 */
@SuppressWarnings("unchecked")
private void forwardResponse(Response receivedResponse) throws SipException, InvalidArgumentException {
    System.out.println("Forwarding " + receivedResponse);
    final ServerTransaction origServerTransaction = this.getServerTransaction();
    Response forgedResponse = (Response) receivedResponse.clone();
    forgedResponse.removeFirst(ViaHeader.NAME);
    origServerTransaction.sendResponse(forgedResponse);
}
Also used : Response(javax.sip.message.Response) ServerTransaction(javax.sip.ServerTransaction)

Example 77 with Response

use of javax.sip.message.Response in project smscgateway by RestComm.

the class TxSipServerSbb method onMESSAGE.

// *********
// SIP Event Handlers
public void onMESSAGE(javax.sip.RequestEvent event, ActivityContextInterface aci) {
    if (this.logger.isFineEnabled()) {
        this.logger.fine("onMESSAGE " + event);
    }
    Sip sip = sipManagement.getSipByName(SipManagement.SIP_NAME);
    try {
        final Request request = event.getRequest();
        byte[] message = request.getRawContent();
        final ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
        final String toUser = ((SipUri) toHeader.getAddress().getURI()).getUser();
        final FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
        final String fromUser = ((SipUri) fromHeader.getAddress().getURI()).getUser();
        // Persist this message
        TargetAddress ta = this.createDestTargetAddress(toUser, sip.getNetworkId());
        byte[] udh = null;
        Header udhHeader = request.getHeader(SipXHeaders.XSmsUdh);
        if (udhHeader != null) {
            udh = this.hexStringToByteArray(((SIPHeader) udhHeader).getValue());
        }
        Header codingHeader = request.getHeader(SipXHeaders.XSmsCoding);
        DataCodingSchemeImpl codingSchme = dcsGsm7;
        if (codingHeader != null) {
            int dcs = Integer.parseInt(((SIPHeader) codingHeader).getValue());
            codingSchme = this.createDataCodingScheme(dcs);
        }
        Date validityPeriod = null;
        Header validityHeader = request.getHeader(SipXHeaders.XSmsValidty);
        if (validityHeader != null) {
            try {
                validityPeriod = MessageUtil.parseDate(((SIPHeader) validityHeader).getValue());
            } catch (ParseException e) {
                logger.severe("ParseException when parsing ValidityPeriod field: " + e.getMessage(), e);
                if (smscPropertiesManagement.isGenerateRejectionCdr()) {
                    generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e.getMessage(), true);
                }
                ServerTransaction serverTransaction = event.getServerTransaction();
                Response res;
                try {
                    res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
                    event.getServerTransaction().sendResponse(res);
                } catch (Exception e1) {
                    this.logger.severe("Exception while trying to send 500 response to sip", e1);
                }
                return;
            }
        }
        // Registered Delivery
        int regDeliveryInt = 0;
        Header regDeliveryHeader = request.getHeader(SipXHeaders.XRegDelivery);
        if (regDeliveryHeader != null) {
            regDeliveryInt = Integer.parseInt(((SIPHeader) regDeliveryHeader).getValue());
        }
        Sms sms = null;
        try {
            sms = this.createSmsEvent(fromUser, message, ta, persistence, udh, codingSchme, validityPeriod, regDeliveryInt, sip.getNetworkId());
            this.processSms(sms, persistence);
        } catch (SmscProcessingException e1) {
            if (!e1.isSkipErrorLogging()) {
                if (e1.isIsWarning()) {
                    this.logger.warning(e1.getMessage());
                } else {
                    this.logger.severe(e1.getMessage(), e1);
                }
                smscStatAggregator.updateMsgInFailedAll();
            }
            if (smscPropertiesManagement.isGenerateRejectionCdr() && !e1.isMessageRejectCdrCreated()) {
                if (sms != null) {
                    generateCDR(sms, CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), false, true);
                } else {
                    generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
                }
            }
            ServerTransaction serverTransaction = event.getServerTransaction();
            Response res;
            try {
                res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
                event.getServerTransaction().sendResponse(res);
            } catch (Exception e) {
                this.logger.severe("Exception while trying to send Ok response to sip", e);
            }
            return;
        } catch (Throwable e1) {
            this.logger.severe("Exception while processing a message from sip", e1);
            smscStatAggregator.updateMsgInFailedAll();
            if (smscPropertiesManagement.isGenerateRejectionCdr()) {
                generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
            }
            ServerTransaction serverTransaction = event.getServerTransaction();
            Response res;
            try {
                // TODO: we possibly need to response ERROR message to sip
                res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
                event.getServerTransaction().sendResponse(res);
            } catch (Exception e) {
                this.logger.severe("Exception while trying to send Ok response to sip", e);
            }
            return;
        }
        ServerTransaction serverTransaction = event.getServerTransaction();
        Response res;
        try {
            res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
            event.getServerTransaction().sendResponse(res);
        } catch (Exception e) {
            this.logger.severe("Exception while trying to send Ok response to sip", e);
        }
    } catch (Exception e) {
        this.logger.severe("Error while trying to process received the SMS " + event, e);
    }
}
Also used : FromHeader(javax.sip.header.FromHeader) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) Request(javax.sip.message.Request) TargetAddress(org.mobicents.smsc.library.TargetAddress) SipUri(gov.nist.javax.sip.address.SipUri) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) Date(java.util.Date) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) ParseException(java.text.ParseException) Response(javax.sip.message.Response) ToHeader(javax.sip.header.ToHeader) FromHeader(javax.sip.header.FromHeader) SIPHeader(gov.nist.javax.sip.header.SIPHeader) Header(javax.sip.header.Header) SIPHeader(gov.nist.javax.sip.header.SIPHeader) ToHeader(javax.sip.header.ToHeader) Sms(org.mobicents.smsc.library.Sms) Sip(org.mobicents.smsc.domain.Sip) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction)

Aggregations

Response (javax.sip.message.Response)77 ParseException (java.text.ParseException)42 SipException (javax.sip.SipException)41 InvalidArgumentException (javax.sip.InvalidArgumentException)32 Request (javax.sip.message.Request)28 ServerTransaction (javax.sip.ServerTransaction)22 TransactionUnavailableException (javax.sip.TransactionUnavailableException)20 Dialog (javax.sip.Dialog)18 ToHeader (javax.sip.header.ToHeader)17 Test (org.junit.Test)17 ListeningPoint (javax.sip.ListeningPoint)16 ContactHeader (javax.sip.header.ContactHeader)16 SipURI (javax.sip.address.SipURI)13 SIPResponse (gov.nist.javax.sip.message.SIPResponse)12 ClientTransaction (javax.sip.ClientTransaction)12 SipProvider (javax.sip.SipProvider)11 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)11 ViaHeader (javax.sip.header.ViaHeader)11 FromHeader (javax.sip.header.FromHeader)10 CSeqHeader (javax.sip.header.CSeqHeader)9