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);
}
}
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);
}
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);
}
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);
}
}
}
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);
}
Aggregations