}
Via via = lp.getViaHeader();
From from = new From();
from.setAddress(this.getLocalParty());
To to = new To();
to.setAddress(this.getRemoteParty());
SIPRequest sipRequest = createRequest(sipUri, via, cseq, from, to);
/*
* The default contact header is obtained from the provider. The
* application can override this.
*
* JvB: Should only do this for target refresh requests, ie not for BYE,
* PRACK, etc
*/
if (SIPRequest.isTargetRefresh(method)) {
ContactHeader contactHeader = ((ListeningPointImpl) this.sipProvider
.getListeningPoint(lp.getTransport()))
.createContactHeader();
((SipURI) contactHeader.getAddress().getURI()).setSecure(this
.isSecure());
sipRequest.setHeader(contactHeader);
}
try {
/*
* Guess of local sequence number - this is being re-set when the
* request is actually dispatched
*/
cseq = (CSeq) sipRequest.getCSeq();
cseq.setSeqNumber(this.localSequenceNumber + 1);
} catch (InvalidArgumentException ex) {
InternalErrorHandler.handleException(ex);
}
if (method.equals(Request.SUBSCRIBE)) {
if (eventHeader != null)
sipRequest.addHeader(eventHeader);
}
/*
* RFC-3515 Section - 2.4.6, if there are multiple REFER transactions in a dialog then the
* NOTIFY MUST include an id parameter in the Event header containing the sequence number
* (the number from the CSeq header field value) of the REFER this NOTIFY is associated with.
* This id parameter MAY be included in NOTIFYs to the first REFER a UA receives in a given dialog
*/
if (method.equals(Request.NOTIFY)) {
if (eventHeader != null ) {
sipRequest.addHeader(eventHeader);
}
}
/*
* RFC3261, section 12.2.1.1:
*
* The URI in the To field of the request MUST be set to the remote URI
* from the dialog state. The tag in the To header field of the request
* MUST be set to the remote tag of the dialog ID. The From URI of the
* request MUST be set to the local URI from the dialog state. The tag
* in the From header field of the request MUST be set to the local tag
* of the dialog ID. If the value of the remote or local tags is null,
* the tag parameter MUST be omitted from the To or From header fields,
* respectively.
*/
try {
if (this.getLocalTag() != null) {
from.setTag(this.getLocalTag());
} else {
from.removeTag();
}
if (this.getRemoteTag() != null) {
to.setTag(this.getRemoteTag());
} else {
to.removeTag();
}
} catch (ParseException ex) {
InternalErrorHandler.handleException(ex);
}