Package java.net

Examples of java.net.MalformedURLException


      // Fail if no valid key store was located
      if (url == null)
      {
         String msg = "Failed to find url=" + storeURL + " as a URL, file or resource";
         throw new MalformedURLException(msg);
      }
      return url;
   }
View Full Code Here


    * @throws MalformedURLException if the pathname is not given in the correct form
    */
   public URL getResource(String path) throws MalformedURLException
   {
      if (path == null || path.length() == 0 || path.charAt(0) != '/')
         throw new MalformedURLException("Path " + path + " is not in acceptable form.");
      File resFile = new File(getRealPath(path));
      if (resFile.exists()) // TODO get canonical path is more robust
         return new URL("file", "localhost", resFile.getPath());
      return null;
   }
View Full Code Here

            // ensure that the seed file url is configured properly
            DigestURI seedURL;
            try {
                final String seedURLStr = sb.peers.mySeed().get(yacySeed.SEEDLISTURL, "");
                if (seedURLStr.length() == 0) { throw new MalformedURLException("The seed-file url must not be empty."); }
                if (!(
                        seedURLStr.toLowerCase().startsWith("http://") ||
                        seedURLStr.toLowerCase().startsWith("https://")
                )) {
                    throw new MalformedURLException("Unsupported protocol.");
                }
                seedURL = new DigestURI(seedURLStr);
            } catch (final MalformedURLException e) {
                final String errorMsg = "Malformed seed file URL '" + sb.peers.mySeed().get(yacySeed.SEEDLISTURL, "") + "'. " + e.getMessage();
                log.logWarning("SaveSeedList: " + errorMsg);
View Full Code Here

        this.ref = url.ref;
        this.port = url.port;
    }
   
    public MultiProtocolURI(String url) throws MalformedURLException {
        if (url == null) throw new MalformedURLException("url string is null");
       
        // identify protocol
        assert (url != null);
        url = url.trim();
        //url = patternSpace.matcher(url).replaceAll(" ");
        if (url.startsWith("\\\\")) {
            url = "smb://" + patternBackSlash.matcher(url.substring(2)).replaceAll("/");
        }
       
        if (url.length() > 1 && url.charAt(1) == ':') {
            // maybe a DOS drive path
            url = "file://" + url;
        }
       
        if (url.length() > 0 && url.charAt(0) == '/') {
            // maybe a unix/linux absolute path
            url = "file://" + url;
        }
       
        int p = url.indexOf(':');
        if (p < 0) {
            url = "http://" + url;
            p = 4;
        }
        this.protocol = url.substring(0, p).toLowerCase().trim();
        if (url.length() < p + 4) throw new MalformedURLException("URL not parseable: '" + url + "'");
        if (!this.protocol.equals("file") && url.substring(p + 1, p + 3).equals("//")) {
            // identify host, userInfo and file for http and ftp protocol
            final int q = url.indexOf('/', p + 3);
            int r;
            if (q < 0) {
                if ((r = url.indexOf('@', p + 3)) < 0) {
                    host = url.substring(p + 3);
                    userInfo = null;
                } else {
                    host = url.substring(r + 1);
                    userInfo = url.substring(p + 3, r);
                }
                path = "/";
            } else {
                host = url.substring(p + 3, q).trim();
                if ((r = host.indexOf('@')) < 0) {
                    userInfo = null;
                } else {
                    userInfo = host.substring(0, r);
                    host = host.substring(r + 1);
                }
                path = url.substring(q);
            }
            if (host.length() < 4 && !protocol.equals("file")) throw new MalformedURLException("host too short: '" + host + "', url = " + url);
            if (host.indexOf('&') >= 0) throw new MalformedURLException("invalid '&' in host");
            path = resolveBackpath(path);
            identPort(url, (isHTTP() ? 80 : (isHTTPS() ? 443 : (isFTP() ? 21 : (isSMB() ? 445 : -1)))));
            identRef();
            identQuest();
            escape();
        } else {
            // this is not a http or ftp url
            if (protocol.equals("mailto")) {
                // parse email url
                final int q = url.indexOf('@', p + 3);
                if (q < 0) {
                    throw new MalformedURLException("wrong email address: " + url);
                }
                userInfo = url.substring(p + 1, q);
                host = url.substring(q + 1);
                path = null;
                port = -1;
                quest = null;
                ref = null;
            } else if (protocol.equals("file")) {
                // parse file url
                String h = url.substring(p + 1);
                if (h.startsWith("//")) {
                    // no host given
                    host = null;
                    path = h.substring(2);
                } else {
                    host = null;
                    if (h.length() > 0 && h.charAt(0) == '/') {
                        char c = h.charAt(2);
                        if (c == ':' || c == '|')
                            path = h.substring(1);
                        else
                            path = h;
                    } else {
                        char c = h.charAt(1);
                        if (c == ':' || c == '|')
                            path = h;
                        else
                            path = "/" + h;
                    }
                }
                userInfo = null;
                port = -1;
                quest = null;
                ref = null;
            } else {
                throw new MalformedURLException("unknown protocol: " + url);
            }
        }
       
        // handle international domains
        if (!Punycode.isBasic(host)) try {
View Full Code Here

        }
        return new MultiProtocolURI(baseURL, relPath);
    }
   
    public MultiProtocolURI(final MultiProtocolURI baseURL, String relPath) throws MalformedURLException {
        if (baseURL == null) throw new MalformedURLException("base URL is null");
        if (relPath == null) throw new MalformedURLException("relPath is null");

        this.protocol = baseURL.protocol;
        this.host = baseURL.host;
        this.port = baseURL.port;
        this.userInfo = baseURL.userInfo;
        if (relPath.startsWith("//")) {
            // a "network-path reference" as defined in rfc2396 denotes
            // a relative path that uses the protocol from the base url
            relPath = baseURL.protocol + ":" + relPath;
        }
        if (relPath.toLowerCase().startsWith("javascript:")) {
            this.path = baseURL.path;
        } else if (
                isHTTP(relPath) ||
                isHTTPS(relPath) ||
                isFTP(relPath) ||
                isFile(relPath) ||
                isSMB(relPath)) {
            this.path = baseURL.path;
        } else if (relPath.contains(":") && patternMail.matcher(relPath.toLowerCase()).find()) { // discards also any unknown protocol from previous if
            throw new MalformedURLException("relative path malformed: " + relPath);
        } else if (relPath.length() > 0 && relPath.charAt(0) == '/') {
            this.path = relPath;
        } else if (baseURL.path.endsWith("/")) {
            if (relPath.length() > 0 && (relPath.charAt(0) == '#' || relPath.charAt(0) == '?')) {
                throw new MalformedURLException("relative path malformed: " + relPath);
            }
            this.path = baseURL.path + relPath;
        } else {
            if (relPath.length() > 0 && (relPath.charAt(0) == '#' || relPath.charAt(0) == '?')) {
                this.path = baseURL.path + relPath;
View Full Code Here

        identQuest();
        escape();
    }
   
    public MultiProtocolURI(final String protocol, final String host, final int port, final String path) throws MalformedURLException {
        if (protocol == null) throw new MalformedURLException("protocol is null");
        this.protocol = protocol;
        this.host = host;
        this.port = port;
        this.path = path;
        this.quest = null;
View Full Code Here

                final String portStr = this.host.substring(r + 1);
                if (portStr.trim().length() > 0) this.port = Integer.parseInt(portStr);
                else this.port =  -1;              
                this.host = this.host.substring(0, r);
            } catch (final NumberFormatException e) {
                throw new MalformedURLException("wrong port in host fragment '" + this.host + "' of input url '" + inputURL + "'");
            }
        }
    }
View Full Code Here

        String urlString = null;

        try {
            urlString = expandSysPropVars(url);
        } catch (IllegalArgumentException iae) {
            throw new MalformedURLException(iae.getMessage() + " for URL '"
                                            + url + "'");
        }

        String userString = null;

        if (username != null) try {
            userString = expandSysPropVars(username);
        } catch (IllegalArgumentException iae) {
            throw new MalformedURLException(iae.getMessage()
                                            + " for user name '" + username
                                            + "'");
        }

        String passwordString = null;

        if (password != null) try {
            passwordString = expandSysPropVars(password);
        } catch (IllegalArgumentException iae) {
            throw new MalformedURLException(iae.getMessage()
                                            + " for password");
        }

        Class.forName(curDriver);
        // This is not necessary for jdbc:odbc or if class loaded by a
View Full Code Here

          return null;
        }

        String basePath = new URL(moduleBase).getPath();
        if (basePath == null) {
          throw new MalformedURLException("Blocked request without GWT base path parameter (XSRF attack?)");
        }

        String contextPath = context.getContextPath();
        if (!basePath.startsWith(contextPath)) {
          throw new MalformedURLException("Blocked request with invalid GWT base path parameter (XSRF attack?)");
        }
        basePath = basePath.substring(contextPath.length());

        InputStream in = findClientOracleData(basePath, permutationStrongName, context);
View Full Code Here

        return (ImageDescriptor)imageDescriptors.get(key);
    }
   
    private static URL makeIconFileURL(String iconPath) throws MalformedURLException {
        if (ICON_BASE_URL == null) {
            throw new MalformedURLException();
        }
           
        return new URL(ICON_BASE_URL, iconPath);
    }
View Full Code Here

TOP

Related Classes of java.net.MalformedURLException

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.