} return transaction;
} transaction.setDialog(dialog, sipRequest.getDialogId(true)); dialog.addRoute(sipRequest); if (dialog.getRemoteTag() != null && dialog.getLocalTag() != null) { this.sipStack.putDialog(dialog); } }
    public ServerTransaction getNewServerTransaction(Request request)            throws TransactionAlreadyExistsException,            TransactionUnavailableException {        SIPServerTransaction transaction = null;        SIPRequest sipRequest = (SIPRequest) request;        if (sipStack.isDialogCreated(sipRequest.getMethod())                && sipStack.dialogSupport) {            if (sipStack.findTransaction((SIPRequest) request, true) != null)                throw new TransactionAlreadyExistsException(                        "server transaction already exists!");            if (!sipStack.hasResources())                throw new TransactionUnavailableException(                        "Resource Not available!");            transaction = (SIPServerTransaction) ((SIPRequest) request)                    .getTransaction();            if (transaction == null)                throw new TransactionUnavailableException(                        "Transaction not available");            if (transaction.getOriginalRequest() == null)                transaction.setOriginalRequest(sipRequest);            try {                sipStack.addTransaction(transaction);            } catch (IOException ex) {                throw new TransactionUnavailableException(                        "Error sending provisional response");            }            // So I can handle timeouts.            transaction.addEventListener(this);            String dialogId = sipRequest.getDialogId(true);            SIPDialog dialog = sipStack.getDialog(dialogId);            if (dialog == null) {                dialog = sipStack.createDialog(transaction);            } else {                transaction.setDialog(dialog);            }            dialog.setStack(this.sipStack);            dialog.addRoute(sipRequest);            if (dialog.getRemoteTag() != null && dialog.getLocalTag() != null) {                this.sipStack.putDialog(dialog);            }        } else {            transaction = (SIPServerTransaction) sipStack.findTransaction(                    (SIPRequest) request, true);            if (transaction != null)                throw new TransactionAlreadyExistsException(                        "Transaction exists! ");            transaction = (SIPServerTransaction) ((SIPRequest) request)                    .getTransaction();            if (transaction == null)                throw new TransactionUnavailableException(                        "Transaction not available!");            if (transaction.getOriginalRequest() == null)                transaction.setOriginalRequest(sipRequest);            // Map the transaction.            try {                sipStack.addTransaction(transaction);            } catch (IOException ex) {                throw new TransactionUnavailableException(                        "Could not send back provisional response!");            }            // If dialogs are to be supported by the stack, create one and add            // it.            String dialogId = sipRequest.getDialogId(true);            SIPDialog dialog = sipStack.getDialog(dialogId);            if (dialog != null) {                dialog.addTransaction(transaction);                dialog.addRoute(sipRequest);            }        }        return transaction;    }