Search in sources :

Example 1 with TransactionDoesNotExistException

use of javax.sip.TransactionDoesNotExistException in project XobotOS by xamarin.

the class SIPDialog method sendRequest.

public void sendRequest(ClientTransaction clientTransactionId, boolean allowInterleaving) throws TransactionDoesNotExistException, SipException {
    if ((!allowInterleaving) && clientTransactionId.getRequest().getMethod().equals(Request.INVITE)) {
        new Thread((new ReInviteSender(clientTransactionId))).start();
        return;
    }
    SIPRequest dialogRequest = ((SIPClientTransaction) clientTransactionId).getOriginalRequest();
    if (sipStack.isLoggingEnabled())
        sipStack.getStackLogger().logDebug("dialog.sendRequest " + " dialog = " + this + "\ndialogRequest = \n" + dialogRequest);
    if (clientTransactionId == null)
        throw new NullPointerException("null parameter");
    if (dialogRequest.getMethod().equals(Request.ACK) || dialogRequest.getMethod().equals(Request.CANCEL))
        throw new SipException("Bad Request Method. " + dialogRequest.getMethod());
    // JvB: added, allow re-sending of BYE after challenge
    if (byeSent && isTerminatedOnBye() && !dialogRequest.getMethod().equals(Request.BYE)) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("BYE already sent for " + this);
        throw new SipException("Cannot send request; BYE already sent");
    }
    if (dialogRequest.getTopmostVia() == null) {
        Via via = ((SIPClientTransaction) clientTransactionId).getOutgoingViaHeader();
        dialogRequest.addHeader(via);
    }
    if (!this.getCallId().getCallId().equalsIgnoreCase(dialogRequest.getCallId().getCallId())) {
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logError("CallID " + this.getCallId());
            sipStack.getStackLogger().logError("RequestCallID = " + dialogRequest.getCallId().getCallId());
            sipStack.getStackLogger().logError("dialog =  " + this);
        }
        throw new SipException("Bad call ID in request");
    }
    // Set the dialog back pointer.
    ((SIPClientTransaction) clientTransactionId).setDialog(this, this.dialogId);
    this.addTransaction((SIPTransaction) clientTransactionId);
    // Enable the retransmission filter for the transaction
    ((SIPClientTransaction) clientTransactionId).isMapped = true;
    From from = (From) dialogRequest.getFrom();
    To to = (To) dialogRequest.getTo();
    // tag assignment is OK.
    if (this.getLocalTag() != null && from.getTag() != null && !from.getTag().equals(this.getLocalTag()))
        throw new SipException("From tag mismatch expecting  " + this.getLocalTag());
    if (this.getRemoteTag() != null && to.getTag() != null && !to.getTag().equals(this.getRemoteTag())) {
        if (sipStack.isLoggingEnabled())
            this.sipStack.getStackLogger().logWarning("To header tag mismatch expecting " + this.getRemoteTag());
    }
    /*
         * The application is sending a NOTIFY before sending the response of the dialog.
         */
    if (this.getLocalTag() == null && dialogRequest.getMethod().equals(Request.NOTIFY)) {
        if (!this.getMethod().equals(Request.SUBSCRIBE))
            throw new SipException("Trying to send NOTIFY without SUBSCRIBE Dialog!");
        this.setLocalTag(from.getTag());
    }
    try {
        if (this.getLocalTag() != null)
            from.setTag(this.getLocalTag());
        if (this.getRemoteTag() != null)
            to.setTag(this.getRemoteTag());
    } catch (ParseException ex) {
        InternalErrorHandler.handleException(ex);
    }
    Hop hop = ((SIPClientTransaction) clientTransactionId).getNextHop();
    if (sipStack.isLoggingEnabled()) {
        sipStack.getStackLogger().logDebug("Using hop = " + hop.getHost() + " : " + hop.getPort());
    }
    try {
        MessageChannel messageChannel = sipStack.createRawMessageChannel(this.getSipProvider().getListeningPoint(hop.getTransport()).getIPAddress(), this.firstTransactionPort, hop);
        MessageChannel oldChannel = ((SIPClientTransaction) clientTransactionId).getMessageChannel();
        // Remove this from the connection cache if it is in the
        // connection
        // cache and is not yet active.
        oldChannel.uncache();
        // Not configured to cache client connections.
        if (!sipStack.cacheClientConnections) {
            oldChannel.useCount--;
            if (sipStack.isLoggingEnabled())
                sipStack.getStackLogger().logDebug("oldChannel: useCount " + oldChannel.useCount);
        }
        if (messageChannel == null) {
            /*
                 * At this point the procedures of 8.1.2 and 12.2.1.1 of RFC3261 have been tried
                 * but the resulting next hop cannot be resolved (recall that the exception thrown
                 * is caught and ignored in SIPStack.createMessageChannel() so we end up here with
                 * a null messageChannel instead of the exception handler below). All else
                 * failing, try the outbound proxy in accordance with 8.1.2, in particular: This
                 * ensures that outbound proxies that do not add Record-Route header field values
                 * will drop out of the path of subsequent requests. It allows endpoints that
                 * cannot resolve the first Route URI to delegate that task to an outbound proxy.
                 * 
                 * if one considers the 'first Route URI' of a request constructed according to
                 * 12.2.1.1 to be the request URI when the route set is empty.
                 */
            if (sipStack.isLoggingEnabled())
                sipStack.getStackLogger().logDebug("Null message channel using outbound proxy !");
            Hop outboundProxy = sipStack.getRouter(dialogRequest).getOutboundProxy();
            if (outboundProxy == null)
                throw new SipException("No route found! hop=" + hop);
            messageChannel = sipStack.createRawMessageChannel(this.getSipProvider().getListeningPoint(outboundProxy.getTransport()).getIPAddress(), this.firstTransactionPort, outboundProxy);
            if (messageChannel != null)
                ((SIPClientTransaction) clientTransactionId).setEncapsulatedChannel(messageChannel);
        } else {
            ((SIPClientTransaction) clientTransactionId).setEncapsulatedChannel(messageChannel);
            if (sipStack.isLoggingEnabled()) {
                sipStack.getStackLogger().logDebug("using message channel " + messageChannel);
            }
        }
        if (messageChannel != null)
            messageChannel.useCount++;
        // See if we need to release the previously mapped channel.
        if ((!sipStack.cacheClientConnections) && oldChannel != null && oldChannel.useCount <= 0)
            oldChannel.close();
    } catch (Exception ex) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logException(ex);
        throw new SipException("Could not create message channel", ex);
    }
    try {
        // Increment before setting!!
        localSequenceNumber++;
        dialogRequest.getCSeq().setSeqNumber(getLocalSeqNumber());
    } catch (InvalidArgumentException ex) {
        sipStack.getStackLogger().logFatalError(ex.getMessage());
    }
    try {
        ((SIPClientTransaction) clientTransactionId).sendMessage(dialogRequest);
        /*
             * Note that if the BYE is rejected then the Dialog should bo back to the ESTABLISHED
             * state so we only set state after successful send.
             */
        if (dialogRequest.getMethod().equals(Request.BYE)) {
            this.byeSent = true;
            /*
                 * Dialog goes into TERMINATED state as soon as BYE is sent. ISSUE 182.
                 */
            if (isTerminatedOnBye()) {
                this.setState(DialogState._TERMINATED);
            }
        }
    } catch (IOException ex) {
        throw new SipException("error sending message", ex);
    }
}
Also used : Hop(javax.sip.address.Hop) From(gov.nist.javax.sip.header.From) IOException(java.io.IOException) SIPRequest(gov.nist.javax.sip.message.SIPRequest) DialogDoesNotExistException(javax.sip.DialogDoesNotExistException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) ObjectInUseException(javax.sip.ObjectInUseException) SipException(javax.sip.SipException) IOException(java.io.IOException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) Via(gov.nist.javax.sip.header.Via) InvalidArgumentException(javax.sip.InvalidArgumentException) To(gov.nist.javax.sip.header.To) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Example 2 with TransactionDoesNotExistException

use of javax.sip.TransactionDoesNotExistException in project load-balancer by RestComm.

the class TestSipListener method sendBye.

/**
 * @throws SipException
 * @throws TransactionUnavailableException
 * @throws TransactionDoesNotExistException
 */
public void sendBye(final Dialog dialog) throws SipException, TransactionUnavailableException, TransactionDoesNotExistException {
    Thread th = new Thread() {

        public void run() {
            try {
                if (sendByeInNewThread)
                    Thread.sleep(600);
                Request byeRequest = dialog.createRequest(Request.BYE);
                URI uri = ((FromHeader) byeRequest.getHeader(FromHeader.NAME)).getAddress().getURI();
                if (uri.isSipURI()) {
                    ((SipURI) uri).removeParameter("fromParam");
                }
                ClientTransaction ct = sipProvider.getNewClientTransaction(byeRequest);
                logger.info("Sending BYE " + byeRequest);
                if (!sendSubsequentRequestsThroughSipProvider) {
                    dialog.sendRequest(ct);
                } else {
                    sipProvider.sendRequest(byeRequest);
                }
                byeSent = true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    if (sendByeInNewThread) {
        th.start();
    } else {
        th.run();
    }
}
Also used : ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) TransactionUnavailableException(javax.sip.TransactionUnavailableException)

Aggregations

ParseException (java.text.ParseException)2 InvalidArgumentException (javax.sip.InvalidArgumentException)2 SipException (javax.sip.SipException)2 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)2 From (gov.nist.javax.sip.header.From)1 To (gov.nist.javax.sip.header.To)1 Via (gov.nist.javax.sip.header.Via)1 SIPRequest (gov.nist.javax.sip.message.SIPRequest)1 IOException (java.io.IOException)1 ClientTransaction (javax.sip.ClientTransaction)1 DialogDoesNotExistException (javax.sip.DialogDoesNotExistException)1 ObjectInUseException (javax.sip.ObjectInUseException)1 TransactionUnavailableException (javax.sip.TransactionUnavailableException)1 Hop (javax.sip.address.Hop)1 SipURI (javax.sip.address.SipURI)1 URI (javax.sip.address.URI)1 Request (javax.sip.message.Request)1