use of gov.nist.javax.sip.message.SIPResponse in project XobotOS by xamarin.
the class SipProviderImpl method sendResponse.
/*
* (non-Javadoc)
*
* @see javax.sip.SipProvider#sendResponse(javax.sip.message.Response)
*/
public void sendResponse(Response response) throws SipException {
if (!sipStack.isAlive())
throw new SipException("Stack is stopped");
SIPResponse sipResponse = (SIPResponse) response;
Via via = sipResponse.getTopmostVia();
if (via == null)
throw new SipException("No via header in response!");
SIPServerTransaction st = (SIPServerTransaction) sipStack.findTransaction((SIPMessage) response, true);
if (st != null && st.getState() != TransactionState.TERMINATED && this.isAutomaticDialogSupportEnabled()) {
throw new SipException("Transaction exists -- cannot send response statelessly");
}
String transport = via.getTransport();
// check to see if Via has "received paramaeter". If so
// set the host to the via parameter. Else set it to the
// Via host.
String host = via.getReceived();
if (host == null)
host = via.getHost();
// Symmetric nat support
int port = via.getRPort();
if (port == -1) {
port = via.getPort();
if (port == -1) {
if (transport.equalsIgnoreCase("TLS"))
port = 5061;
else
port = 5060;
}
}
// for correct management of IPv6 addresses.
if (host.indexOf(":") > 0)
if (host.indexOf("[") < 0)
host = "[" + host + "]";
Hop hop = sipStack.getAddressResolver().resolveAddress(new HopImpl(host, port, transport));
try {
ListeningPointImpl listeningPoint = (ListeningPointImpl) this.getListeningPoint(transport);
if (listeningPoint == null)
throw new SipException("whoopsa daisy! no listening point found for transport " + transport);
MessageChannel messageChannel = sipStack.createRawMessageChannel(this.getListeningPoint(hop.getTransport()).getIPAddress(), listeningPoint.port, hop);
messageChannel.sendMessage(sipResponse);
} catch (IOException ex) {
throw new SipException(ex.getMessage());
}
}
use of gov.nist.javax.sip.message.SIPResponse in project XobotOS by xamarin.
the class SipProviderImpl method getNewDialog.
/*
* (non-Javadoc)
*
* @see javax.sip.SipProvider#getNewDialog(javax.sip.Transaction)
*/
public Dialog getNewDialog(Transaction transaction) throws SipException {
if (transaction == null)
throw new NullPointerException("Null transaction!");
if (!sipStack.isAlive())
throw new SipException("Stack is stopped.");
if (isAutomaticDialogSupportEnabled())
throw new SipException(" Error - AUTOMATIC_DIALOG_SUPPORT is on");
if (!sipStack.isDialogCreated(transaction.getRequest().getMethod()))
throw new SipException("Dialog cannot be created for this method " + transaction.getRequest().getMethod());
SIPDialog dialog = null;
SIPTransaction sipTransaction = (SIPTransaction) transaction;
if (transaction instanceof ServerTransaction) {
SIPServerTransaction st = (SIPServerTransaction) transaction;
Response response = st.getLastResponse();
if (response != null) {
if (response.getStatusCode() != 100)
throw new SipException("Cannot set dialog after response has been sent");
}
SIPRequest sipRequest = (SIPRequest) transaction.getRequest();
String dialogId = sipRequest.getDialogId(true);
dialog = sipStack.getDialog(dialogId);
if (dialog == null) {
dialog = sipStack.createDialog((SIPTransaction) transaction);
// create and register the dialog and add the inital route set.
dialog.addTransaction(sipTransaction);
dialog.addRoute(sipRequest);
sipTransaction.setDialog(dialog, null);
} else {
sipTransaction.setDialog(dialog, sipRequest.getDialogId(true));
}
if (sipRequest.getMethod().equals(Request.INVITE) && this.isDialogErrorsAutomaticallyHandled()) {
sipStack.putInMergeTable(st, sipRequest);
}
} else {
SIPClientTransaction sipClientTx = (SIPClientTransaction) transaction;
SIPResponse response = sipClientTx.getLastResponse();
if (response == null) {
// A response has not yet been received, then set this up as the
// default dialog.
SIPRequest request = (SIPRequest) sipClientTx.getRequest();
String dialogId = request.getDialogId(false);
dialog = sipStack.getDialog(dialogId);
if (dialog != null) {
throw new SipException("Dialog already exists!");
} else {
dialog = sipStack.createDialog(sipTransaction);
}
sipClientTx.setDialog(dialog, null);
} else {
throw new SipException("Cannot call this method after response is received!");
}
}
dialog.addEventListener(this);
return dialog;
}
use of gov.nist.javax.sip.message.SIPResponse 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 gov.nist.javax.sip.message.SIPResponse 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 gov.nist.javax.sip.message.SIPResponse 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);
}
}
Aggregations