Search in sources :

Example 6 with ServerTransaction

use of javax.sip.ServerTransaction 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 7 with ServerTransaction

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

the class TestSipListener method processRegister.

private void processRegister(Request request, ServerTransaction serverTransactionId) {
    try {
        registerReceived = request;
        ServerTransaction serverTransaction = serverTransactionId == null ? sipProvider.getNewServerTransaction(request) : serverTransactionId;
        lastRegisterCSeqNumber = ((CSeqHeader) request.getHeader("CSeq")).getSeqNumber();
        Response okResponse = protocolObjects.messageFactory.createResponse(Response.OK, request);
        ToHeader toHeader = (ToHeader) okResponse.getHeader(ToHeader.NAME);
        if (toHeader.getTag() == null) {
            toHeader.setTag(Integer.toString(new Random().nextInt(10000000)));
        }
        // okResponse.addHeader(contactHeader);
        serverTransaction.sendResponse(okResponse);
    } catch (Exception ex) {
        ex.printStackTrace();
        logger.error("error sending OK response to message", ex);
    }
}
Also used : Response(javax.sip.message.Response) Random(java.util.Random) ReferToHeader(javax.sip.header.ReferToHeader) ToHeader(javax.sip.header.ToHeader) ServerTransaction(javax.sip.ServerTransaction) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) TransactionUnavailableException(javax.sip.TransactionUnavailableException)

Example 8 with ServerTransaction

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

the class Shootist method processRequest.

public void processRequest(RequestEvent requestReceivedEvent) {
    Request request = requestReceivedEvent.getRequest();
    requests.add(request);
    ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
    if (serverTransactionId == null) {
        try {
            serverTransactionId = sipProvider.getNewServerTransaction(request);
        } catch (TransactionAlreadyExistsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransactionUnavailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    System.out.println("\n\nRequest " + request.getMethod() + " received at " + sipStack.getStackName() + " with server transaction id " + serverTransactionId);
    if (request.getMethod().equals(Request.INVITE)) {
        processInvite(request, serverTransactionId);
    } else if (request.getMethod().equals(Request.BYE)) {
        processBye(request, serverTransactionId);
    } else if (request.getMethod().equals(Request.ACK)) {
        processAck(request, serverTransactionId);
    } else {
        try {
            serverTransactionId.sendResponse(messageFactory.createResponse(200, request));
        } catch (Exception e) {
            e.printStackTrace();
            fail("Unxepcted exception ");
        }
    }
}
Also used : Request(javax.sip.message.Request) TransactionAlreadyExistsException(javax.sip.TransactionAlreadyExistsException) TransactionUnavailableException(javax.sip.TransactionUnavailableException) ServerTransaction(javax.sip.ServerTransaction) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) TransactionAlreadyExistsException(javax.sip.TransactionAlreadyExistsException) PeerUnavailableException(javax.sip.PeerUnavailableException) SipException(javax.sip.SipException) TransactionUnavailableException(javax.sip.TransactionUnavailableException)

Example 9 with ServerTransaction

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

the class Shootist method processRequest.

public void processRequest(RequestEvent requestReceivedEvent) {
    Request request = requestReceivedEvent.getRequest();
    ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();
    if (serverTransactionId == null) {
        try {
            serverTransactionId = sipProvider.getNewServerTransaction(request);
        } catch (TransactionAlreadyExistsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TransactionUnavailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    System.out.println("\n\nRequest " + request.getMethod() + " received at " + sipStack.getStackName() + " with server transaction id " + serverTransactionId);
    if (request.getMethod().equals(Request.INVITE)) {
        processInvite(request, serverTransactionId);
    } else if (request.getMethod().equals(Request.BYE)) {
        processBye(request, serverTransactionId);
    } else if (request.getMethod().equals(Request.ACK)) {
        processAck(request, serverTransactionId);
    } else {
        try {
            serverTransactionId.sendResponse(messageFactory.createResponse(200, request));
        } catch (Exception e) {
            e.printStackTrace();
            fail("Unxepcted exception ");
        }
    }
}
Also used : Request(javax.sip.message.Request) TransactionAlreadyExistsException(javax.sip.TransactionAlreadyExistsException) TransactionUnavailableException(javax.sip.TransactionUnavailableException) ServerTransaction(javax.sip.ServerTransaction) TransactionAlreadyExistsException(javax.sip.TransactionAlreadyExistsException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException) SipException(javax.sip.SipException) TransactionUnavailableException(javax.sip.TransactionUnavailableException)

Example 10 with ServerTransaction

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

the class TestSipListener method processPublish.

private void processPublish(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    try {
        SipProvider sipProvider = (SipProvider) requestEvent.getSource();
        Request request = requestEvent.getRequest();
        logger.info("shootist:  got a publish . ServerTxId = " + serverTransactionId);
        ServerTransaction st = requestEvent.getServerTransaction();
        if (st == null) {
            st = sipProvider.getNewServerTransaction(request);
        }
        inviteServerTid = st;
        Dialog dialog = st.getDialog();
        this.dialogCount++;
        this.dialog = dialog;
        logger.info("Shootme: dialog = " + dialog);
        if (request.getRawContent() != null) {
            this.lastMessageContent = new String(request.getRawContent());
            allMessagesContent.add(new String(lastMessageContent));
        }
        SIPIfMatchHeader sipIfMatchHeader = (SIPIfMatchHeader) request.getHeader(SIPIfMatchHeader.NAME);
        boolean sipIfMatchFound = true;
        if (sipIfMatchHeader != null && sipIfMatchHeader.getETag() != null && !sipIfMatchHeader.getETag().equals(sipETag)) {
            sipIfMatchFound = false;
        }
        if (sipIfMatchFound) {
            Response response = protocolObjects.messageFactory.createResponse(200, request);
            sipETag = Integer.toString(new Random().nextInt(10000000));
            SIPETagHeader sipTagHeader = protocolObjects.headerFactory.createSIPETagHeader(sipETag);
            response.addHeader(sipTagHeader);
            response.addHeader(request.getHeader(ExpiresHeader.NAME));
            st.sendResponse(response);
            logger.info("shootist:  Sending OK.");
        } else {
            Response response = protocolObjects.messageFactory.createResponse(500, request);
            serverTransactionId.sendResponse(response);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Response(javax.sip.message.Response) Random(java.util.Random) SIPETagHeader(javax.sip.header.SIPETagHeader) Dialog(javax.sip.Dialog) Request(javax.sip.message.Request) ServerTransaction(javax.sip.ServerTransaction) SIPIfMatchHeader(javax.sip.header.SIPIfMatchHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) TransactionUnavailableException(javax.sip.TransactionUnavailableException) SipProvider(javax.sip.SipProvider)

Aggregations

ServerTransaction (javax.sip.ServerTransaction)29 Response (javax.sip.message.Response)21 SipException (javax.sip.SipException)20 Request (javax.sip.message.Request)20 ParseException (java.text.ParseException)19 InvalidArgumentException (javax.sip.InvalidArgumentException)17 TransactionUnavailableException (javax.sip.TransactionUnavailableException)10 ToHeader (javax.sip.header.ToHeader)10 Dialog (javax.sip.Dialog)9 ContactHeader (javax.sip.header.ContactHeader)9 ClientTransaction (javax.sip.ClientTransaction)7 SipProvider (javax.sip.SipProvider)7 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)7 FromHeader (javax.sip.header.FromHeader)6 ReferToHeader (javax.sip.header.ReferToHeader)6 ViaHeader (javax.sip.header.ViaHeader)6 Random (java.util.Random)5 SipURI (javax.sip.address.SipURI)5 ContentTypeHeader (javax.sip.header.ContentTypeHeader)5 EventHeader (javax.sip.header.EventHeader)5