return;
}
// Always create a ServerTransaction, best as early as possible in the code
Response response = null;
ServerTransaction st = requestEvent.getServerTransaction();
if (st == null) {
st = sipProvider.getNewServerTransaction(refer);
}
// Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
String toTag = Integer.toHexString( (int) (Math.random() * Integer.MAX_VALUE) );
response = messageFactory.createResponse(202, refer);
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
// Sanity check: to header should not have a tag. Else the dialog
// should have matched
TestHarness.assertNull("To-tag!=null but no dialog match! My dialog=" + dialog, toHeader.getTag());
toHeader.setTag(toTag); // Application is supposed to set.
this.dialog = st.getDialog();
// REFER dialogs do not terminate on bye.
this.dialog.terminateOnBye(false);
if (dialog != null) {
logger.info("Dialog " + dialog);
logger.info("Dialog state " + dialog.getState());
logger.info( "local tag=" + dialog.getLocalTag() );
logger.info( "remote tag=" + dialog.getRemoteTag() );
}
// Both 2xx response to SUBSCRIBE and NOTIFY need a Contact
Address address = addressFactory.createAddress("Referee <sip:127.0.0.1>");
((SipURI)address.getURI()).setPort( mySipProvider.getListeningPoint(transport).getPort() );
ContactHeader contactHeader = headerFactory.createContactHeader(address);
response.addHeader(contactHeader);
// Expires header is mandatory in 2xx responses to REFER
ExpiresHeader expires = (ExpiresHeader) refer.getHeader( ExpiresHeader.NAME );
if (expires==null) {
expires = headerFactory.createExpiresHeader(30);// rather short
}
response.addHeader( expires );
/*
* The REFER MUST be answered first.
*/
TestHarness.assertNull( dialog.getState() );
st.sendResponse(response);
TestHarness.assertEquals( DialogState.CONFIRMED, dialog.getState() );
// NOTIFY MUST have "refer" event, possibly with id
referEvent = headerFactory.createEventHeader("refer");