Search in sources :

Example 1 with SIPServerTransaction

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());
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) MessageChannel(gov.nist.javax.sip.stack.MessageChannel) Hop(javax.sip.address.Hop) SIPMessage(gov.nist.javax.sip.message.SIPMessage) IOException(java.io.IOException) SipException(javax.sip.SipException) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) ListeningPoint(javax.sip.ListeningPoint) HopImpl(gov.nist.javax.sip.stack.HopImpl) Via(gov.nist.javax.sip.header.Via)

Example 2 with SIPServerTransaction

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;
}
Also used : Response(javax.sip.message.Response) SIPResponse(gov.nist.javax.sip.message.SIPResponse) SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) SIPResponse(gov.nist.javax.sip.message.SIPResponse) SIPDialog(gov.nist.javax.sip.stack.SIPDialog) SIPTransaction(gov.nist.javax.sip.stack.SIPTransaction) SipException(javax.sip.SipException) ServerTransaction(javax.sip.ServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) SIPRequest(gov.nist.javax.sip.message.SIPRequest)

Example 3 with SIPServerTransaction

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;
}
Also used : SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) MobicentsHASIPClientTransaction(gov.nist.javax.sip.stack.MobicentsHASIPClientTransaction) SIPTransaction(gov.nist.javax.sip.stack.SIPTransaction) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction)

Example 4 with SIPServerTransaction

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);
    }
}
Also used : SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction)

Example 5 with 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;
}
Also used : SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) MobicentsHASIPServerTransaction(gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) IMap(com.hazelcast.core.IMap) Map(java.util.Map) SipCacheException(org.mobicents.ha.javax.sip.cache.SipCacheException) IOException(java.io.IOException) ParseException(java.text.ParseException) PeerUnavailableException(javax.sip.PeerUnavailableException)

Aggregations

SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)10 IOException (java.io.IOException)6 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)5 SIPTransaction (gov.nist.javax.sip.stack.SIPTransaction)4 ParseException (java.text.ParseException)4 SIPRequest (gov.nist.javax.sip.message.SIPRequest)3 SIPResponse (gov.nist.javax.sip.message.SIPResponse)3 MobicentsHASIPServerTransaction (gov.nist.javax.sip.stack.MobicentsHASIPServerTransaction)3 SIPDialog (gov.nist.javax.sip.stack.SIPDialog)3 PeerUnavailableException (javax.sip.PeerUnavailableException)3 ServerTransaction (javax.sip.ServerTransaction)3 SipException (javax.sip.SipException)3 SipCacheException (org.mobicents.ha.javax.sip.cache.SipCacheException)3 MessageChannel (gov.nist.javax.sip.stack.MessageChannel)2 Map (java.util.Map)2 ClientTransaction (javax.sip.ClientTransaction)2 Hop (javax.sip.address.Hop)2 Response (javax.sip.message.Response)2 IMap (com.hazelcast.core.IMap)1 RouterExt (gov.nist.javax.sip.address.RouterExt)1