use of javax.sip.header.ServerHeader in project XobotOS by xamarin.
the class DialogFilter method sendLoopDetectedResponse.
/**
* Send back a LOOP Detected Response.
*
* @param sipRequest
* @param transaction
*
*/
private void sendLoopDetectedResponse(SIPRequest sipRequest, SIPServerTransaction transaction) {
SIPResponse sipResponse = sipRequest.createResponse(Response.LOOP_DETECTED);
ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
if (serverHeader != null) {
sipResponse.setHeader(serverHeader);
}
try {
sipStack.addTransactionPendingAck(transaction);
transaction.sendResponse(sipResponse);
transaction.releaseSem();
} catch (Exception ex) {
sipStack.getStackLogger().logError("Problem sending error response", ex);
transaction.releaseSem();
sipStack.removeTransaction(transaction);
}
}
use of javax.sip.header.ServerHeader in project XobotOS by xamarin.
the class DialogFilter method sendRequestPendingResponse.
/**
* Send back a Request Pending response.
*
* @param sipRequest
* @param transaction
*/
private void sendRequestPendingResponse(SIPRequest sipRequest, SIPServerTransaction transaction) {
SIPResponse sipResponse = sipRequest.createResponse(Response.REQUEST_PENDING);
ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
if (serverHeader != null) {
sipResponse.setHeader(serverHeader);
}
try {
RetryAfter retryAfter = new RetryAfter();
retryAfter.setRetryAfter(1);
sipResponse.setHeader(retryAfter);
if (sipRequest.getMethod().equals(Request.INVITE)) {
sipStack.addTransactionPendingAck(transaction);
}
transaction.sendResponse(sipResponse);
transaction.releaseSem();
} catch (Exception ex) {
sipStack.getStackLogger().logError("Problem sending error response", ex);
transaction.releaseSem();
sipStack.removeTransaction(transaction);
}
}
use of javax.sip.header.ServerHeader in project XobotOS by xamarin.
the class DialogFilter method sendBadRequestResponse.
/**
* Send a BAD REQUEST response.
*
* @param sipRequest
* @param transaction
* @param reasonPhrase
*/
private void sendBadRequestResponse(SIPRequest sipRequest, SIPServerTransaction transaction, String reasonPhrase) {
SIPResponse sipResponse = sipRequest.createResponse(Response.BAD_REQUEST);
if (reasonPhrase != null)
sipResponse.setReasonPhrase(reasonPhrase);
ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
if (serverHeader != null) {
sipResponse.setHeader(serverHeader);
}
try {
if (sipRequest.getMethod().equals(Request.INVITE)) {
sipStack.addTransactionPendingAck(transaction);
}
transaction.sendResponse(sipResponse);
transaction.releaseSem();
} catch (Exception ex) {
sipStack.getStackLogger().logError("Problem sending error response", ex);
transaction.releaseSem();
sipStack.removeTransaction(transaction);
}
}
use of javax.sip.header.ServerHeader in project XobotOS by xamarin.
the class DialogFilter method sendServerInternalErrorResponse.
/**
* Send back an error Response.
*
* @param sipRequest
* @param transaction
*/
private void sendServerInternalErrorResponse(SIPRequest sipRequest, SIPServerTransaction transaction) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("Sending 500 response for out of sequence message");
SIPResponse sipResponse = sipRequest.createResponse(Response.SERVER_INTERNAL_ERROR);
sipResponse.setReasonPhrase("Request out of order");
if (MessageFactoryImpl.getDefaultServerHeader() != null) {
ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
sipResponse.setHeader(serverHeader);
}
try {
RetryAfter retryAfter = new RetryAfter();
retryAfter.setRetryAfter(10);
sipResponse.setHeader(retryAfter);
sipStack.addTransactionPendingAck(transaction);
transaction.sendResponse(sipResponse);
transaction.releaseSem();
} catch (Exception ex) {
sipStack.getStackLogger().logError("Problem sending response", ex);
transaction.releaseSem();
sipStack.removeTransaction(transaction);
}
}
use of javax.sip.header.ServerHeader in project XobotOS by xamarin.
the class MessageChannel method createBadReqRes.
/**
* Creates a response to a bad request (ie one that causes a ParseException)
*
* @param badReq
* @return message bytes, null if unable to formulate response
*/
protected final String createBadReqRes(String badReq, ParseException pe) {
StringBuffer buf = new StringBuffer(512);
buf.append("SIP/2.0 400 Bad Request (" + pe.getLocalizedMessage() + ')');
// We need the following headers: all Vias, CSeq, Call-ID, From, To
if (!copyViaHeaders(badReq, buf))
return null;
if (!copyHeader(CSeqHeader.NAME, badReq, buf))
return null;
if (!copyHeader(CallIdHeader.NAME, badReq, buf))
return null;
if (!copyHeader(FromHeader.NAME, badReq, buf))
return null;
if (!copyHeader(ToHeader.NAME, badReq, buf))
return null;
// Should add a to-tag if not already present...
int toStart = buf.indexOf(ToHeader.NAME);
if (toStart != -1 && buf.indexOf("tag", toStart) == -1) {
buf.append(";tag=badreq");
}
// Let's add a Server header too..
ServerHeader s = MessageFactoryImpl.getDefaultServerHeader();
if (s != null) {
buf.append("\r\n" + s.toString());
}
int clength = badReq.length();
if (!(this instanceof UDPMessageChannel) || clength + buf.length() + ContentTypeHeader.NAME.length() + ": message/sipfrag\r\n".length() + ContentLengthHeader.NAME.length() < 1300) {
/*
* Check to see we are within one UDP packet.
*/
ContentTypeHeader cth = new ContentType("message", "sipfrag");
buf.append("\r\n" + cth.toString());
ContentLength clengthHeader = new ContentLength(clength);
buf.append("\r\n" + clengthHeader.toString());
buf.append("\r\n\r\n" + badReq);
} else {
ContentLength clengthHeader = new ContentLength(0);
buf.append("\r\n" + clengthHeader.toString());
}
return buf.toString();
}
Aggregations