Search in sources :

Example 56 with Response

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

the class BackToBackUserAgent method forwardResponse.

private void forwardResponse(ResponseEvent receivedResponse) throws SipException {
    try {
        ServerTransaction serverTransaction = (ServerTransaction) receivedResponse.getClientTransaction().getApplicationData();
        Request stRequest = serverTransaction.getRequest();
        Response newResponse = this.messageFactory.createResponse(receivedResponse.getResponse().getStatusCode(), stRequest);
        ListeningPoint peerListeningPoint = sp.getListeningPoint(transport);
        ContactHeader peerContactHeader = ((ListeningPointExt) peerListeningPoint).createContactHeader();
        newResponse.setHeader(peerContactHeader);
        serverTransaction.sendResponse(newResponse);
    } catch (InvalidArgumentException e) {
        throw new SipException("invalid response", e);
    } catch (ParseException e) {
        throw new SipException("invalid response", e);
    }
}
Also used : Response(javax.sip.message.Response) ContactHeader(javax.sip.header.ContactHeader) ListeningPointExt(gov.nist.javax.sip.ListeningPointExt) InvalidArgumentException(javax.sip.InvalidArgumentException) Request(javax.sip.message.Request) ListeningPoint(javax.sip.ListeningPoint) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction) SipException(javax.sip.SipException)

Example 57 with Response

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

the class HealthcheckTest method testMediaFailure.

@Test
public void testMediaFailure() throws Exception {
    int okCounter = 0;
    setUp();
    for (int i = 0; i < 8; i++) {
        shootist.sendInitialInvite();
        Thread.sleep(5000);
    }
    for (Response res : shootist.responses) if (res.getStatusCode() == Response.OK)
        okCounter++;
    assertEquals(5, okCounter);
    assertEquals(0, badServer.getTestSipListener().getDialogCount());
    assertEquals(5, goodServer.getTestSipListener().getDialogCount());
}
Also used : Response(javax.sip.message.Response) ListeningPoint(javax.sip.ListeningPoint) Test(org.junit.Test)

Example 58 with Response

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

the class MediaFailureTest method testMediaFailure.

@Test
public void testMediaFailure() throws Exception {
    int serviceAnavaible = 0;
    int okCounter = 0;
    setUp();
    for (int i = 0; i < 8; i++) {
        shootist.sendInitialInvite();
        Thread.sleep(5000);
        if (i == 6) {
            badServer.stop();
            goodServer.stop();
            Thread.sleep(5000);
            badServer.start();
            Thread.sleep(8000);
        }
    }
    for (Response res : shootist.responses) {
        if (res.getStatusCode() == Response.SERVICE_UNAVAILABLE)
            serviceAnavaible++;
        if (res.getStatusCode() == Response.OK)
            okCounter++;
    }
    assertEquals(3, serviceAnavaible);
    assertEquals(5, okCounter);
    assertEquals(1, badServer.getTestSipListener().getDialogCount());
    assertEquals(4, goodServer.getTestSipListener().getDialogCount());
}
Also used : Response(javax.sip.message.Response) ListeningPoint(javax.sip.ListeningPoint) Test(org.junit.Test)

Example 59 with Response

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

the class RegexTest method testRegexAddAndRemove.

@Test
public void testRegexAddAndRemove() throws Exception {
    int okCounter = 0;
    setUp();
    WebConversation conversation = new WebConversation();
    WebRequest request = new GetMethodWebRequest("http://127.0.0.1:2006/lbnoderegex?regex=(-)&ip=127.0.0.1&port=4060");
    conversation.getResponse(request);
    Thread.sleep(2000);
    shootist.sendInitial("Kostya-test", "here.com", Request.INVITE, null, null, null);
    Thread.sleep(5000);
    shootist.sendInitial("Nosach-test", "here.com", Request.INVITE, null, null, null);
    Thread.sleep(5000);
    request = new GetMethodWebRequest("http://127.0.0.1:2006/lbnoderegex?regex=(-)");
    conversation.getResponse(request);
    Thread.sleep(2000);
    shootist.sendInitial("Kostya-test", "here.com", Request.INVITE, null, null, null);
    Thread.sleep(5000);
    shootist.sendInitial("Nosach-test", "here.com", Request.INVITE, null, null, null);
    Thread.sleep(5000);
    for (Response res : shootist.responses) {
        if (res.getStatusCode() == Response.OK)
            okCounter++;
    }
    assertEquals(4, okCounter);
    assertEquals(3, node0.getTestSipListener().getDialogCount());
    assertEquals(1, node1.getTestSipListener().getDialogCount());
}
Also used : Response(javax.sip.message.Response) WebConversation(com.meterware.httpunit.WebConversation) WebRequest(com.meterware.httpunit.WebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) GetMethodWebRequest(com.meterware.httpunit.GetMethodWebRequest) ListeningPoint(javax.sip.ListeningPoint) Test(org.junit.Test)

Example 60 with Response

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

the class Response5xxTest method testSend503Response.

@Test
public void testSend503Response() throws Exception {
    setUp();
    boolean was503 = false;
    shootist.sendInitialInvite();
    Thread.sleep(1000);
    for (Response res : shootist.responses) {
        if (res.getStatusCode() != Response.SERVICE_UNAVAILABLE)
            was503 = true;
    }
    assertTrue(was503);
}
Also used : Response(javax.sip.message.Response) 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