use of gov.nist.javax.sip.stack.SIPServerTransaction 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.stack.SIPServerTransaction 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.stack.SIPServerTransaction in project jain-sip.ha by RestComm.
the class ClusteredSipStackImpl method findTransaction.
/*
* (non-Javadoc)
* @see gov.nist.javax.sip.stack.SIPTransactionStack#findTransaction(java.lang.String, boolean)
*/
@Override
public SIPTransaction findTransaction(String transactionId, boolean isServer) {
if (sipCache.inLocalMode() || replicationStrategy != ReplicationStrategy.EarlyDialog) {
return super.findTransaction(transactionId, isServer);
}
final String txId = transactionId.toLowerCase();
SIPTransaction sipTransaction = super.findTransaction(txId, isServer);
if (sipTransaction == null && transactionFactory != null) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("local transaction " + txId + " server = " + isServer + " is null, checking in the distributed cache");
}
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " checking if the transaction " + txId + " server = " + isServer + " is present in the distributed cache");
}
if (isServer) {
// fetch the corresponding server transaction from the cache instance
try {
sipTransaction = sipCache.getServerTransaction(txId);
if (sipTransaction != null) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " transaction " + txId + " server = " + isServer + " is present in the distributed cache");
}
SIPServerTransaction retval = serverTransactionTable.putIfAbsent(txId, (SIPServerTransaction) sipTransaction);
if (retval != null) {
sipTransaction = retval;
}
} else {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " transaction " + txId + " server = " + isServer + " is not present in the distributed cache");
}
}
} catch (SipCacheException e) {
getStackLogger().logError("sipStack " + this + " problem getting transaction " + txId + " server = " + isServer + " from the distributed cache", e);
}
} else {
// fetch the corresponding client transaction from the cache instance
try {
sipTransaction = sipCache.getClientTransaction(txId);
if (sipTransaction != null) {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " transaction " + txId + " server = " + isServer + " is present in the distributed cache");
}
SIPClientTransaction retval = clientTransactionTable.putIfAbsent(txId, (SIPClientTransaction) sipTransaction);
if (retval != null) {
sipTransaction = retval;
} else {
// start the transaction timer only when the transaction has been added to the stack
// to avoid leaks on retransmissions
((MobicentsHASIPClientTransaction) sipTransaction).startTransactionTimerOnFailover();
}
} else {
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " transaction " + txId + " server = " + isServer + " is not present in the distributed cache");
}
}
} catch (SipCacheException e) {
getStackLogger().logError("sipStack " + this + " problem getting transaction " + txId + " server = " + isServer + " from the distributed cache", e);
}
}
}
return sipTransaction;
}
use of gov.nist.javax.sip.stack.SIPServerTransaction in project jain-sip.ha by RestComm.
the class ClusteredSipStackImpl method remoteServerTransactionRemoval.
/*
* (non-Javadoc)
* @see org.mobicents.ha.javax.sip.ClusteredSipStack#remoteServerTransactionRemoval(java.lang.String)
*/
public void remoteServerTransactionRemoval(String transactionId) {
final String txId = transactionId.toLowerCase();
// assuming it's a confirmed dialog there is no chance it is on early dialogs too
if (getStackLogger().isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
getStackLogger().logDebug("sipStack " + this + " remote Server Transaction Removal of transaction Id : " + txId);
}
// the transaction id is set to lower case in the cache so it might not remove it correctly
SIPServerTransaction sipServerTransaction = super.serverTransactionTable.remove(txId);
if (sipServerTransaction != null) {
super.removeFromMergeTable(sipServerTransaction);
super.removePendingTransaction(sipServerTransaction);
super.removeTransactionPendingAck(sipServerTransaction);
}
}
use of gov.nist.javax.sip.stack.SIPServerTransaction in project jain-sip.ha by RestComm.
the class SIPServerTransactionCacheData method getServerTransaction.
public SIPServerTransaction getServerTransaction(String txId) throws SipCacheException {
SIPServerTransaction haSipServerTransaction = null;
if (logger.isLoggingEnabled(StackLogger.TRACE_TRACE))
logger.logDebug("getServerTransaction(" + txId + ")");
try {
final Map<String, Object> transactionMetaData = (Map<String, Object>) serverTransactions.get(txId);
final Object txAppData = serverTransactionsApp.get(txId);
haSipServerTransaction = createServerTransaction(txId, transactionMetaData, txAppData);
} catch (Exception e) {
throw new SipCacheException(e);
}
return haSipServerTransaction;
}
Aggregations