Package javax.sip

Examples of javax.sip.Dialog


        JipletDialog jdata = jiplet.getDialog(serverTransaction.getDialog(),
                true);
        TransactionsMapping transactionsMapping = jdata
                .getTransactionsMapping();

        Dialog peerDialog = transactionsMapping
                .getPeerDialog(serverTransaction);

        if (peerDialog == null)
        {
            ClientTransaction ct = sipProvider
                    .getNewClientTransaction(clonedRequest);
            ct.sendRequest();
            transactionsMapping.addMapping(serverTransaction, ct);
           
            if (ct.getDialog() != null)
            {
                JipletDialog clientDialog = jiplet.getDialog(
                        ct.getDialog(), true);
                if (clientDialog.getSipProvider() == null)
                {
                    clientDialog.setSipProvider(sipProvider);
                }
            }
        }
        else if (clonedRequest.getMethod().equals(Request.ACK))
        {
            peerDialog.sendAck(clonedRequest);
        }
        else
        {

            Request dialogRequest = peerDialog.createRequest(clonedRequest
                    .getMethod());
            Object content = clonedRequest.getContent();
            if (content != null)
            {
                ContentTypeHeader contentTypeHeader = (ContentTypeHeader) clonedRequest
                        .getHeader(ContentTypeHeader.NAME);
                if (contentTypeHeader != null)
                    dialogRequest.setContent(content, contentTypeHeader);
            }

            // Copy all the headers from the original request to the
            // dialog created request:
            ListIterator l = clonedRequest.getHeaderNames();
            while (l.hasNext())
            {
                String name = (String) l.next();
                Header header = dialogRequest.getHeader(name);
                if (header == null)
                {
                    ListIterator li = clonedRequest.getHeaders(name);
                    if (li != null)
                    {
                        while (li.hasNext())
                        {
                            Header h = (Header) li.next();
                            dialogRequest.addHeader(h);
                        }
                    }
                }
                else
                {
                    if (header instanceof ViaHeader)
                    {
                        ListIterator li = clonedRequest.getHeaders(name);
                        if (li != null)
                        {
                            dialogRequest.removeHeader(name);
                            Vector v = new Vector();
                            while (li.hasNext())
                            {
                                Header h = (Header) li.next();
                                v.addElement(h);
                            }
                            for (int k = (v.size() - 1); k >= 0; k--)
                            {
                                Header h = (Header) v.elementAt(k);
                                dialogRequest.addHeader(h);
                            }
                        }
                    }
                }
            }

            JipletDialog clientDialog = jiplet.getDialog(peerDialog, false);
            ClientTransaction clientTransaction = clientDialog.getSipProvider()
                    .getNewClientTransaction(dialogRequest);
            peerDialog.sendRequest(clientTransaction);
            transactionsMapping
                    .addMapping(serverTransaction, clientTransaction);

            // register for response
            jiplet.registerForResponse(clonedRequest, 60000L);
View Full Code Here


                            + " method requestEvent.getProxy() from the processRequest() method of the jiplet class."
                            + " Therefore this proxy object cannot perform the cancel operation");
            return;
        }

        Dialog dialog = serverTransaction.getDialog();
        if (dialog == null)
        {
            JipletLogger
                    .warn("Could not obtain the SIP dialog while canceling a proxy."
                            + " Cannot cancel the proxy");
View Full Code Here

                        {
                            transactionsMapping = new TransactionsMapping(
                                    jiplet, serverTransaction);
                           
                            // save server transaction side SipProvider in JipletDialog
                            Dialog serverDialog = serverTransaction.getDialog();
                            JipletDialog jd = jiplet.getDialog(serverDialog, true);
                            jd.setSipProvider((SipProvider) request.getSource());
                        }
                    }
                    catch (TransactionAlreadyExistsException e)
                    {
                        if (jiplet.isDebugEnabled() == true)
                        {
                            jiplet.debug("The request message to be proxied"
                                    + " is a retransmission, we drop it!");
                        }
                    }
                }
            }

            // 2. Preprocess routing information (Section 16.4)

            /*
             * The proxy MUST inspect the Request-URI of the request. If the
             * Request-URI of the request contains a value this proxy previously
             * placed into a Record-Route header field (see Section 16.6 item
             * 4), the proxy MUST replace the Request-URI in the request with
             * the last value from the Route header field, and remove that value
             * from the Route header field. The proxy MUST then proceed as if it
             * received this modified request. ..... (idem to below:) 16.12. The
             * proxy will inspect the URI in the topmost Route header field
             * value. If it indicates this proxy, the proxy removes it from the
             * Route header field (this route node has been reached).
             */

            ListIterator routes = msg.getHeaders(RouteHeader.NAME);
            if (routes != null)
            {
                if (routes.hasNext())
                {
                    RouteHeader routeHeader = (RouteHeader) routes.next();
                    Address routeAddress = routeHeader.getAddress();
                    SipURI routeSipURI = (SipURI) routeAddress.getURI();

                    String h = routeSipURI.getHost();
                    int port = routeSipURI.getPort();

                    if (jiplet.hasAddress(h, port) == true)
                    {
                        if (jiplet.isDebugEnabled() == true)
                        {
                            jiplet
                                    .debug("A request message to be proxied has this proxy in the route header. "
                                            + " We are going to remove the first route from "
                                            + " the RouteHeader");
                        }
                        routes.remove();
                    }
                }
            }

            // 3. Determine target(s) for the request (Section 16.5)

            /*
             * The set of targets will either be predetermined by the contents
             * of the request or will be obtained from an abstract location
             * service. Each target in the set is represented as a URI.
             */

            /*
             * If the Request-URI of the request contains an maddr parameter,
             * the Request-URI MUST be placed into the target set as the only
             * target URI, and the proxy MUST proceed to Section 16.6.
             */

            URI requestURI = msg.getRequestURI();
            if (requestURI.isSipURI())
            {
                SipURI requestSipURI = (SipURI) requestURI;
                if (requestSipURI.getMAddrParam() != null)
                {
                    uris.clear();
                    uris.add(requestURI);
                    if (jiplet.isDebugEnabled() == true)
                        jiplet
                                .debug("While proxying a request, "
                                        + " the only target is the Request-URI (mAddr parameter)");

                    // 4. Forward the request
                    RequestForwarding forwarder = new RequestForwarding(jiplet,
                            this, request,
                            serverTransaction, stateful, addRecordRoute);
                    forwarder.forwardRequest(uris);
                    return;
                }
            }

            if (stateful == true)
            {
                // Forward to next hop but dont reply OK right away for the
                // BYE. Bye is end-to-end not hop by hop!
                if (msg.getMethod().equals(Request.BYE))
                {
                    if (serverTransaction == null)
                    {
                        if (jiplet.isDebugEnabled() == true)
                            jiplet
                                    .debug("While proxying a request, null server transaction for BYE");
                        return;
                    }

                    Dialog d = serverTransaction.getDialog();
                    TransactionsMapping transactionsMapping = jiplet.getDialog(
                            d, true).getTransactionsMapping();
                    Dialog peerDialog = transactionsMapping
                            .getPeerDialog(serverTransaction);
                    Request clonedRequest = (Request) msg.clone();
                    FromHeader from = (FromHeader) clonedRequest
                            .getHeader(FromHeader.NAME);
                    from.removeParameter("tag");
                    ToHeader to = (ToHeader) clonedRequest
                            .getHeader(ToHeader.NAME);
                    to.removeParameter("tag");
                   
                    if (peerDialog.getState() != null)
                    {
                        JipletDialog clientDialog = jiplet.getDialog(peerDialog, false);
                        SipProvider clientProvider = clientDialog.getSipProvider();
                        ListeningPoint lp = clientProvider.getListeningPoints()[0];
                        // TODO, need to save the right transport - save LP instead of SipProvider?
                        // (in JipletDialog)
                        ViaHeader via = jiplet.getHeaderFactory().createViaHeader(lp.getIPAddress(),
                                    lp.getPort(), lp.getTransport(), null);
                        clonedRequest.addHeader(via);   
                       
                        ClientTransaction newct = clientProvider
                                .getNewClientTransaction(clonedRequest);
                        transactionsMapping
                                .addMapping(serverTransaction, newct);
                        peerDialog.sendRequest(newct);
                        jiplet.registerForResponse(clonedRequest, 60000L);
                        return;
                    }
                    else
                    {
                        // the peer dialog is not yet established so bail out.
                        // this is a client error - client is sending BYE
                        // before dialog establishment.
                        jiplet
                                .warn("While proxying a SIP request, bad dialog state - BYE dropped");
                        return;
                    }
                }
                // NEW CODE added by Amit to handle ACK and CANCEL
                else if (msg.getMethod().equals(Request.ACK))
                {
                    if (serverTransaction == null)
                    {
                        if (jiplet.isDebugEnabled() == true)
                            jiplet
                                    .debug("While proxying an ACK request, null server transaction");
                        return;
                    }

                    Dialog d = serverTransaction.getDialog();
                    TransactionsMapping transactionsMapping = jiplet.getDialog(
                            d, true).getTransactionsMapping();
                    Dialog peerDialog = transactionsMapping
                            .getPeerDialog(serverTransaction);
                    Request clonedRequest = (Request) msg.clone();
                    if (peerDialog.getState() != null)
                    {
                        peerDialog.sendAck(clonedRequest);
                    }
                    return;
                }
                else if (msg.getMethod().equals(Request.CANCEL))
                {
                    if (serverTransaction == null)
                    {
                        if (jiplet.isDebugEnabled() == true)
                            jiplet
                                    .debug("While proxying a CANCEL request, null server transaction for BYE");
                        return;
                    }

                    Dialog d = serverTransaction.getDialog();
                    JipletDialog jd = jiplet.getDialog(d, true);
                    TransactionsMapping transactionsMapping = jd
                            .getTransactionsMapping();

                    Vector transactions = transactionsMapping
View Full Code Here

        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();
View Full Code Here

            // 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
                        {
View Full Code Here

    /** Creates new TransactionsTable */
    public TransactionsMapping(Jiplet jiplet, ServerTransaction serverTransaction)
    {
        this.jiplet = jiplet;
        Dialog serverDialog = serverTransaction.getDialog();
        JipletDialog jd = jiplet.getDialog(serverDialog, true);
        table = new Hashtable();
        jd.setTransactionsMapping(this);
       
        jd.setAttribute("firstTransaction", serverTransaction);
View Full Code Here

        else
        {
            for (Enumeration e = vector.elements(); e.hasMoreElements();)
            {
                ClientTransaction ct = (ClientTransaction) e.nextElement();
                Dialog d = ct.getDialog();
                if (d.getState() != null
                        && d.getState().equals(DialogState.CONFIRMED))
                    return ct;
            }
            return null;
        }
    }
View Full Code Here

        {
            return;
        }
       
        Vector clients = getClientTransactions(serverTransaction);
        Dialog dialog = serverTransaction.getDialog();
        JipletDialog jd = jiplet.getDialog(dialog, true);
        TransactionsMapping map = jd.getTransactionsMapping();
        Dialog clientDialog = clientTransaction.getDialog();
        JipletDialog cjd = jiplet.getDialog(clientDialog, true);
        cjd.setTransactionsMapping(map);
       
        // save first transaction on client side, if this is the first
        if (cjd.getAttribute("firstTransaction") == null)
View Full Code Here

                if (LOG.isDebugEnabled()) {
                    LOG.info("ServerTransaction is null. Creating new Server transaction");
                }
                serverTransactionId = provider.getNewServerTransaction(notify);
            }
            Dialog dialog = serverTransactionId.getDialog();

            if (dialog != subscriberDialog) {
                forkedDialog = dialog;
            }
            //Dispatch the response along the route
            dispatchExchange(notify.getContent());
           
            // Send back an success response
            Response response = sipSubscriber.getConfiguration().getMessageFactory().createResponse(200, notify);           
            response.addHeader(sipSubscriber.getConfiguration().getContactHeader());
            serverTransactionId.sendResponse(response);

            SubscriptionStateHeader subscriptionState = (SubscriptionStateHeader) notify
                    .getHeader(SubscriptionStateHeader.NAME);

            // Subscription is terminated?
            if (subscriptionState.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
                if (LOG.isDebugEnabled()) {
                    LOG.info("Subscription state is terminated. Deleting the current dialog");
                }
                dialog.delete();
            }
        } catch (Exception e) {
            LOG.error("Exception thrown during Notify processing in the SipSubscriptionListener.", e);
        }
    }
View Full Code Here

        try {
            if (serverTransactionId == null) {
                LOG.info("ServerTransaction is null. Creating new Server transaction");
                serverTransactionId = provider.getNewServerTransaction(notify);
            }
            Dialog dialog = serverTransactionId.getDialog();

            if (dialog != subscriberDialog) {
                forkedDialog = dialog;
            }
            //Dispatch the response along the route
            dispatchExchange(notify.getContent());
           
            // Send back an success response
            Response response = sipSubscriber.getConfiguration().getMessageFactory().createResponse(200, notify);           
            response.addHeader(sipSubscriber.getConfiguration().getContactHeader());
            serverTransactionId.sendResponse(response);

            SubscriptionStateHeader subscriptionState = (SubscriptionStateHeader) notify
                    .getHeader(SubscriptionStateHeader.NAME);

            // Subscription is terminated?
            if (subscriptionState.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
                LOG.info("Subscription state is terminated. Deleting the current dialog");
                dialog.delete();
            }
        } catch (Exception e) {
            LOG.error("Exception thrown during Notify processing in the SipSubscriptionListener.", e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.sip.Dialog

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.