Package javax.sip.address

Examples of javax.sip.address.SipURI


                String toSipAddress = "there.com";
                String toUser = "LittleGuy";
                String toDisplayName = "The Little Blister";

                // create >From Header
                SipURI fromAddress = protocolObjects.addressFactory.createSipURI(fromName,
                        fromSipAddress);

                Address fromNameAddress = protocolObjects.addressFactory
                        .createAddress(fromAddress);
                fromNameAddress.setDisplayName(fromDisplayName);
                FromHeader fromHeader = protocolObjects.headerFactory.createFromHeader(
                        fromNameAddress, new Integer((int) (Math.random() * Integer.MAX_VALUE))
                                .toString());

                // create To Header
                SipURI toAddress = protocolObjects.addressFactory.createSipURI(toUser,
                        toSipAddress);
                Address toNameAddress = protocolObjects.addressFactory.createAddress(toAddress);
                toNameAddress.setDisplayName(toDisplayName);
                ToHeader toHeader = protocolObjects.headerFactory.createToHeader(toNameAddress,
                        null);

                // create Request URI
                SipURI requestURI = protocolObjects.addressFactory.createSipURI(toUser,
                        peerHostPort);

                // Create ViaHeaders

                ArrayList viaHeaders = new ArrayList();
                int port = provider.getListeningPoint(protocolObjects.transport).getPort();

                ViaHeader viaHeader = protocolObjects.headerFactory.createViaHeader(myAddress,
                        port, protocolObjects.transport, null);

                // add via headers
                viaHeaders.add(viaHeader);

                // Create ContentTypeHeader
                ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory
                        .createContentTypeHeader("application", "sdp");

                // Create a new CallId header
                CallIdHeader callIdHeader = provider.getNewCallId();
                // JvB: Make sure that the implementation matches the messagefactory
                callIdHeader = protocolObjects.headerFactory.createCallIdHeader(callIdHeader
                        .getCallId());

                // Create a new Cseq header
                CSeqHeader cSeqHeader = protocolObjects.headerFactory.createCSeqHeader(1L,
                        Request.INVITE);

                // Create a new MaxForwardsHeader
                MaxForwardsHeader maxForwards = protocolObjects.headerFactory
                        .createMaxForwardsHeader(70);

                // Create the request.
                Request request = protocolObjects.messageFactory.createRequest(requestURI,
                        Request.INVITE, callIdHeader, cSeqHeader, fromHeader, toHeader,
                        viaHeaders, maxForwards);
                // Create contact headers

                // Create the contact name address.
                SipURI contactURI = protocolObjects.addressFactory.createSipURI(fromName,
                        myAddress);
                contactURI.setPort(provider.getListeningPoint(protocolObjects.transport)
                        .getPort());

                Address contactAddress = protocolObjects.addressFactory.createAddress(contactURI);

                // Add the contact address.
View Full Code Here


                 * 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);
                    RecordRouteHeader recordRouteHeader = headerFactory
                            .createRecordRouteHeader(address);
View Full Code Here

            {
                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
                            .getClientTransactions((ServerTransaction) jd
                                    .getAttribute("firstTransaction"));
                   
                    if (transactions == null || transactions.isEmpty())
                    {
                        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;
                        }
                       
                        JipletDialog clientJipletDialog = (JipletDialog) ct.getDialog().getApplicationData();
                        if (clientJipletDialog != null)
                        {
                            ClientTransaction client = clientJipletDialog.getSipProvider().getNewClientTransaction(ct.createCancel());
                            client.sendRequest();
                        }
                    }
                }
                // END NEW CODE

            }

            /*
             * If the target set for the request has not been predetermined as
             * described above, this implies that the element is responsible for
             * the domain in the Request-URI, and the element MAY use whatever
             * mechanism it desires to determine where to send the request. ...
             * When accessing the location service constructed by a registrar,
             * the Request-URI MUST first be canonicalized as described in
             * Section 10.3 before being used as an index.
             */

            if (requestURI.isSipURI())
            {
                SipURI requestSipURI = (SipURI) requestURI;
                Iterator iterator = requestSipURI.getParameterNames();
                if (jiplet.isDebugEnabled() == true)
                    jiplet.debug("While proxying a request, we canonicalized"
                            + " the request-URI");
                while (iterator != null && iterator.hasNext())
                {
                    String name = (String) iterator.next();
                    requestSipURI.removeParameter(name);
                }
            }

            // We fork only INVITE
            if (uris.size() > 1 && !msg.getMethod().equals(Request.INVITE))
View Full Code Here

    public ContactHeader getStackContactHeader() throws ParseException
    {
        ListeningPoint lp = jiplet.getListeningPointDefault();

        SipURI sipURI = jiplet.getAddressFactory().createSipURI(null, lp.getIPAddress());
        sipURI.setPort(lp.getPort());
        sipURI.setTransportParam(lp.getTransport());
        Address contactAddress = jiplet.getAddressFactory().createAddress(
                sipURI);

        return jiplet.getHeaderFactory().createContactHeader(contactAddress);
    }
View Full Code Here

                    // 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
                    // application calls ServerTransaction.sendResponse() to
                    // send it
                    JipletLogger
                            .error("Response forwarding failed - invalid send method for reliable provisional response - need to add a check for this and call dialog method sendReliableProvisionalResponse() instead. Response = \n"
                                    + response.toString());
                }
            }

            /** ************************************************************************ */
            /** ************ 10. Generate CANCELs ******* */
            /** ************************************************************************* */
            /*
             * If the forwarded response was a final response, the jiplet MUST
             * generate a CANCEL request for all pending client transactions
             * associated with this response context. A jiplet SHOULD also
             * generate a CANCEL request for all pending client transactions
             * associated with this response context when it receives a 6xx
             * response. A pending client transaction is one that has received a
             * provisional response, but no final response (it is in the
             * proceeding state) and has not had an associated CANCEL generated
             * for it. Generating CANCEL requests is described in Section 9.1.
             */

            if (response.getStatusCode() == Response.OK
                    || (response.getStatusCode() >= Response.BUSY_EVERYWHERE && response
                            .getStatusCode() <= Response.SESSION_NOT_ACCEPTABLE))
            {
                Vector clientsTransactionList = transactionsMapping
                        .getClientTransactions(serverTransaction);

                for (Enumeration e = clientsTransactionList.elements(); e
                        .hasMoreElements();)
                {
                    ClientTransaction ctr = (ClientTransaction) e.nextElement();
                    if (ctr != clientTransaction)
                    {
                        TransactionState transactionState = ctr.getState();
                        if (transactionState == null
                                || transactionState.getValue() == TransactionState.PROCEEDING
                                        .getValue())
                        {

                            /*
                             * 9.1: The following procedures are used to
                             * construct a CANCEL request. The Request-URI,
                             * Call-ID, To, the numeric part of CSeq, and From
                             * header fields in the CANCEL request MUST be
                             * identical to those in the request being
                             * cancelled, including tags. A CANCEL constructed
                             * by a client MUST have only a single Via header
                             * field value matching the top Via value in the
                             * request being cancelled. Using the same values
                             * for these header fields allows the CANCEL to be
                             * matched with the request it cancels (Section 9.2
                             * indicates how such matching occurs). However, the
                             * method part of the CSeq header field MUST have a
                             * value of CANCEL. This allows it to be identified
                             * and processed as a transaction in its own right
                             * (See Section 17).
                             *
                             * If the request being cancelled contains a Route
                             * header field, the CANCEL request MUST include
                             * that Route header field's values.
                             */
                            Request cancelRequest = ctr.createCancel();

                            // Let's keep only the top most via header:
                            ListIterator cancelViaList = cancelRequest
                                    .getHeaders(ViaHeader.NAME);
                            cancelRequest.removeHeader(ViaHeader.NAME);
                            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();
View Full Code Here

            // if (expires > 0 && expires < 60) {
            // [issue 2] Schedule re registrations
            // bug reported by LynlvL@netscape.com
            // use the value returned by the server to reschedule
            // registration
            SipURI uri = (SipURI) address.getURI();
            scheduleReRegistration(uri.getHost(), uri.getPort(), uri
                    .getTransportParam(), expires);
            // }
            /*
            * else{ SipURI uri = (SipURI) address.getURI();
            * scheduleReRegistration(uri.getHost(), uri.getPort(),
View Full Code Here

            // From
            FromHeader fromHeader = sipManCallback.getFromHeader(true);
            Address fromAddress = fromHeader.getAddress();
            sipManCallback.fireRegistering(fromAddress.toString());
            // Request URI
            SipURI requestURI = null;
            try {
                requestURI = sipManCallback.addressFactory.createSipURI(null,
                        registrarAddress);
            }
            catch (ParseException ex) {

                throw new CommunicationsException("Bad registrar address:"
                        + registrarAddress, ex);
            }
            catch (NullPointerException ex) {
                // Do not throw an exc, we should rather silently notify the
                // user
                // throw new CommunicationsException("A registrar address was
                // not specified!", ex);
                sipManCallback.fireUnregistered(fromAddress.getURI().toString()
                        + " (registrar not specified)");
                return;
            }

            requestURI.setPort(registrarPort);
            try {
                requestURI.setTransportParam(registrarTransport);
            }
            catch (ParseException ex) {
                throw new CommunicationsException(registrarTransport
                        + " is not a valid transport!", ex);
            }
View Full Code Here

            throws CommunicationsException {
        if (fromHeader != null && !isNew) {
            return fromHeader;
        }
        try {
            SipURI fromURI = (SipURI) addressFactory
                    .createURI(currentlyUsedURI);

            fromURI.setTransportParam(listeningPoint.getTransport());

            fromURI.setPort(listeningPoint.getPort());
            Address fromAddress = addressFactory.createAddress(fromURI);
            if (displayName != null && displayName.trim().length() > 0) {
                fromAddress.setDisplayName(displayName);
            } else {
                fromAddress
View Full Code Here

        if (contactHeader != null) {
            return contactHeader;
        }
        try {

            SipURI contactURI;

            if (useLocalHostAddress) {
                contactURI = addressFactory.createSipURI(null,
                        UserCredentials.getUserDisplay()
                                + "@"
                                + publicIpAddress.getAddress()
                                .getHostAddress());
            } else {
                contactURI = (SipURI) addressFactory
                        .createURI(currentlyUsedURI);
            }

            contactURI.setPort(publicIpAddress.getPort());
            Address contactAddress = addressFactory
                    .createAddress(contactURI);
            if (displayName != null && displayName.trim().length() > 0) {
                contactAddress.setDisplayName(displayName);
            }
View Full Code Here

       
        return request;      
    }
   
    private void createFromHeader() throws ParseException {
        SipURI fromAddress = getAddressFactory().createSipURI(getFromUser(), getFromHost());
        fromAddress.setPort(Integer.valueOf(getFromPort()).intValue());
        Address fromNameAddress = addressFactory.createAddress(fromAddress);
        fromNameAddress.setDisplayName(getFromUser());
       
        setFromHeader(headerFactory.createFromHeader(fromNameAddress, getFromUser() + "_Header"));       
    }
View Full Code Here

TOP

Related Classes of javax.sip.address.SipURI

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.