logger.info("referee : dialog = " + requestEvent.getDialog());
// Check that it has a Refer-To, if not bad request
ReferToHeader refTo = (ReferToHeader) refer.getHeader( ReferToHeader.NAME );
if (refTo==null) {
Response bad = messageFactory.createResponse(Response.BAD_REQUEST, refer);
bad.setReasonPhrase( "Missing Refer-To" );
sipProvider.sendResponse( bad );
TestHarness.fail("Bad REFER request. Missing Refer-To.");
}
// New test: first time, only send 100 Trying, to test that retransmission
// continues for non-INVITE requests (using UDP)
// before(!) creating a ServerTransaction! Else retransmissions are filtered
if (!tryingSent && "udp".equalsIgnoreCase(transport)) {
tryingSent = true;
sipProvider.sendResponse( messageFactory.createResponse(100, refer) );
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() );