Search in sources :

Example 31 with Response

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

the class UserBasedAlgorithmTest method testInviteByeLandOnDifferentNodes.

@Test
public void testInviteByeLandOnDifferentNodes() 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)

Example 32 with Response

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

the class BTBUATest method testBackToBackUserAgent.

// test back to back use agent
@Test
public void testBackToBackUserAgent() throws Exception {
    boolean wasRinging = false;
    boolean wasOk = false;
    boolean wasInvite = false;
    boolean wasAck = false;
    boolean wasBye = false;
    shootist2.start();
    shootist1.start();
    shootist1.callerSendsBye = true;
    SipURI route = shootist1.addressFactory.createSipURI("lbint", "127.0.0.1:5060");
    route.setLrParam();
    shootist1.sendInitial(Request.INVITE, shootist1.headerFactory.createRouteHeader(shootist1.addressFactory.createAddress(route)));
    Thread.sleep(9000);
    shootist1.sendBye();
    Thread.sleep(2000);
    for (Response res : shootist1.responses) {
        if (res.getStatusCode() == Response.RINGING)
            wasRinging = true;
        if (res.getStatusCode() == Response.OK)
            wasOk = true;
    }
    for (Request req : shootist2.requests) {
        if (req.getMethod().equals(Request.INVITE))
            wasInvite = true;
        if (req.getMethod().equals(Request.ACK))
            wasAck = true;
        if (req.getMethod().equals(Request.BYE))
            wasBye = true;
    }
    assertEquals(3, shootist2.requests.size());
    assertTrue(wasOk);
    assertTrue(wasRinging);
    assertTrue(wasInvite);
    assertTrue(wasAck);
    assertTrue(wasBye);
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI) Test(org.junit.Test)

Example 33 with Response

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

the class NodeGracefulShutdownTest method testGracefulRemovingNode.

@Test
public void testGracefulRemovingNode() throws Exception {
    int okNumber1 = 0;
    int okNumber2 = 0;
    shootist1.sendInitialInvite();
    Thread.sleep(500);
    for (AppServer server : servers) if (server.sipListener.getInviteRequest() != null)
        server.gracefulShutdown();
    Thread.sleep(5000);
    shootist1.sendBye();
    Thread.sleep(2000);
    shootist2.sendInitialInvite();
    Thread.sleep(5000);
    shootist2.sendBye();
    Thread.sleep(2000);
    for (Response res : shootist1.responses) if (res.getStatusCode() == Response.OK)
        okNumber1++;
    for (Response res : shootist2.responses) if (res.getStatusCode() == Response.OK)
        okNumber2++;
    for (AppServer server : servers) assertNotNull(server.sipListener.getInviteRequest());
    assertEquals(2, okNumber1);
    assertEquals(2, okNumber2);
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) Response(javax.sip.message.Response) ListeningPoint(javax.sip.ListeningPoint) Test(org.junit.Test)

Example 34 with Response

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

the class RingingFailoverTest method testViaHeaderRewrite.

@Test
public void testViaHeaderRewrite() throws Exception, ParseException {
    CallIDAffinityBalancerAlgorithm algorithm = new CallIDAffinityBalancerAlgorithm();
    Response response = SipFactory.getInstance().createMessageFactory().createResponse(ringing);
    String node = "1.2.3.4";
    Integer port = 1234;
    Node adNode = new Node(node, node);
    adNode.getProperties().put("udpPort", "" + port);
    algorithm.balancerContext = new BalancerContext();
    algorithm.balancerContext.algorithmClassName = CallIDAffinityBalancerAlgorithm.class.getName();
    algorithm.balancerContext.smppToNodeAlgorithmClassName = SmppToNodeRoundRobinAlgorithm.class.getName();
    algorithm.balancerContext.smppToProviderAlgorithmClassName = SmppToProviderRoundRobinAlgorithm.class.getName();
    algorithm.setConfiguration(new LoadBalancerConfiguration());
    InvocationContext ctx = new InvocationContext("0", algorithm.balancerContext);
    ctx.sipNodeMap(false).put(new KeySip(adNode, false), adNode);
    algorithm.invocationContext = ctx;
    algorithm.processExternalResponse(response, false);
    algorithm.stop();
    assertTrue(response.toString().contains(node + ":" + port));
}
Also used : Response(javax.sip.message.Response) SmppToNodeRoundRobinAlgorithm(org.mobicents.tools.smpp.multiplexer.SmppToNodeRoundRobinAlgorithm) Node(org.mobicents.tools.heartbeat.api.Node) LoadBalancerConfiguration(org.mobicents.tools.configuration.LoadBalancerConfiguration) CallIDAffinityBalancerAlgorithm(org.mobicents.tools.sip.balancer.CallIDAffinityBalancerAlgorithm) BalancerContext(org.mobicents.tools.sip.balancer.BalancerContext) SmppToProviderRoundRobinAlgorithm(org.mobicents.tools.smpp.multiplexer.SmppToProviderRoundRobinAlgorithm) Test(org.junit.Test)

Example 35 with Response

use of javax.sip.message.Response in project jain-sip.ha by RestComm.

the class SimpleB2BUAHandler method processSubscribe.

public void processSubscribe(RequestEvent requestEvent) {
    try {
        Response response = messageFactory.createResponse(200, requestEvent.getRequest());
        response.addHeader(headerFactory.createHeader(ExpiresHeader.NAME, "3600"));
        requestEvent.getServerTransaction().sendResponse(response);
        Dialog dialog = getOutgoingDialog();
        Request request = dialog.createRequest(Request.SUBSCRIBE);
        ((SipURI) request.getRequestURI()).setPort(5070);
        final ClientTransaction ct = sipProvider.getNewClientTransaction(request);
        dialog.sendRequest(ct);
    } catch (Exception e) {
        ((SipStackImpl) sipStack).getStackLogger().logError("unexpected exception", e);
    }
}
Also used : Response(javax.sip.message.Response) Dialog(javax.sip.Dialog) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) SIPRequest(gov.nist.javax.sip.message.SIPRequest) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) CacheException(org.jboss.cache.CacheException) SipException(javax.sip.SipException)

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