Search in sources :

Example 26 with Response

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

the class Shootist method processInvite.

public void processInvite(Request request, ServerTransaction stx) {
    try {
        inviteRequest = request;
        Response response = messageFactory.createResponse(180, request);
        contactHeader = headerFactory.createContactHeader(addressFactory.createAddress("sip:here@127.0.0.1:5033"));
        response.addHeader(contactHeader);
        dialog = stx.getDialog();
        stx.sendResponse(response);
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        response = messageFactory.createResponse(200, request);
        contactHeader = headerFactory.createContactHeader(addressFactory.createAddress("sip:here@127.0.0.1:5033"));
        response.addHeader(contactHeader);
        dialog = stx.getDialog();
        stx.sendResponse(response);
    } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Response(javax.sip.message.Response) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Example 27 with Response

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

the class Shootist method processResponse.

public void processResponse(ResponseEvent responseReceivedEvent) {
    System.out.println("Got a response");
    Response response = (Response) responseReceivedEvent.getResponse();
    ClientTransaction tid = responseReceivedEvent.getClientTransaction();
    CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
    System.out.println("Response received : Status Code = " + response.getStatusCode() + " " + cseq);
    if (tid == null) {
        // RFC3261: MUST respond to every 2xx
        if (ackRequest != null && dialog != null) {
            System.out.println("re-sending ACK");
            try {
                dialog.sendAck(ackRequest);
            } catch (SipException se) {
                se.printStackTrace();
                fail("Unxpected exception ");
            }
        }
        return;
    }
    // If the caller is supposed to send the bye
    if (callerSendsBye && !byeTaskRunning) {
        byeTaskRunning = true;
        new Timer().schedule(new ByeTask(dialog), 4000);
    }
    System.out.println("transaction state is " + tid.getState());
    System.out.println("Dialog = " + tid.getDialog());
    System.out.println("Dialog State is " + tid.getDialog().getState());
    TestCase.assertSame("Checking dialog identity", tid.getDialog(), this.dialog);
    try {
        if (response.getStatusCode() == Response.OK) {
            if (cseq.getMethod().equals(Request.INVITE)) {
                System.out.println("Dialog after 200 OK  " + dialog);
                System.out.println("Dialog State after 200 OK  " + dialog.getState());
                Request ackRequest = dialog.createAck(cseq.getSeqNumber());
                System.out.println("Sending ACK");
                dialog.sendAck(ackRequest);
            } else if (cseq.getMethod().equals(Request.CANCEL)) {
                if (dialog.getState() == DialogState.CONFIRMED) {
                    // oops cancel went in too late. Need to hang up the
                    // dialog.
                    System.out.println("Sending BYE -- cancel went in too late !!");
                    Request byeRequest = dialog.createRequest(Request.BYE);
                    ClientTransaction ct = sipProvider.getNewClientTransaction(byeRequest);
                    dialog.sendRequest(ct);
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Response(javax.sip.message.Response) CSeqHeader(javax.sip.header.CSeqHeader) Timer(java.util.Timer) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) SipException(javax.sip.SipException) 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 28 with Response

use of javax.sip.message.Response 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)

Example 29 with Response

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

the class FromURIBasedAlgorithmTest method testCongestionControl.

@Test
public void testCongestionControl() throws Exception {
    // balancer.balancerContext.sipHeaderAffinityKeyExclusionPattern = Pattern.compile(".*sip.nexmo.com");
    for (int i = 0; i < shootists.length; i++) {
        String fromUri = "Anonymous";
        // if(i % 2 == 0) {
        // fromUri = "Restricted";
        // }
        shootists[i].sendInitial(fromUri, "sip.nexmo.com", "INVITE", null, new String[] { "User-Agent" }, new String[] { "sipx" });
        Thread.sleep(6000);
        assertFalse(servers[0].getTestSipListener().isInviteReceived());
        assertFalse(servers[1].getTestSipListener().isInviteReceived());
    // shootists[i].sendBye();
    // Thread.sleep(2000);
    }
    assertEquals(servers[0].getTestSipListener().isInviteReceived(), servers[1].getTestSipListener().isInviteReceived());
    assertEquals(servers[0].getTestSipListener().isAckReceived(), servers[1].getTestSipListener().isAckReceived());
    assertEquals(servers[0].getTestSipListener().getByeReceived(), servers[1].getTestSipListener().getByeReceived());
    for (Shootist s : shootists) {
        boolean wasRinging = false;
        boolean wasOk = false;
        for (Response res : s.responses) {
            if (res.getStatusCode() != Response.RINGING)
                wasRinging = true;
            if (res.getStatusCode() != Response.OK)
                wasOk = true;
        }
        assertFalse(wasOk);
        assertFalse(wasRinging);
    }
}
Also used : Response(javax.sip.message.Response) Shootist(org.mobicents.tools.sip.balancer.operation.Shootist) ListeningPoint(javax.sip.ListeningPoint) Test(org.junit.Test)

Example 30 with Response

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

the class FromURIBasedAlgorithmTest method testInviteFromToSameNode.

@Test
public void testInviteFromToSameNode() throws Exception {
    for (int i = 0; i < shootists.length; i++) {
        shootists[i].sendInitialInvite();
        Thread.sleep(6000);
        shootists[i].sendBye();
        Thread.sleep(2000);
    }
    assertNotEquals(servers[0].getTestSipListener().isInviteReceived(), servers[1].getTestSipListener().isInviteReceived());
    assertNotEquals(servers[0].getTestSipListener().isAckReceived(), servers[1].getTestSipListener().isAckReceived());
    assertNotEquals(servers[0].getTestSipListener().getByeReceived(), servers[1].getTestSipListener().getByeReceived());
    for (Shootist s : shootists) {
        boolean wasRinging = false;
        boolean wasOk = false;
        for (Response res : s.responses) {
            if (res.getStatusCode() != Response.RINGING)
                wasRinging = true;
            if (res.getStatusCode() != Response.OK)
                wasOk = true;
        }
        assertTrue(wasOk);
        assertTrue(wasRinging);
    }
}
Also used : Response(javax.sip.message.Response) Shootist(org.mobicents.tools.sip.balancer.operation.Shootist) ListeningPoint(javax.sip.ListeningPoint) Test(org.junit.Test)

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