Package javax.sip.address

Examples of javax.sip.address.URI


    try
    {
      AddressFactory addressFactory = getAddressFactory();

      List<ViaHeader> viaHeaders = _sipPhone.getViaHeaders();
      URI requestUri = addressFactory.createURI(to);
      Address toAddr = addressFactory.createAddress(requestUri);

      Request request = getMessageFactory().createRequest(
          requestUri,
          method,
View Full Code Here


            if (contact != null)
                displayName = contact.getDisplayName();
            else
            {
                URI peerURI = getPeerAddress().getURI();

                if (peerURI instanceof SipURI)
                {
                    String userName = ((SipURI) peerURI).getUser();

                    if (userName != null && userName.length() > 0)
                        displayName = userName;
                }
                else
                {
                    displayName = peerURI.toString();
                }
            }
        }

        if(displayName.startsWith("sip:"))
View Full Code Here

            if (contact != null)
                displayName = contact.getDisplayName();
            else
            {
                URI peerURI = getPeerAddress().getURI();

                if (peerURI instanceof SipURI)
                {
                    String userName = ((SipURI) peerURI).getUser();

                    if (userName != null && userName.length() > 0)
                        displayName = userName;
                }
                else
                {
                    displayName = peerURI.toString();
                }
            }
        }

        if(displayName.startsWith("sip:"))
View Full Code Here

                    if ( credHash == null ) {
                        sipStack.getStackLogger().logDebug("Could not find creds");
                        throw new SipException(
                        "Cannot find user creds for the given user name and realm");
                    }
                    URI uri = reoriginatedRequest.getRequestURI();
                    sipDomain = credHash.getSipDomain();
                    authorization = this.getAuthorization(reoriginatedRequest
                            .getMethod(), uri.toString(),
                            (reoriginatedRequest.getContent() == null) ? "" : new String(
                            reoriginatedRequest.getRawContent()), authHeader, credHash);
                } else {
                    UserCredentials userCreds = ((AccountManager) this.accountManager).getCredentials(challengedTransaction, realm);
                   
View Full Code Here

        }
      } else {
        super.parse(contact);
      }
      AddressImpl address = (AddressImpl) contact.getAddress();
      URI uri = contact.getAddress().getURI();
      /*
       * When the header field value contains a display name, the URI
       * including all URI parameters is enclosed in "<" and ">". If no "<"
       * and ">" are present, all parameters after the URI are header
       * parameters, not URI parameters.
View Full Code Here

      toNameAddress.setDisplayName(toDisplayName);
      ToHeader toHeader = headerFactory.createToHeader(toNameAddress,
          null);

      // create Request URI
      URI requestURI = addressFactory.createURI("tel:46317014291;phone-context=+5");
   
      // Create ViaHeaders

      ArrayList viaHeaders = new ArrayList();
      ViaHeader viaHeader = headerFactory.createViaHeader("127.0.0.1",
View Full Code Here

        }
    }
   
    public void testGoodURIs() throws Exception {
        for (int i = 0; i < goodURIs.length; i++) {
          URI uri = uri(goodURIs[i]);
        }
    }
View Full Code Here

    }
   
    public void testBadURIs() throws Exception {
        for (int i = 0; i < badURIs.length; i++) {
          try {
            URI uri = uri(badURIs[i]);
            fail(uri + " should throw parse exception");
          } catch (ParseException e) {
             // ok
          }
        }
View Full Code Here

         */

        HeaderFactory headerFactory = jiplet.getHeaderFactory();
        AddressFactory addressFactory = jiplet.getAddressFactory();
        // Get the parameters and the transport of the request URI
        URI requestURI = requestEvent.getRequest().getRequestURI();
        Iterator parametersNames = null;

        if (requestURI.isSipURI())
        {
            parametersNames = ((SipURI) requestURI).getParameterNames();

            // this is how the JAIN-SIP jiplet guys have done it but it seems
            // problematic. Why?
            // transport = ((SipURI) requestURI).getTransportParam();
        }

        for (int i = 0; i < targetsURIList.size(); i++)
        {
            URI targetURI = (URI) targetsURIList.get(i);

            // Copy the parameters and the transport in the new Request URI
            // of the cloned Request

            //           
            // 1. Make a clone of the received request
            //           
            //           

            Request clonedRequest = (Request) requestEvent.getRequest().clone();

            //           
            // 2. Update the Request-URI
            //         

            /*
             * The Request-URI in the copy's start line MUST be replaced with
             * the URI for this target. If the URI contains any parameters not
             * allowed in a Request-URI, they MUST be removed.
             *
             * This is the essence of a jiplet's role. This is the mechanism
             * through which a jiplet routes a request toward its destination.
             *
             * In some circumstances, the received Request-URI is placed into
             * the target set without being modified. For that target, the
             * replacement above is effectively a no-op.
             *
             */
            // All the targets URI are already canonicalized
            if (requestURI.isSipURI())
            {
                clonedRequest.setRequestURI(targetURI);
            }

            //           
            // 3. Max-Forwards
            //           
            /*
             * If the copy contains a Max-Forwards header field, the jiplet MUST
             * decrement its value by one (1). If the copy does not contain a
             * Max-Forwards header field, the jiplet MUST add one with a field
             * value, which SHOULD be 70.
             */
            MaxForwardsHeader mf = (MaxForwardsHeader) clonedRequest
                    .getHeader(MaxForwardsHeader.NAME);
            if (mf == null)
            {
                mf = headerFactory.createMaxForwardsHeader(70);
                clonedRequest.addHeader(mf);
            }
            else
            {
                int max = mf.getMaxForwards() - 1;
                mf.setMaxForwards(max);
            }

            //           
            // 4. Record-Route
            //           
            /*
             * The URI placed in the Record-Route header field value MUST be a
             * SIP or SIPS URI. This URI MUST contain an lr parameter (see
             * Section 19.1.1). This URI MAY be different for each destination
             * 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);
                    RecordRouteHeader recordRouteHeader = headerFactory
                            .createRecordRouteHeader(address);

                    ListIterator recordRouteHeaders = clonedRequest
                            .getHeaders(RecordRouteHeader.NAME);
                    clonedRequest.removeHeader(RecordRouteHeader.NAME);
                    ArrayList v = new ArrayList();
                    v.add(recordRouteHeader);

                    // add the other record route headers.
                    while (recordRouteHeaders != null
                            && recordRouteHeaders.hasNext())
                    {
                        recordRouteHeader = (RecordRouteHeader) recordRouteHeaders
                                .next();
                        v.add(recordRouteHeader);
                    }

                    for (int j = 0; j < v.size(); j++)
                    {
                        recordRouteHeader = (RecordRouteHeader) v.get(j);
                        clonedRequest.addHeader(recordRouteHeader);
                    }
                }
            }

            //           
            // 5. Add Additional Header Fields
            //

            // No Additional headers to add...

            //           
            // 6. Postprocess routing information
            //           
            /*
             * If the copy contains a Route header field, the jiplet MUST
             * inspect the URI in its first value. If that URI does not contain
             * an lr parameter, the jiplet MUST modify the copy as follows: -
             * The jiplet MUST place the Request-URI into the Route header field
             * as the last value. - The jiplet MUST then place the first Route
             * header field value into the Request-URI and remove that value
             * from the Route header field.
             */

            // Strip first route if it is the jiplet UIR adn lr parameter
            ListIterator routes = clonedRequest.getHeaders(RouteHeader.NAME);
            if (routes != null && routes.hasNext())
            {

                RouteHeader routeHeader = (RouteHeader) routes.next();
                Address routeAddress = routeHeader.getAddress();
                URI routeURI = routeAddress.getURI();

                if (routeURI.isSipURI() && ((SipURI) routeURI).hasLrParam())
                {
                    String host = ((SipURI) routeURI).getHost();
                    int port = ((SipURI) routeURI).getPort();

                    if (jiplet.hasAddress(host, port))
View Full Code Here

             * 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))
            {
                if (jiplet.isDebugEnabled() == true)
                    jiplet.debug("While proxying a request, the request "
                            + " to fork is not an INVITE, so we will process"
                            + " it with the first target as the only target.");

                URI uri = (URI) uris.get(0);
                uris.clear();
                uris.add(uri);

                // 4. Forward the request to the target:
                RequestForwarding forwarder = new RequestForwarding(jiplet,
View Full Code Here

TOP

Related Classes of javax.sip.address.URI

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.