}
}
public synchronized void processResponse(ResponseEvent responseReceived) {
try {
ResponseEventExt responseReceivedEvent = (ResponseEventExt) responseReceived;
Response response = (Response) responseReceivedEvent.getResponse();
ClientTransaction tid = responseReceivedEvent.getClientTransaction();
CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
logger.info("Response received : Status Code = "
+ response.getStatusCode() + " " + cseq);
logger.info("Response = " + response + " class=" + response.getClass() );
Dialog dialog = responseReceivedEvent.getDialog();
if(createDialogAfterRequest) {
TestCase.assertNull( dialog );
return;
} else {
TestCase.assertNotNull( dialog );
}
System.out.println("original Tx " + responseReceivedEvent.getOriginalTransaction());
if (tid != null)
logger.info("transaction state is " + tid.getState());
else
logger.info("transaction = " + tid);
logger.info("Dialog = " + dialog);
logger.info("Dialog state is " + dialog.getState());
String toTag = ((ResponseExt)response).getToHeader().getTag();
boolean isFromFork = false;
if(forkFirst) {
isFromFork = toTag != null && !toTag.contains("shootme-5080");
} else {
isFromFork = toTag != null && !toTag.contains("shootme-5081");
}
logger.info("isRetransmission = " + responseReceivedEvent.isRetransmission() + " isFromForked = " + isFromFork + " isForked = " + responseReceivedEvent.isForkedResponse() + " response "+ response);
if (response.getStatusCode() == Response.OK) {
if (cseq.getMethod().equals(Request.INVITE)) {
// Proxy will fork. I will accept the first dialog.
this.forkedDialogs.add(dialog);
if (!isFromFork) {
TestCase.assertFalse("non forked event must not set flag",responseReceivedEvent.isForkedResponse());
if(ackedDialog == null) {
TestCase.assertFalse("retransmission flag should be false",responseReceivedEvent.isRetransmission());
TestCase.assertTrue(
"Dialog state should be CONFIRMED", dialog
.getState() == DialogState.CONFIRMED);
TestCase.assertTrue(this.ackedDialog == null ||
this.ackedDialog == dialog);
this.ackedDialog = dialog;
Request ackRequest = dialog.createAck(cseq
.getSeqNumber());
TestCase.assertNotNull( ackRequest.getHeader( MaxForwardsHeader.NAME ) );
// sleeping to see how it reacts with retrans
logger.info("Waiting to Send ACK");
Thread.sleep(1000);
logger.info("Sending " + ackRequest);
dialog.sendAck(ackRequest);
if ( callerSendsBye ) {
timer.schedule( new SendBye(ackedDialog), 2000 );
}
} else {
TestCase.assertTrue("retransmission flag should be true",responseReceivedEvent.isRetransmission());
}
} else {
TestCase.assertTrue("forked event must set flag",responseReceivedEvent.isForkedResponse());
TestCase.assertSame("original ctx must match " , this.originalTransaction,
responseReceivedEvent.getOriginalTransaction());
if ( cseq.getMethod().equals(Request.INVITE)) {
TestCase.assertSame("Must preserve original dialog",
this.originalDialog,responseReceivedEvent.getOriginalTransaction().getDefaultDialog());
}
if(canceledDialog.isEmpty()) {
TestCase.assertFalse("retransmission flag should be false",responseReceivedEvent.isRetransmission());
TestCase.assertEquals( DialogState.CONFIRMED, dialog.getState() );
this.canceledDialog.add(dialog);
Request ackRequest = dialog.createAck(cseq
.getSeqNumber());
TestCase.assertNotNull( ackRequest.getHeader( MaxForwardsHeader.NAME ) );
// sleeping to see how it reacts with retrans
logger.info("Waiting to Send ACK");
Thread.sleep(1000);
logger.info("Sending " + ackRequest);
dialog.sendAck(ackRequest);
Thread.sleep(2000);
Request byeRequest = dialog.createRequest(Request.BYE);
ClientTransaction ct = sipProvider
.getNewClientTransaction(byeRequest);
dialog.sendRequest(ct);
} else {
TestCase.assertTrue("retransmission flag should be true",responseReceivedEvent.isRetransmission());
}
}
} else if ( cseq.getMethod().equals(Request.BYE)) {
TestCase.assertFalse("retransmission flag should be false",responseReceivedEvent.isRetransmission());
if ( dialog == this.ackedDialog) {
this.byeResponseSeen = true;
}
} else {
logger.info("Response method = " + cseq.getMethod());
}
} else if ( response.getStatusCode() == Response.RINGING ) {
TestCase.assertEquals( DialogState.EARLY, dialog.getState() );
this.forkedEarlyDialogs.add(dialog);
// Proxy will fork. This make sure the forked early dialog is not the same as the first one.
if(isFromFork) {
logger.info("forked early dialog= " + dialog + " for response " + response);
ResponseEventExt responseEventExt = (ResponseEventExt) responseReceivedEvent;
TestCase.assertTrue("forked event must set flag",responseEventExt.isForkedResponse());
TestCase.assertNotSame(dialog, earlyDialog);
TestCase.assertSame(earlyDialog, responseEventExt.getOriginalTransaction().getDefaultDialog());
} else {
earlyDialog = dialog;
logger.info("original early dialog= " + dialog + " for response " + response);
ResponseEventExt responseEventExt = (ResponseEventExt) responseReceivedEvent;
TestCase.assertFalse("non forked event must not set flag",responseEventExt.isForkedResponse());
}
}
} catch (Throwable ex) {
ex.printStackTrace();
// System.exit(0);