use of gov.nist.javax.sip.header.Require in project XobotOS by xamarin.
the class SIPDialog method sendReliableProvisionalResponse.
/*
* (non-Javadoc)
*
* @see javax.sip.Dialog#sendReliableProvisionalResponse(javax.sip.message.Response)
*/
public void sendReliableProvisionalResponse(Response relResponse) throws SipException {
if (!this.isServer()) {
throw new SipException("Not a Server Dialog");
}
SIPResponse sipResponse = (SIPResponse) relResponse;
if (relResponse.getStatusCode() == 100)
throw new SipException("Cannot send 100 as a reliable provisional response");
if (relResponse.getStatusCode() / 100 > 2)
throw new SipException("Response code is not a 1xx response - should be in the range 101 to 199 ");
/*
* Do a little checking on the outgoing response.
*/
if (sipResponse.getToTag() == null) {
throw new SipException("Badly formatted response -- To tag mandatory for Reliable Provisional Response");
}
ListIterator requireList = (ListIterator) relResponse.getHeaders(RequireHeader.NAME);
boolean found = false;
if (requireList != null) {
while (requireList.hasNext() && !found) {
RequireHeader rh = (RequireHeader) requireList.next();
if (rh.getOptionTag().equalsIgnoreCase("100rel")) {
found = true;
}
}
}
if (!found) {
Require require = new Require("100rel");
relResponse.addHeader(require);
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug("Require header with optionTag 100rel is needed -- adding one");
}
}
SIPServerTransaction serverTransaction = (SIPServerTransaction) this.getFirstTransaction();
/*
* put into the dialog table before sending the response so as to avoid race condition
* with PRACK
*/
this.setLastResponse(serverTransaction, sipResponse);
this.setDialogId(sipResponse.getDialogId(true));
serverTransaction.sendReliableProvisionalResponse(relResponse);
this.startRetransmitTimer(serverTransaction, relResponse);
}
use of gov.nist.javax.sip.header.Require in project XobotOS by xamarin.
the class SIPDialog method createReliableProvisionalResponse.
/*
* (non-Javadoc)
*
* @see javax.sip.Dialog#createReliableProvisionalResponse(int)
*/
public Response createReliableProvisionalResponse(int statusCode) throws InvalidArgumentException, SipException {
if (!(firstTransactionIsServerTransaction)) {
throw new SipException("Not a Server Dialog!");
}
/*
* A UAS MUST NOT attempt to send a 100 (Trying) response reliably. Only provisional
* responses numbered 101 to 199 may be sent reliably. If the request did not include
* either a Supported or Require header field indicating this feature, the UAS MUST NOT
* send the provisional response reliably.
*/
if (statusCode <= 100 || statusCode > 199)
throw new InvalidArgumentException("Bad status code ");
SIPRequest request = this.originalRequest;
if (!request.getMethod().equals(Request.INVITE))
throw new SipException("Bad method");
ListIterator<SIPHeader> list = request.getHeaders(SupportedHeader.NAME);
if (list == null || !optionPresent(list, "100rel")) {
list = request.getHeaders(RequireHeader.NAME);
if (list == null || !optionPresent(list, "100rel")) {
throw new SipException("No Supported/Require 100rel header in the request");
}
}
SIPResponse response = request.createResponse(statusCode);
/*
* The provisional response to be sent reliably is constructed by the UAS core according
* to the procedures of Section 8.2.6 of RFC 3261. In addition, it MUST contain a Require
* header field containing the option tag 100rel, and MUST include an RSeq header field.
* The value of the header field for the first reliable provisional response in a
* transaction MUST be between 1 and 2**31 - 1. It is RECOMMENDED that it be chosen
* uniformly in this range. The RSeq numbering space is within a single transaction. This
* means that provisional responses for different requests MAY use the same values for the
* RSeq number.
*/
Require require = new Require();
try {
require.setOptionTag("100rel");
} catch (Exception ex) {
InternalErrorHandler.handleException(ex);
}
response.addHeader(require);
RSeq rseq = new RSeq();
/*
* set an arbitrary sequence number. This is actually set when the response is sent out
*/
rseq.setSeqNumber(1L);
/*
* Copy the record route headers from the request to the response ( Issue 160 ). Note that
* other 1xx headers do not get their Record Route headers copied over but reliable
* provisional responses do. See RFC 3262 Table 2.
*/
RecordRouteList rrl = request.getRecordRouteHeaders();
if (rrl != null) {
RecordRouteList rrlclone = (RecordRouteList) rrl.clone();
response.setHeader(rrlclone);
}
return response;
}
Aggregations