Search in sources :

Example 71 with Response

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

the class RampUpTest method testInviteByeLandOnDifferentNodes.

@Test
public void testInviteByeLandOnDifferentNodes() throws Exception {
    for (int i = 0; i < shootists.length; i++) {
        shootists[i].sendInitialInvite();
        Thread.sleep(5000);
        shootists[i].sendBye();
        Thread.sleep(2000);
        if (i == 1) {
            servers[1].start();
            Thread.sleep(3000);
        }
    }
    assertEquals(6, servers[0].getTestSipListener().getDialogCount());
    assertEquals(2, servers[1].getTestSipListener().getDialogCount());
    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 72 with Response

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

the class SinglePointTest method testTlsToTcp.

@Test
public void testTlsToTcp() throws Exception {
    setUp(true);
    boolean wasRinging = false;
    boolean wasOk = false;
    shootistTls.sendInitialInvite();
    Thread.sleep(5000);
    shootistTls.sendBye();
    Thread.sleep(5000);
    assertTrue(server.getTestSipListener().isInviteReceived());
    assertTrue(server.getTestSipListener().isAckReceived());
    assertTrue(server.getTestSipListener().getByeReceived());
    for (Response res : shootistTls.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) Test(org.junit.Test)

Example 73 with Response

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

the class SinglePointTest method testTlsToTls.

@Test
public void testTlsToTls() throws Exception {
    setUp(false);
    boolean wasRinging = false;
    boolean wasOk = false;
    shootistTls.sendInitialInvite();
    Thread.sleep(5000);
    shootistTls.sendBye();
    Thread.sleep(5000);
    assertTrue(server.getTestSipListener().isInviteReceived());
    assertTrue(server.getTestSipListener().isAckReceived());
    assertTrue(server.getTestSipListener().getByeReceived());
    for (Response res : shootistTls.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) Test(org.junit.Test)

Example 74 with Response

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

the class SIPBalancerForwarder method decreaseMaxForwardsHeader.

/**
 * @param sipProvider
 * @param request
 * @throws InvalidArgumentException
 * @throws ParseException
 * @throws SipException
 */
private void decreaseMaxForwardsHeader(SipProvider sipProvider, Request request) throws InvalidArgumentException, ParseException, SipException {
    // Decreasing the Max Forward Header
    if (logger.isDebugEnabled()) {
        logger.debug("Decreasing  the Max Forward Header ");
    }
    MaxForwardsHeader maxForwardsHeader = (MaxForwardsHeader) request.getHeader(MaxForwardsHeader.NAME);
    if (maxForwardsHeader == null) {
        maxForwardsHeader = balancerRunner.balancerContext.headerFactory.createMaxForwardsHeader(70);
        request.addHeader(maxForwardsHeader);
    } else {
        if (maxForwardsHeader.getMaxForwards() - 1 > 0) {
            maxForwardsHeader.setMaxForwards(maxForwardsHeader.getMaxForwards() - 1);
        } else {
            // Max forward header equals to 0, thus sending too many hops response
            Response response = balancerRunner.balancerContext.messageFactory.createResponse(Response.TOO_MANY_HOPS, request);
            sipProvider.sendResponse(response);
        }
    }
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) Response(javax.sip.message.Response) SIPResponse(gov.nist.javax.sip.message.SIPResponse)

Example 75 with Response

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

the class SimpleB2BUAHandler method forwardResponse.

/**
 * @param responseEvent
 * @throws InvalidArgumentException
 */
@SuppressWarnings("unchecked")
private void forwardResponse(Response receivedResponse) throws SipException, InvalidArgumentException {
    if (receivedResponse.getStatusCode() == 202) {
        return;
    }
    System.out.println("Forwarding " + receivedResponse);
    final ServerTransaction origServerTransaction = this.getServerTransaction();
    Response forgedResponse = null;
    try {
        forgedResponse = messageFactory.createResponse(receivedResponse.getStatusCode(), origServerTransaction.getRequest());
    } catch (ParseException e) {
        throw new SipException("Failed to forge message", e);
    }
    // if ((getIncomingDialog() == null || getIncomingDialog().getState() == DialogState.EARLY) && localTag != null && getIncomingDialog() != null && getIncomingDialog().isServer()) {
    // // no tag set in the response, since the dialog creating transaction didn't had it
    // try {
    // ((ToHeader)forgedResponse.getHeader(ToHeader.NAME)).setTag(localTag);
    // } catch (ParseException e) {
    // throw new SipException("Failed to set local tag", e);
    // }
    // }
    // copy headers
    ListIterator<String> lit = receivedResponse.getHeaderNames();
    String headerName = null;
    ListIterator<Header> headersIterator = null;
    while (lit.hasNext()) {
        headerName = lit.next();
        if (SimpleB2BUAHandler.getHeadersToOmmitOnResponseCopy().contains(headerName)) {
            continue;
        } else {
            forgedResponse.removeHeader(headerName);
            headersIterator = receivedResponse.getHeaders(headerName);
            while (headersIterator.hasNext()) {
                forgedResponse.addLast((Header) headersIterator.next().clone());
            }
        }
    }
    // Copy content
    final byte[] rawOriginal = receivedResponse.getRawContent();
    if (rawOriginal != null && rawOriginal.length != 0) {
        final byte[] copy = new byte[rawOriginal.length];
        System.arraycopy(rawOriginal, 0, copy, 0, copy.length);
        try {
            forgedResponse.setContent(copy, (ContentTypeHeader) forgedResponse.getHeader(ContentTypeHeader.NAME));
        } catch (ParseException e) {
            throw new SipException("Failed to copy content.", e);
        }
    }
    // set contact if the received response had it
    if (receivedResponse.getHeader(ContactHeader.NAME) != null) {
        final String transport = ((ViaHeader) forgedResponse.getHeader(ViaHeader.NAME)).getTransport();
        forgedResponse.setHeader(((ListeningPointImpl) sipProvider.getListeningPoint(transport)).createContactHeader());
    }
    // set the to tag mandatory so that the dialog gets replicated
    if (((MessageExt) forgedResponse).getToHeader().getTag() == null) {
        try {
            ((MessageExt) forgedResponse).getToHeader().setTag("696");
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    origServerTransaction.sendResponse(forgedResponse);
}
Also used : Response(javax.sip.message.Response) MessageExt(gov.nist.javax.sip.message.MessageExt) ContactHeader(javax.sip.header.ContactHeader) ViaHeader(javax.sip.header.ViaHeader) CallIdHeader(javax.sip.header.CallIdHeader) ContentLengthHeader(javax.sip.header.ContentLengthHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) Header(javax.sip.header.Header) CSeqHeader(javax.sip.header.CSeqHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ToHeader(javax.sip.header.ToHeader) RouteHeader(javax.sip.header.RouteHeader) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) EventHeader(javax.sip.header.EventHeader) FromHeader(javax.sip.header.FromHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) ViaHeader(javax.sip.header.ViaHeader) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction) 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