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());
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);
// JvB: test REFER, reported bug in tag handling
// Request referRequest = dialog.createRequest("REFER");
// //simulating a balancer that will forward the request to the recovery node
// SipURI referRequestURI = addressFactory.createSipURI(null, "127.0.0.1:5080");
// referRequest.setRequestURI(referRequestURI);
// dialog.sendRequest( sipProvider.getNewClientTransaction(referRequest));
//
} 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 !!");