Package javax.sip

Examples of javax.sip.ServerTransaction


        }

      
        public void processRequest(RequestEvent requestReceivedEvent) {
            Request request = requestReceivedEvent.getRequest();
            ServerTransaction serverTransactionId = requestReceivedEvent.getServerTransaction();

            logger.info("\n\nRequest " + request.getMethod() + " received at "
                    + protocolObjects.sipStack.getStackName() + " with server transaction id "
                    + serverTransactionId);
View Full Code Here


            if (firstTransaction instanceof ClientTransaction)
            {
                return;
            }

            ServerTransaction firstServerTransaction = (ServerTransaction) firstTransaction;

            try
            {
                // send 487 Request Terminated reply to canceled request
                Response response = messageFactory.createResponse(
                        Response.REQUEST_TERMINATED, firstServerTransaction
                                .getRequest());
                firstServerTransaction.sendResponse(response);
            }
            catch (InvalidArgumentException e)
            {
                // inapplicable - it only happens if the Response was created
                // by Dialog.createReliableProvisionalResponse(int) and the
View Full Code Here

                    .warn("Found the first transaction in the dialog to be a client transaction while canceling a proxy."
                            + " Cannot cancel the proxy");
            return;
        }

        ServerTransaction firstServerTransaction = (ServerTransaction) t;
        Vector transactions = transactionsMapping
                .getClientTransactions(firstServerTransaction);
        if (transactions == null || transactions.isEmpty())
        {
            // this is an error condition and should not happen
            JipletLogger
                    .error("While canceling a proxy request, found empty client transaction in the transaction map for the dialog. ");
            return;
        }

        for (Enumeration en = transactions.elements(); en.hasMoreElements();)
        {
            ClientTransaction ct = (ClientTransaction) en.nextElement();

            // check if the client transaction can be canceled.
            if (ct.getState().equals(TransactionState.COMPLETED)
                    || ct.getState().equals(TransactionState.TERMINATED))
            {
                continue;
            }

            try
            {
                JipletDialog clientJipletDialog = (JipletDialog) ct.getDialog()
                        .getApplicationData();
                if (clientJipletDialog != null)
                {
                    ClientTransaction client = clientJipletDialog
                            .getSipProvider().getNewClientTransaction(
                                    ct.createCancel());
                    client.sendRequest();
                }
                else
                {
                    ListeningPoint defaultLP = jiplet
                            .getListeningPointDefault();
                    ClientTransaction client = jiplet.getSipProvider(defaultLP)
                            .getNewClientTransaction(ct.createCancel());
                    client.sendRequest();
                }
            }
            catch (Exception e)
            {
                jiplet.error("Couldn't cancel client transaction : Exception "
                        + e.getClass().getName() + " : " + e.getMessage()
                        + "\n" + JipletLogger.getStackTrace(e));
            }
        }

        transactions.clear();

        try
        {
            if (statusCode >= 0)
            {
                if (firstServerTransaction.getState().equals(
                        TransactionState.COMPLETED)
                        || firstServerTransaction.getState().equals(
                                TransactionState.TERMINATED))
                {
                    // nothing to do
                    return;
                }

                Response response = jiplet.getMessageFactory().createResponse(
                        statusCode, firstServerTransaction.getRequest());
                if (reason != null)
                {
                    response.setReasonPhrase(reason);
                }
                firstServerTransaction.sendResponse(response);
            }
        }
        catch (Exception e)
        {
            jiplet.error("Exception " + e.getClass().getName() + " : "
View Full Code Here

        {
            return false;
        }

        TransactionsMapping transactionsMapping = jd.getTransactionsMapping();
        ServerTransaction serverTransaction = transactionsMapping
                .getServerTransaction(clientTransaction);

        if (serverTransaction != null)
        {
            // if other outbound legs present, simply drop this leg out
View Full Code Here

        SipProvider provider = (SipProvider) timeout.getSource();
        TransactionsMapping transactionsMapping = null;
        if (timeout.isServerTransaction())
        {
            ServerTransaction serverTransaction = timeout
                    .getServerTransaction();
            Dialog dialog = serverTransaction.getDialog();
            if (dialog != null)
            {

                transactionsMapping = jiplet.getDialog(dialog, true)
                        .getTransactionsMapping();
                transactionsMapping.removeMapping(serverTransaction);
            }
        }
        else
        {
            ClientTransaction clientTransaction = timeout
                    .getClientTransaction();
            Dialog dialog = clientTransaction.getDialog();
            ServerTransaction st = null;
            if (dialog != null)
            {
                transactionsMapping = jiplet.getDialog(dialog, true)
                        .getTransactionsMapping();
                if (transactionsMapping != null)
                {
                    st = transactionsMapping
                            .getServerTransaction(clientTransaction);
                }

                if (st == null)
                {
                    jiplet.error("Unable to retrieve the server transaction,"
                            + " cannot process timeout!");
                    return;
                }
            }
            else
            {
                jiplet.error("Unable to retrieve the transaction Mapping,"
                        + " cannot process timeout!");
                return;
            }

            Request request = st.getRequest();

            // This removes the given mapping from the table but not
            // necessarily the whole thing.
            transactionsMapping.removeMapping(clientTransaction);
            if (!transactionsMapping.hasMapping(st))
            {
                // No more mappings left in the transaction table.
                Response response = jiplet.getMessageFactory().createResponse(
                        Response.REQUEST_TIMEOUT, request);
               
                try
                {
                    st.sendResponse(response);
                }
                catch (InvalidArgumentException e)
                {
                    // inapplicable - it only happens if the Response was created
                    // by Dialog.createReliableProvisionalResponse(int) and the
View Full Code Here

             * failure to send the response or signal a timeout in its state
             * machine. These errors would be logged for diagnostic purposes as
             * appropriate, but the protocol requires no remedial action from
             * the jiplet.
             */
            ServerTransaction serverTransaction = transactionsMapping
                    .getServerTransaction(clientTransaction);

            // For forking:
            if ((response.getStatusCode() == Response.UNAUTHORIZED || response
                    .getStatusCode() == Response.DECLINE)
                    && serverTransaction != null)
            {
                // check the busy or decline
                Vector clientsTransactionList = transactionsMapping
                        .getClientTransactions(serverTransaction);
                if (clientsTransactionList != null
                        && clientsTransactionList.size() > 1)
                {
                    transactionsMapping.removeMapping(clientTransaction);
                }
            }

            // For forking:
            if (response.getStatusCode() == Response.OK
                    && serverTransaction != null)
            {
                Dialog peerDialog = serverTransaction.getDialog();
                Vector clientsTransactionList = transactionsMapping
                        .getClientTransactions(serverTransaction);

                if (peerDialog != null && peerDialog.getState() != null
                        && peerDialog.getState().equals(DialogState.CONFIRMED)
                        && clientsTransactionList != null
                        && clientsTransactionList.size() > 1)
                {
                    Dialog dialog = clientTransaction.getDialog();
                    Request byeRequest = dialog.createRequest(Request.BYE);

                    ClientTransaction ct = responseProvider
                            .getNewClientTransaction(byeRequest);
                    dialog.sendRequest(ct);

                    // we have to remove the transaction from the table:
                    transactionsMapping.removeMapping(clientTransaction);
                    return;
                }
                else
                {
                    if (serverTransaction != null)
                        transactionsMapping.addMapping(serverTransaction,
                                clientTransaction);
                }
            }

            if (serverTransaction == null)
            {
                ListeningPoint defaultLP = jiplet.getListeningPointDefault();
                jiplet.getSipProvider(defaultLP).sendResponse(response);
                return;
            }
            else
            {
                // we can try to modify the tags:
                Dialog dialog = serverTransaction.getDialog();
                if (dialog != null)
                {
                    String localTag = dialog.getLocalTag();
                    String remoteTag = dialog.getRemoteTag();
                    ToHeader toHeader = (ToHeader) response
                            .getHeader(ToHeader.NAME);
                    FromHeader fromHeader = (FromHeader) response
                            .getHeader(FromHeader.NAME);

                    if (localTag != null && remoteTag != null)
                    {
                        if (dialog.isServer())
                        {
                            toHeader.setTag(localTag);
                        }
                        else
                        {
                            fromHeader.setTag(remoteTag);
                        }
                    }
                }

                // 8. Record-Route - modify record route header if needed
                /*
                 * If the selected response contains a Record-Route header field
                 * value originally provided by this proxy, the proxy MAY choose
                 * to rewrite the value before forwarding the response. This
                 * allows the proxy to provide different URIs for itself to the
                 * next upstream and downstream elements. A proxy may choose to
                 * use this mechanism for any reason. For instance, it is useful
                 * for multi-homed hosts.
                 */

                ListIterator rrHeaders = response
                        .getHeaders(RecordRouteHeader.NAME);
                while (rrHeaders.hasNext())
                {
                    // look for the 1st one to replace, replace it & get out
                    RecordRouteHeader rr = (RecordRouteHeader) rrHeaders.next();
                    URI uri = rr.getAddress().getURI();
                    if (uri instanceof SipURI)
                    {
                        SipURI sipURI = (SipURI) uri;
                        // is this a record route header we added?
                        if (jiplet.hasAddress(sipURI.getHost(), sipURI
                                .getPort()))
                        {
                            // does this one need replacing?
                            String user = sipURI.getUser();
                            if (user != null)
                            {
                                StringTokenizer tok = new StringTokenizer(user,
                                        "-");
                                if (tok.countTokens() == 2)
                                {
                                    SipURI sourceURI = jiplet
                                            .getAddressFactory().createSipURI(
                                                    null, tok.nextToken());

                                    sourceURI.setPort(Integer.valueOf(
                                            tok.nextToken()).intValue());
                                    sourceURI.setLrParam();

                                    // rewrite it back into the RR header
                                    rr.getAddress().setURI(sourceURI);
                                    rrHeaders.set(rr);
                                    break;
                                }
                            }
                        }
                    }
                }

                try
                {
                    serverTransaction.sendResponse(response);
                }
                catch (InvalidArgumentException e)
                {
                    // this exception only happens if the Response was created
                    // by Dialog.createReliableProvisionalResponse(int) and the
View Full Code Here

                if (ct != null)
                    return ct.getDialog();
            }
            else
            {
                ServerTransaction st = getServerTransaction((ClientTransaction) transaction);
                if (st != null)
                    return st.getDialog();
            }
        }
        return null;

    }
View Full Code Here

        // Retrieve the good value:
        Enumeration e = table.keys();

        while (e.hasMoreElements())
        {
            ServerTransaction serverTransaction = (ServerTransaction) e
                    .nextElement();
            Vector vector = (Vector) table.get(serverTransaction);

            for (Enumeration en = vector.elements(); en.hasMoreElements();)
            {
View Full Code Here

        table.remove(serverTransaction);
    }

    protected void removeMapping(ClientTransaction clientTransaction)
    {
        ServerTransaction serverTransaction = getServerTransaction(clientTransaction);
        Vector clientTransactions = getClientTransactions(serverTransaction);

        if (clientTransactions != null && clientTransactions.isEmpty()) // ???
        {
            clientTransactions.removeElement(clientTransaction);
View Full Code Here

        {
            Enumeration e = table.keys();

            while (e.hasMoreElements())
            {
                ServerTransaction serverTransaction = (ServerTransaction) e
                        .nextElement();

                Vector vector = (Vector) table.get(serverTransaction);
                if (vector != null)
                {
View Full Code Here

TOP

Related Classes of javax.sip.ServerTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.