Search in sources :

Example 6 with Transaction

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

the class SipManager method processTimeout.

public void processTimeout(TimeoutEvent transactionTimeOutEvent) {
    Transaction transaction;
    if (transactionTimeOutEvent.isServerTransaction()) {
        transaction = transactionTimeOutEvent.getServerTransaction();
    } else {
        transaction = transactionTimeOutEvent.getClientTransaction();
    }
    Request request = transaction.getRequest();
    if (request.getMethod().equals(Request.REGISTER)) {
        registerProcessing.processTimeout(transaction, request);
    } else if (request.getMethod().equals(Request.INVITE)) {
        callProcessing.processTimeout(transaction, request);
    } else {
    // Just show an error for now
    }
}
Also used : ClientTransaction(javax.sip.ClientTransaction) ServerTransaction(javax.sip.ServerTransaction) Transaction(javax.sip.Transaction) Request(javax.sip.message.Request)

Example 7 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)

Example 8 with Transaction

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

the class CallProcessing method processCancel.

void processCancel(ServerTransaction serverTransaction, Request cancelRequest) {
    if (!serverTransaction.getDialog().getFirstTransaction().getRequest().getMethod().equals(Request.INVITE)) {
        return;
    }
    // find the call
    Call call = callDispatcher.findCall(serverTransaction.getDialog());
    if (call == null) {
        sipManCallback.fireUnknownMessageReceived(cancelRequest);
        return;
    }
    // change status
    call.setState(Call.DISCONNECTED);
    // (report and fix by Ranga)
    try {
        Response ok = sipManCallback.messageFactory.createResponse(Response.OK, cancelRequest);
        sipManCallback.attachToTag(ok, call.getDialog());
        serverTransaction.sendResponse(ok);
    } catch (ParseException ex) {
        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create an OK Response to an CANCEL request.", ex));
    } catch (SipException ex) {
        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send an OK Response to an CANCEL request.", ex));
    } catch (InvalidArgumentException e) {
        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
    }
    try {
        // stop the invite transaction as well
        Transaction tran = call.getDialog().getFirstTransaction();
        // filtered by the stack but it doesn't hurt checking anyway
        if (!(tran instanceof ServerTransaction)) {
            sipManCallback.fireCommunicationsError(new CommunicationsException("Received a misplaced CANCEL request!"));
            return;
        }
        ServerTransaction inviteTran = (ServerTransaction) tran;
        Request invite = call.getDialog().getFirstTransaction().getRequest();
        Response requestTerminated = sipManCallback.messageFactory.createResponse(Response.REQUEST_TERMINATED, invite);
        sipManCallback.attachToTag(requestTerminated, call.getDialog());
        inviteTran.sendResponse(requestTerminated);
    } catch (ParseException ex) {
        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create a REQUEST_TERMINATED Response to an INVITE request.", ex));
    } catch (SipException ex) {
        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send an REQUEST_TERMINATED Response to an INVITE request.", ex));
    } catch (InvalidArgumentException e) {
        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
    }
}
Also used : Response(javax.sip.message.Response) InvalidArgumentException(javax.sip.InvalidArgumentException) ServerTransaction(javax.sip.ServerTransaction) Transaction(javax.sip.Transaction) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) ParseException(java.text.ParseException) SipException(javax.sip.SipException) ServerTransaction(javax.sip.ServerTransaction)

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