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