Search in sources :

Example 1 with Transaction

use of javax.sip.Transaction in project Spark by igniterealtime.

the class CallProcessing method sayOK.

// busy here
// ------------------ say ok
public void sayOK(int callID, String sdpContent) throws CommunicationsException {
    Call call = callDispatcher.getCall(callID);
    if (call == null) {
        throw new CommunicationsException("Failed to find call with id=" + callID);
    }
    if (!call.isIncoming())
        return;
    Dialog dialog = call.getDialog();
    if (dialog == null) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to extract call's associated dialog! Ending Call!");
    }
    Transaction transaction = dialog.getFirstTransaction();
    if (transaction == null || !dialog.isServer()) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to extract a ServerTransaction " + "from the call's associated dialog!");
    }
    ServerTransaction serverTransaction = (ServerTransaction) transaction;
    Response ok = null;
    try {
        ok = sipManCallback.messageFactory.createResponse(Response.OK, dialog.getFirstTransaction().getRequest());
        sipManCallback.attachToTag(ok, dialog);
    } catch (ParseException ex) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to construct an OK response to an INVITE request", ex);
    }
    // Content
    ContentTypeHeader contentTypeHeader = null;
    try {
        // content type should be application/sdp (not applications)
        // reported by Oleg Shevchenko (Miratech)
        contentTypeHeader = sipManCallback.headerFactory.createContentTypeHeader("application", "sdp");
    } catch (ParseException ex) {
        // Shouldn't happen
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to create a content type header for the OK request", ex);
    }
    try {
        ok.setContent(sdpContent, contentTypeHeader);
    } catch (NullPointerException ex) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("No sdp data was provided for the ok response to an INVITE request!", ex);
    } catch (ParseException ex) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to parse sdp data while creating invite request!", ex);
    }
    // and should probably be removed
    if (((ToHeader) ok.getHeader(ToHeader.NAME)).getTag() == null) {
        try {
            ((ToHeader) ok.getHeader(ToHeader.NAME)).setTag(Integer.toString(dialog.hashCode()));
        } catch (ParseException ex) {
            call.setState(Call.DISCONNECTED);
            throw new CommunicationsException("Unable to set to tag", ex);
        }
    }
    ContactHeader contactHeader = sipManCallback.getContactHeader();
    ok.addHeader(contactHeader);
    try {
        serverTransaction.sendResponse(ok);
    } catch (SipException ex) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to send an OK response to an INVITE request", ex);
    } catch (InvalidArgumentException e) {
        call.setState(Call.DISCONNECTED);
        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
    }
}
Also used : ContactHeader(javax.sip.header.ContactHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) Response(javax.sip.message.Response) InvalidArgumentException(javax.sip.InvalidArgumentException) ServerTransaction(javax.sip.ServerTransaction) Transaction(javax.sip.Transaction) ClientTransaction(javax.sip.ClientTransaction) Dialog(javax.sip.Dialog) ToHeader(javax.sip.header.ToHeader) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction) SipException(javax.sip.SipException)

Example 2 with Transaction

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

the class SIPBalancerForwarder method processTimeout.

/*
     * (non-Javadoc)
     * @see javax.sip.SipListener#processTimeout(javax.sip.TimeoutEvent)
     */
public void processTimeout(TimeoutEvent timeoutEvent) {
    Transaction transaction = null;
    if (timeoutEvent.isServerTransaction()) {
        transaction = timeoutEvent.getServerTransaction();
        if (logger.isDebugEnabled()) {
            logger.debug("timeout => " + transaction.getRequest().toString());
        }
    } else {
        transaction = timeoutEvent.getClientTransaction();
        if (logger.isDebugEnabled()) {
            logger.debug("timeout => " + transaction.getRequest().toString());
        }
    }
    String callId = ((CallIdHeader) transaction.getRequest().getHeader(CallIdHeader.NAME)).getCallId();
    register.unStickSessionFromNode(callId);
}
Also used : Transaction(javax.sip.Transaction) CallIdHeader(javax.sip.header.CallIdHeader)

Example 3 with Transaction

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

the class SipProviderImpl method transactionErrorEvent.

/**
     * Invoked when an error has ocurred with a transaction. Propagate up to the
     * listeners.
     *
     * @param transactionErrorEvent
     *            Error event.
     */
public void transactionErrorEvent(SIPTransactionErrorEvent transactionErrorEvent) {
    SIPTransaction transaction = (SIPTransaction) transactionErrorEvent.getSource();
    if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TRANSPORT_ERROR) {
        // There must be a way to inform the TU here!!
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logDebug("TransportError occured on " + transaction);
        }
        // Treat this like a timeout event. (Suggestion from Christophe).
        Object errorObject = transactionErrorEvent.getSource();
        Timeout timeout = Timeout.TRANSACTION;
        TimeoutEvent ev = null;
        if (errorObject instanceof SIPServerTransaction) {
            ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
        } else {
            SIPClientTransaction clientTx = (SIPClientTransaction) errorObject;
            Hop hop = clientTx.getNextHop();
            if (sipStack.getRouter() instanceof RouterExt) {
                ((RouterExt) sipStack.getRouter()).transactionTimeout(hop);
            }
            ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
        }
        // Handling transport error like timeout
        this.handleEvent(ev, (SIPTransaction) errorObject);
    } else if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TIMEOUT_ERROR) {
        // This is a timeout event.
        Object errorObject = transactionErrorEvent.getSource();
        Timeout timeout = Timeout.TRANSACTION;
        TimeoutEvent ev = null;
        if (errorObject instanceof SIPServerTransaction) {
            ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
        } else {
            SIPClientTransaction clientTx = (SIPClientTransaction) errorObject;
            Hop hop = clientTx.getNextHop();
            if (sipStack.getRouter() instanceof RouterExt) {
                ((RouterExt) sipStack.getRouter()).transactionTimeout(hop);
            }
            ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
        }
        this.handleEvent(ev, (SIPTransaction) errorObject);
    } else if (transactionErrorEvent.getErrorID() == SIPTransactionErrorEvent.TIMEOUT_RETRANSMIT) {
        // This is a timeout retransmit event.
        // We should never get this if retransmit filter is
        // enabled (ie. in that case the stack should handle.
        // all retransmits.
        Object errorObject = transactionErrorEvent.getSource();
        Transaction tx = (Transaction) errorObject;
        if (tx.getDialog() != null)
            InternalErrorHandler.handleException("Unexpected event !", this.sipStack.getStackLogger());
        Timeout timeout = Timeout.RETRANSMIT;
        TimeoutEvent ev = null;
        if (errorObject instanceof SIPServerTransaction) {
            ev = new TimeoutEvent(this, (ServerTransaction) errorObject, timeout);
        } else {
            ev = new TimeoutEvent(this, (ClientTransaction) errorObject, timeout);
        }
        this.handleEvent(ev, (SIPTransaction) errorObject);
    }
}
Also used : SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) TimeoutEvent(javax.sip.TimeoutEvent) ServerTransaction(javax.sip.ServerTransaction) Transaction(javax.sip.Transaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) SIPTransaction(gov.nist.javax.sip.stack.SIPTransaction) ClientTransaction(javax.sip.ClientTransaction) RouterExt(gov.nist.javax.sip.address.RouterExt) Timeout(javax.sip.Timeout) SIPTransaction(gov.nist.javax.sip.stack.SIPTransaction) SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) ClientTransaction(javax.sip.ClientTransaction) Hop(javax.sip.address.Hop) EventObject(java.util.EventObject) ServerTransaction(javax.sip.ServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction)

Example 4 with Transaction

use of javax.sip.Transaction in project camel by apache.

the class SipSubscriptionListener method processResponse.

public void processResponse(ResponseEvent responseReceivedEvent) {
    LOG.debug("Response received at Subscriber");
    Response response = responseReceivedEvent.getResponse();
    Transaction clientTransactionId = responseReceivedEvent.getClientTransaction();
    LOG.debug("Response received with client transaction id {}:{}", clientTransactionId, response.getStatusCode());
    if (clientTransactionId == null) {
        if (LOG.isWarnEnabled()) {
            LOG.warn("Stray response -- dropping");
        }
        return;
    }
}
Also used : Response(javax.sip.message.Response) ServerTransaction(javax.sip.ServerTransaction) Transaction(javax.sip.Transaction)

Example 5 with Transaction

use of javax.sip.Transaction in project Spark by igniterealtime.

the class CallProcessing method sayInternalError.

// answer call
// ------------------ Internal Error
void sayInternalError(int callID) throws CommunicationsException {
    Call call = callDispatcher.getCall(callID);
    if (call == null) {
        throw new CommunicationsException("Failed to find call with id=" + callID);
    }
    Dialog dialog = call.getDialog();
    if (dialog == null) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to extract call's associated dialog! Ending Call!");
    }
    Transaction transaction = dialog.getFirstTransaction();
    if (transaction == null || !dialog.isServer()) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to extract a transaction from the call's associated dialog!");
    }
    ServerTransaction serverTransaction = (ServerTransaction) transaction;
    Response internalError = null;
    try {
        internalError = sipManCallback.messageFactory.createResponse(Response.SERVER_INTERNAL_ERROR, dialog.getFirstTransaction().getRequest());
        sipManCallback.attachToTag(internalError, dialog);
    } catch (ParseException ex) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to construct an OK response to an INVITE request", ex);
    }
    ContactHeader contactHeader = sipManCallback.getContactHeader();
    internalError.addHeader(contactHeader);
    try {
        serverTransaction.sendResponse(internalError);
    } catch (SipException ex) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to send an OK response to an INVITE request", ex);
    } catch (InvalidArgumentException e) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to send an OK response to an INVITE request", e);
    }
}
Also used : Response(javax.sip.message.Response) ContactHeader(javax.sip.header.ContactHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) ServerTransaction(javax.sip.ServerTransaction) Transaction(javax.sip.Transaction) ClientTransaction(javax.sip.ClientTransaction) Dialog(javax.sip.Dialog) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction) SipException(javax.sip.SipException)

Aggregations

Transaction (javax.sip.Transaction)8 ServerTransaction (javax.sip.ServerTransaction)6 ClientTransaction (javax.sip.ClientTransaction)5 Response (javax.sip.message.Response)4 ParseException (java.text.ParseException)3 InvalidArgumentException (javax.sip.InvalidArgumentException)3 SipException (javax.sip.SipException)3 Dialog (javax.sip.Dialog)2 CallIdHeader (javax.sip.header.CallIdHeader)2 ContactHeader (javax.sip.header.ContactHeader)2 Request (javax.sip.message.Request)2 RouterExt (gov.nist.javax.sip.address.RouterExt)1 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)1 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)1 SIPTransaction (gov.nist.javax.sip.stack.SIPTransaction)1 EventObject (java.util.EventObject)1 Timeout (javax.sip.Timeout)1 TimeoutEvent (javax.sip.TimeoutEvent)1 Hop (javax.sip.address.Hop)1 ContentTypeHeader (javax.sip.header.ContentTypeHeader)1