Package org.glassfish.comms.api.telurl

Examples of org.glassfish.comms.api.telurl.TelUrlResolverException


    }

    protected SipURI doLookupSipURI(URI uri) throws TelUrlResolverException {
        // validate uri
        if (!isTelephoneNumber(uri)) {
            throw new TelUrlResolverException("The uri is not a phone number:" +
                uri);
        }

        TelURL telUrl = null;

        if (uri.isSipURI()) {
            try {
                telUrl = UriUtil.convertToTelURL((SipURI) uri);
            } catch (UriUtilException e) {
                throw new TelUrlResolverException("Could not convert URI: \"" +
                    uri + "\" to Tel-URL", e);
            }

            if (logger.isLoggable(Level.FINEST)) {
                logger.log(Level.FINEST,
                    "Sip-URI was converted to Tel-URL: " + telUrl);
            }
        } else if (uri.getScheme().equals(SipFactoryImpl.TEL_URI_PROTOCOL)) {
            telUrl = (TelURL) uri;
        }

        String phoneNumber;

        if (telUrl.isGlobal()) {
            phoneNumber = telUrl.getPhoneNumber();
        } else {
            String phoneContext;

            if ((phoneContext = telUrl.getPhoneContext()) == null) {
                throw new TelUrlResolverException("The local number is missing a phone-context: "+telUrl);
            } else {
                phoneNumber = normalize(telUrl.getPhoneNumber(), phoneContext);

                if (phoneNumber == null) {
                    throw new TelUrlResolverException("Could not normalize the phone number: "+telUrl);
                }
                if (logger.isLoggable(Level.FINEST)) {
                    logger.log(Level.FINEST,
                        "The number in the Tel-URL: " + telUrl +
                        " was normalized to " + phoneNumber);
                }
            }
        }

        try {
            String AUS = EnumUtil.getAUSValue(phoneNumber);
            String domainNameToLookup = EnumUtil.toDomain(AUS, myEnumTopDomain);

            return lookupTelUrlNAPTRRecord(AUS, domainNameToLookup,
                new HashSet<String>(), 1);
        } catch (DnsServerUnavailableException dnsue) {
            // All runtime exceptions except DnsServerUnavailableException
            // should be wrapped into a TelUrlResolverException
            throw dnsue;
        } catch (RuntimeException rte) {
            throw new TelUrlResolverException(rte);
        }
    }
View Full Code Here


    */
    protected SipURI lookupTelUrlNAPTRRecord(String AUS,
        String e164arpa_domain, Set<String> visited, int depth)
        throws TelUrlResolverException {
        if ((depth > EnumUtil.MAX_DEPTH) || !visited.add(e164arpa_domain)) {
            throw new TelUrlResolverException("Loop detected when resolving:" +
                AUS);
        }

        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE,
                "depth:" + depth + " AUS:" + AUS + " domain:" +
                e164arpa_domain);
        }

        try {
            Record[] records = doLookup(e164arpa_domain, Type.NAPTR);
            Arrays.sort(records, new NaptrComparator());

            for (Record record : records) {
                NAPTRRecord naptrRecord = (NAPTRRecord) record;

                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE,
                        "number of DNS/NAPTR records:" + records.length);
                    logger.log(Level.FINE,
                        "NAPTRRecord.toString():" + record.toString());
                }

                String flag = naptrRecord.getFlags();
                String service = naptrRecord.getService();
                Name replacement = naptrRecord.getReplacement();

                if (service.equalsIgnoreCase("E2U+sip") ||
                        service.equalsIgnoreCase("sip+E2U")) {
                    if (logger.isLoggable(Level.FINE)) {
                        logger.log(Level.FINE,
                            "flag:" + naptrRecord.getFlags() + " flaglength:" +
                            naptrRecord.getFlags().length());
                        logger.log(Level.FINE,
                            "regexp:" + naptrRecord.getRegexp() +
                            " replacement:" + replacement);
                    }

                    if (!EnumUtil.isEmpty(replacement) && (flag.length() == 0)) {
                        return lookupTelUrlNAPTRRecord(AUS,
                            replacement.toString(), visited, ++depth);
                    }

                    String substitution = EnumUtil.applyRegExp(AUS,
                            naptrRecord.getRegexp());

                    if (substitution == null) {
                        // try next record
                        continue;
                    }

                    if (flag.equals("u")) {
                        int separator = substitution.indexOf(':');

                        if (separator == -1) {
                            throw new TelUrlResolverException(
                                "The regexp substitution result is not any supported uri:" +
                                substitution);
                        }

                        String schemePart = substitution.substring(0, separator);

                        String theUriPart = substitution.substring(separator +
                                1);

                        if (schemePart.equals(SipFactoryImpl.TEL_URI_PROTOCOL)) {
                            return lookupTelUrlNAPTRRecord(AUS,
                                EnumUtil.toDomain(theUriPart, myEnumTopDomain),
                                visited, ++depth);
                        } else if (schemePart.equals(
                                    SipFactoryImpl.SIP_URI_PROTOCOL) ||
                                schemePart.equals(
                                    SipFactoryImpl.SIPS_URI_PROTOCOL)) {
                            try {
                                SipURIImpl sipuri = new SipURIImpl(schemePart,
                                        theUriPart, 0);

                                // check user=phone etc here
                                String userParam = sipuri.getParameter("user");

                                if ((userParam != null) &&
                                        userParam.equals("phone")) {
                                    String userTelUrl = sipuri.getUser();

                                    return lookupTelUrlNAPTRRecord(AUS,
                                        EnumUtil.toDomain(userTelUrl,
                                            myEnumTopDomain), visited, ++depth);
                                }

                                return sipuri;
                            } catch (ServletParseException e) {
                                throw new TelUrlResolverException(e);
                            }
                        } else {
                            throw new TelUrlResolverException(
                                "The regexp substitution result is not any supported uri:" +
                                substitution);
                        }
                    } else if (flag.length() == 0) {
                        return lookupTelUrlNAPTRRecord(AUS, substitution,
View Full Code Here

TOP

Related Classes of org.glassfish.comms.api.telurl.TelUrlResolverException

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.