Package javax.sip

Examples of javax.sip.SipProvider


        public SipProvider createSipProvider() throws Exception {
            listeningPoint = protocolObjects.sipStack.createListeningPoint(myAddress,
                    myPort, protocolObjects.transport);


            SipProvider sipProvider = protocolObjects.sipStack.createSipProvider(listeningPoint);
            return sipProvider;
        }
View Full Code Here


            if (tid != null) {
        logger.info("Dialog = " + responseReceivedEvent.getDialog());
        logger.info("Dialog State is "
            + responseReceivedEvent.getDialog().getState());
      }
            SipProvider provider = (SipProvider) responseReceivedEvent.getSource();

            try {
                if (response.getStatusCode() == Response.OK
                        && ((CSeqHeader) response.getHeader(CSeqHeader.NAME))
                                .getMethod().equals(Request.INVITE)) {
View Full Code Here

                return;
            }
            logger.info("transaction state is " + tid.getState());
            logger.info("Dialog = " + tid.getDialog());
            logger.info("Dialog State is " + tid.getDialog().getState());
            SipProvider provider = (SipProvider) responseReceivedEvent.getSource();

            try {
                if (response.getStatusCode() == Response.OK
                        && ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod().equals(
                                Request.INVITE)) {

                    // Request cancel = inviteTid.createCancel();
                    // ClientTransaction ct =
                    // sipProvider.getNewClientTransaction(cancel);
                    Dialog dialog = tid.getDialog();
                    CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
                    Request ackRequest = dialog.createAck(cseq.getSeqNumber());
                    logger.info("Ack request to send = " + ackRequest);
                    logger.info("Sending ACK");
                    dialog.sendAck(ackRequest);

                    Thread.sleep(100);
                 
                    Request inviteRequest = dialog.createRequest(Request.INVITE);
                    ((SipURI) inviteRequest.getRequestURI()).removeParameter("transport");
                    ((ViaHeader) inviteRequest.getHeader(ViaHeader.NAME)).setTransport("udp");
                    inviteRequest.addHeader(contactHeader);
                    MaxForwardsHeader mf = protocolObjects.headerFactory
                            .createMaxForwardsHeader(10);
                    inviteRequest.addHeader(mf);
                     ClientTransaction ct = provider.getNewClientTransaction(inviteRequest);
                    dialog.sendRequest(ct);
                    reInviteCount++;
                    logger.info("RE-INVITE sent");

                } else if (response.getStatusCode() == Response.BUSY_HERE) {
View Full Code Here

             * the request is forwarded to. The URI SHOULD NOT contain the
             * transport parameter.
             */

            ListeningPoint defaultLP = jiplet.getListeningPointDefault();
            SipProvider sipProvider = jiplet.getSipProvider(defaultLP);
           
            if (addRecordRoute)
            {
                // Only in stateful forwarding
                // We add our jiplet RecordRoute header to the top of the
                // list - use the following recommended mechanism to handle multi-homing

                /*
                 * If the URI placed in the Record-Route header field needs to
                 * be rewritten when it passes back through in a response, the
                 * URI MUST be distinct enough to locate at that time. (The
                 * request may spiral through this proxy, resulting in more than
                 * one Record-Route header field value being added). Item 8 of
                 * Section 16.7 recommends a mechanism to make the URI
                 * sufficiently distinct.
                 *
                 * The proxy MAY include parameters in the Record-Route header
                 * field value. These will be echoed in some responses to the
                 * request such as the 200 (OK) responses to INVITE. Such
                 * parameters may be useful for keeping state in the message
                 * rather than the proxy.
                 */

                if (stateful)
                {
                    SipURI sipURI = addressFactory.createSipURI(null, defaultLP
                            .getIPAddress());

                    sipURI.setPort(defaultLP.getPort());
                    sipURI.setTransportParam(defaultLP.getTransport());
                    sipURI.setLrParam();

                    // save the IP address and port the request came in on, for
                    // rewriting the record route header later in the response
                    // put it in this forwarded message itself - user part of RR
                    SipProvider sourceProvider = (SipProvider) requestEvent
                            .getSource();
                    ListeningPoint sourceLp = sourceProvider
                            .getListeningPoints()[0];
                    sipURI.setUser(sourceLp.getIPAddress() + '-' + sourceLp.getPort());
                   
                    Address address = addressFactory
                            .createAddress(null, sipURI);
View Full Code Here

            this.addRecordRoute = addRecordRoute;
            this.stateful = stateful;
            this.presenceServer = presenceServer;

            SipProvider provider = (SipProvider) request.getSource();
            Request msg = request.getRequest();

            if (serverTransaction == null)
            {
                if (jiplet.isDebugEnabled() == true)
                {
                    jiplet
                            .debug("The server transaction is being obtained first time for this proxy object");
                }
                serverTransaction = request.getServerTransaction();
            }
            else
            {
                if (jiplet.isDebugEnabled() == true)
                {
                    jiplet
                            .debug("The server transaction already exists. This proxy object is being re-used to send another request");
                }           
            }

            // PROXY BEHAVIOR

            /*
             * RFC 3261: 16.2: For all new requests, including any with unknown
             * methods, an element intending to proxy the request MUST:
             *
             * 1. Validate the request (Section 16.3)
             *
             * 2. Preprocess routing information (Section 16.4)
             *
             * 3. Determine target(s) for the request (Section 16.5)
             *
             * 4. Forward the request to each target (Section 16.6)
             *
             * 5. Process all responses (Section 16.7)
             */

            // 1. Validate the request (Section 16.3)
            RequestValidation valid = new RequestValidation(jiplet, presenceServer);
            if (valid.validateRequest(provider, request.getRequest(),
                    serverTransaction) == false)
            {
                jiplet
                        .warn("A request message that is to be proxied failed validation."
                                + " Not going to proxy it. An appropriate response has been sent");
                return;
            }

            // Let's check if the ACK is for the proxy: if there is no Route
            // header: it is mandatory for the ACK to be forwarded

            if (msg.getMethod().equals(Request.ACK))
            {
                ListIterator routes = msg.getHeaders(RouteHeader.NAME);
                if (routes == null || !routes.hasNext())
                {
                    if (jiplet.isDebugEnabled() == true)
                    {
                        jiplet.debug("Proxying an ACK "
                                + " targeted for the proxy, we ignore it");
                    }
                    return;
                }
            }

            if (stateful == true)
            {
                String method = msg.getMethod();
                // Methods that creates dialogs, so that can
                // generate transactions
                if (method.equals(Request.INVITE)
                        || method.equals(Request.SUBSCRIBE))
                {
                    try
                    {
                        if (serverTransaction == null)
                        {
                            serverTransaction = provider
                                    .getNewServerTransaction(msg);
                        }

                        TransactionsMapping transactionsMapping = jiplet
                                .getDialog(serverTransaction.getDialog(), true)
                                .getTransactionsMapping();
                        if (transactionsMapping == null)
                        {
                            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);
View Full Code Here

            // TODO this needs to be looked into in some details. For now, just
            // return.
            return;
        }

        SipProvider provider = (SipProvider) timeout.getSource();
        TransactionsMapping transactionsMapping = null;
        if (timeout.isServerTransaction())
        {
            ServerTransaction serverTransaction = timeout
                    .getServerTransaction();
View Full Code Here

                            cancelRequest.addHeader((ViaHeader) cancelViaList
                                    .next());

                            SipURI localAddr = (SipURI) ctr.getDialog()
                                    .getLocalParty().getURI();
                            SipProvider p = jiplet.getSipProvider(localAddr
                                    .getHost(), localAddr.getPort());

                            if (p == null)
                            {
                                ListeningPoint defaultLP = jiplet
                                        .getListeningPointDefault();
                                p = jiplet.getSipProvider(defaultLP);
                            }

                            ClientTransaction ct = p
                                    .getNewClientTransaction(cancelRequest);
                            ct.sendRequest();
                        }
                    }
                }
View Full Code Here

            {
                transaction.sendResponse(resp);
            }
            else
            {
                SipProvider provider = (SipProvider) event.getSource();
                provider.sendResponse(resp);
            }
        }
        catch (Exception e)
        {
            JipletLogger
View Full Code Here

            }

            ListeningPoint lp = sipStack.createListeningPoint(address, port
                    .getPort(), porttype);

            SipProvider provider = findSipProvider(address, port.getPort());
            if (provider == null)
            {
                provider = sipStack.createSipProvider(lp);
                addSipProvider(provider);

                if (JipletLogger.isDebugEnabled() == true)
                {
                    JipletLogger.debug("Connector " + c.getName()
                            + ": created new SipProvider for IP address "
                            + address + ", port " + port.getPort()
                            + "; added ListeningPoint for transport "
                            + porttype);
                }
            }
            else
            {
                if (providerSupportsProtocol(provider, porttype) == false)
                {
                    provider.addListeningPoint(lp);

                    if (JipletLogger.isDebugEnabled() == true)
                    {
                        JipletLogger.debug("Connector " + c.getName()
                                + ": added new ListeningPoint for transport "
View Full Code Here

    private void registerListener() throws TooManyListenersException
    {
        Iterator iter = sipProviders.iterator();
        while (iter.hasNext() == true)
        {
            SipProvider provider = (SipProvider) iter.next();
            provider.addSipListener(this);

            if (JipletLogger.isDebugEnabled() == true)
            {
                JipletLogger.debug("Added SIP listener to connector " + name
                        + ", provider "
View Full Code Here

TOP

Related Classes of javax.sip.SipProvider

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.