Example usage for java.net MalformedURLException getCause

List of usage examples for java.net MalformedURLException getCause

Introduction

In this page you can find the example usage for java.net MalformedURLException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.ts.db.connector.ConnectorDriverManager.java

static Driver getDriver(String url, String driverClassName, String classpath) throws SQLException {
    assert !StringUtils.isBlank(url);
    final boolean hasClasspath = !StringUtils.isBlank(classpath);
    if (!hasClasspath) {
        for (Driver driver : new ArrayList<Driver>(drivers)) {
            if (driver.acceptsURL(url)) {
                return driver;
            }/* w  ww  .j  a  v a 2  s .co  m*/
        }
    }
    List<File> jars = new ArrayList<File>();
    ClassLoader cl;
    if (hasClasspath) {
        List<URL> urls = new ArrayList<URL>();
        for (String path : classpath.split(pathSeparator)) {
            final File file = new File(path);
            if (isJarFile(file)) {
                jars.add(file);
            }
            try {
                urls.add(file.toURI().toURL());
            } catch (MalformedURLException ex) {
                log.warn(ex.toString());
            }
        }
        cl = new URLClassLoader(urls.toArray(new URL[urls.size()]));
    } else {
        jars.addAll(getJarFiles("."));
        jars.addAll(driverFiles);
        List<URL> urls = new ArrayList<URL>();
        for (File file : jars) {
            try {
                urls.add(file.toURI().toURL());
            } catch (MalformedURLException ex) {
                log.warn(ex.toString());
            }
        }
        cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), ClassLoader.getSystemClassLoader());
    }
    driverFiles.addAll(jars);
    final boolean hasDriverClassName = !StringUtils.isBlank(driverClassName);
    if (hasDriverClassName) {
        try {
            Driver driver = DynamicLoader.newInstance(driverClassName, cl);
            assert driver != null;
            return driver;
        } catch (DynamicLoadingException ex) {
            Throwable cause = (ex.getCause() != ex) ? ex.getCause() : ex;
            SQLException exception = new SQLException(cause.toString());
            exception.initCause(cause);
            throw exception;
        }
    }
    final String jdbcDrivers = System.getProperty("jdbc.drivers");
    if (!StringUtils.isBlank(jdbcDrivers)) {
        for (String jdbcDriver : jdbcDrivers.split(":")) {
            try {
                Driver driver = DynamicLoader.newInstance(jdbcDriver, cl);
                if (driver != null) {
                    if (!hasClasspath) {
                        drivers.add(driver);
                    }
                    return driver;
                }
            } catch (DynamicLoadingException ex) {
                log.warn(ex.toString());
            }
        }
    }
    for (File jar : jars) {
        try {
            Driver driver = getDriver(jar, url, cl);
            if (driver != null) {
                if (!hasClasspath) {
                    drivers.add(driver);
                }
                return driver;
            }
        } catch (IOException ex) {
            log.warn(ex.toString());
        }
    }
    for (String path : System.getProperty("java.class.path", "").split(pathSeparator)) {
        if (isJarFile(path)) {
            Driver driver;
            try {
                driver = getDriver(new File(path), url, cl);
                if (driver != null) {
                    drivers.add(driver);
                    return driver;
                }
            } catch (IOException ex) {
                log.warn(ex.toString());
            }
        }
    }
    throw new SQLException("driver not found");
}

From source file:it.geosolutions.geofence.gui.server.service.impl.InstancesManagerServiceImpl.java

public void testConnection(it.geosolutions.geofence.gui.client.model.GSInstance instance)
        throws ApplicationException {
    try {//from   w  w  w.j a  v a2 s.c  om
        String response = getURL(instance.getBaseURL() + "/rest/geofence/info", instance.getUsername(),
                instance.getPassword());
        if (response != null) {
            if (!response.equals(instance.getName())) {
                if (response.contains("Geoserver Configuration API")) { // some heuristic here
                    logger.error("GeoFence probe not installed on " + instance.getName());
                    throw new ApplicationException("GeoFence probe not installed on " + instance.getName());
                } else {
                    logger.error("Wrong instance name: " + response);
                    throw new ApplicationException(
                            "Wrong instance name: " + instance.getName() + ", should be :" + response);
                }
            }
        } else {
            throw new ApplicationException("Error contacting GeoServer");
        }
    } catch (MalformedURLException e) {
        logger.error(e.getLocalizedMessage(), e.getCause());
        throw new ApplicationException(e.getLocalizedMessage(), e.getCause());
    }
}

From source file:com.sun.socialsite.web.ui.admin.struts2.GadgetRegistrationReview.java

@Override
public String execute() {
    try {/*from   ww  w . ja  v  a 2  s.c om*/
        com.sun.socialsite.business.AppManager amgr = Factory.getSocialSite().getAppManager();
        if (id == null) {
            String[] idArray = (String[]) parameters.get("id");
            if (idArray == null) {
                addError("GadgerRegistrationReview.needId");
            } else {
                id = idArray[0];
            }
        }
        appRegistration = amgr.getAppRegistration(id);
        gadgetSpec = amgr.getGadgetSpecByURL(new URL(appRegistration.getAppUrl()));

    } catch (MalformedURLException ex) {
        // error parsing gadget spec url
        addError("GadgerRegistrationReview.badUrl");

    } catch (SocialSiteException ex) {
        if (ex.getCause() instanceof SpecParserException) {
            // error parsing gadget spec, could be 404 or bad XML
            // try to give as much info as possible
            addError("GadgerRegistrationReview.cannotParseGadgetSpec");
            if (ex.getCause() != null) {
                addError(ex.getCause().getMessage());
                if (ex.getCause().getCause() != null) {
                    addError(ex.getCause().getCause().getMessage());
                }
            }
        } else {
            // error fetching app registration from database
            // try to give as much info as possible
            addError("GadgerRegistrationReview.cannotFindRegistration");
            if (ex.getCause() != null) {
                addError(ex.getCause().getMessage());
                if (ex.getCause().getCause() != null) {
                    addError(ex.getCause().getCause().getMessage());
                }
            }
        }
    }
    return INPUT;
}

From source file:api.v2.LabdooClient.java

public LabdooClient(String url) throws APIException {
    this.url = url;

    try {/*from   ww  w  . ja va 2  s .  c o m*/
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        if (!url.startsWith("mock:")) {
            config.setServerURL(new URL(url));
            client = new XmlRpcClient();
            client.setConfig(config);
        } else {
            client = new MockXmlRpcClient();
        }
    } catch (MalformedURLException e) {
        log.error(e.getMessage());
        APIException apiException = new APIException();
        apiException.initCause(e.getCause());
        throw apiException;
    }

}

From source file:org.esupportail.portlet.filemanager.services.cifs.CifsAccessImpl.java

@Override
public void open(SharedUserPortletParameters userParameters) {
    super.open(userParameters);

    if (!this.isOpened()) {
        // we set the jcifs properties given in the bean for the drive
        if (this.jcifsConfigProperties != null && !this.jcifsConfigProperties.isEmpty()) {
            Config.setProperties(jcifsConfigProperties);
        }/* w  w  w.  ja  v  a 2s. c om*/

        try {
            if (userAuthenticatorService != null) {
                UserPassword userPassword = userAuthenticatorService.getUserPassword(userParameters);
                userAuthenticator = new NtlmPasswordAuthentication(userPassword.getDomain(),
                        userPassword.getUsername(), userPassword.getPassword());
                SmbFile smbFile = new SmbFile(this.getUri(), userAuthenticator);
                if (smbFile.exists()) {
                    root = smbFile;
                }
            }
        } catch (MalformedURLException me) {
            log.error(me, me.getCause());
            throw new EsupStockException(me);
        } catch (SmbAuthException e) {
            if (e.getNtStatus() == NtStatus.NT_STATUS_WRONG_PASSWORD) {
                log.error("connect" + " :: bad password ");
                throw new EsupStockException(e);
            } else if (e.getNtStatus() == NtStatus.NT_STATUS_LOGON_FAILURE) {
                log.error("connect" + " :: bad login ");
                throw new EsupStockException(e);
            } else {
                log.error("connect" + " :: " + e);
                throw new EsupStockException(e);
            }
        } catch (SmbException se) {
            log.error("connect" + " :: " + se);
            throw new EsupStockException(se);
        }
    }
}

From source file:solidbase.Main.java

/**
 * Reload SolidBase with an extended classpath. Calls {@link #pass2(String...)} when it's done.
 *
 * @param args The arguments from the command line.
 * @param jars The jars that need to be added to the classpath.
 * @param verbose Show more information.
 * @throws SQLExecutionException When an {@link SQLException} is thrown during execution of a database change.
 */// www. j av  a2  s .co m
static protected void reload(String[] args, List<String> jars, boolean verbose) throws SQLExecutionException {
    if (jars == null || jars.isEmpty()) {
        // No need to add a new classloader
        pass2(args);
        return;
    }

    if (verbose)
        console.println("Extending classpath");

    // Add the driver jar(s) to the classpath
    URLClassLoader classLoader = (URLClassLoader) Main.class.getClassLoader();
    URL[] orig = classLoader.getURLs();
    URL[] urls;
    urls = new URL[orig.length + jars.size()];
    System.arraycopy(orig, 0, urls, 0, orig.length);
    int i = orig.length;
    for (String jar : jars) {
        File driverJarFile = new File(jar);
        try {
            urls[i++] = driverJarFile.toURI().toURL();
        } catch (MalformedURLException e) {
            throw new SystemException(e);
        }
        if (verbose)
            console.println("Adding jar to classpath: " + urls[i - 1]);
    }

    if (verbose)
        console.println();

    // Create a new classloader with the new classpath
    classLoader = new URLClassLoader(urls, Main.class.getClassLoader().getParent());

    // Execute the main class through the new classloader with reflection
    Class<?> main;
    try {
        main = classLoader.loadClass("solidbase.Main");
    } catch (ClassNotFoundException e) {
        throw new SystemException(e);
    }
    Method method;
    try {
        method = main.getDeclaredMethod("pass2", String[].class);
    } catch (SecurityException e) {
        throw new SystemException(e);
    } catch (NoSuchMethodException e) {
        throw new SystemException(e);
    }
    // TODO Should we change the contextClassLoader too?
    try {
        method.invoke(method, (Object) args);
    } catch (IllegalArgumentException e) {
        throw new SystemException(e);
    } catch (IllegalAccessException e) {
        throw new SystemException(e);
    } catch (InvocationTargetException e) {
        throw new SystemException(e.getCause());
    }
}

From source file:org.walkmod.gradle.providers.ClassLoaderConfigurationProvider.java

@Override
public void load() throws ConfigurationException {
    if (configuration != null) {

        try {//from w  w w  .j  a  va  2s  .com
            compile();
        } catch (Exception e1) {
            throw new ConfigurationException("Error compiling the project", e1.getCause());
        }
        List<File> classPathList = getClassPathFiles();
        String[] bootPath = System.getProperties().get("sun.boot.class.path").toString()
                .split(Character.toString(File.pathSeparatorChar));
        URL[] classPath = new URL[classPathList.size() + bootPath.length];

        int i = 0;
        for (String lib : bootPath) {

            try {
                classPath[i] = new File(lib).toURI().toURL();
            } catch (MalformedURLException e) {
                throw new ConfigurationException("Invalid URL for the boot classpath entry " + lib,
                        e.getCause());
            }

            i++;
        }

        if (!classPathList.isEmpty()) {

            for (File entry : classPathList) {
                try {
                    classPath[i] = entry.toURI().toURL();
                } catch (MalformedURLException e) {
                    throw new ConfigurationException(
                            "Invalid URL for the dependency " + entry.getAbsolutePath(), e.getCause());
                }
                i++;
            }

        }
        URLClassLoader loader = new URLClassLoader(classPath) {
            @Override
            protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
                Class<?> result = null;
                try {
                    result = findClass(name);

                } catch (Throwable e) {

                }
                if (result != null) {
                    return result;
                }

                return super.loadClass(name, resolve);
            }

            @Override
            public Class<?> loadClass(String name) throws ClassNotFoundException {
                return loadClass(name, false);
            }
        };
        configuration.getParameters().put("classLoader", loader);

    }
}

From source file:org.openimaj.image.dataset.BingImageDataset.java

/**
 * Loads the image in {@code next} and converts it to the type {@code <IMAGE>}
 * @param next the image source to load the image from
 * @return the loaded and converted image if loading the image worked,
 *         {@code null} otherwise/*from   w  ww. j  av a  2  s. c  om*/
 */
private IMAGE read(ImageDataSourceResponse next) {
    if (next == null)
        return null;

    final String imageURL = next.getContentUrl();

    InputStream stream = null;
    try {
        stream = HttpUtils.readURL(new URL(imageURL));

        return reader.read(stream);
    } catch (final MalformedURLException e) {
        //if the URL is malformed, something went wrong with programming
        throw new RuntimeException(e);
    } catch (final IOException e) {
        if (e.getCause() instanceof org.apache.sanselan.ImageReadException) {
            // image urls that redirect to html pages will have this error (eg tinypic.com)
            System.out.println("The following URL didn't redirect to an image: " + imageURL);
        } else {
            // there was some issue with loading data from the URL
            e.printStackTrace();
        }
        return null;
    } finally {
        try {
            if (stream != null)
                stream.close();
        } catch (final IOException e) {
            // ignore
        }
    }
}

From source file:org.hyperic.hq.product.jmx.MxUtil.java

static Object getValue(Metric metric)
        throws MetricNotFoundException, MetricInvalidException, MetricUnreachableException, PluginException {
    String objectName = Metric.decode(metric.getObjectName());
    String attribute = metric.getAttributeName();
    Properties config = metric.getProperties();

    try {// ww w. j a v  a  2  s .  co m
        return getValue(config, objectName, attribute);
    } catch (MalformedURLException e) {
        throw invalidURL(metric.getProperties(), e);
    } catch (MalformedObjectNameException e) {
        throw invalidObjectName(objectName, e);
    } catch (IOException e) {
        removeMBeanConnector(config);
        if (metric.isAvail()) {
            return new Double(Metric.AVAIL_DOWN);
        }
        throw unreachable(metric.getProperties(), e);
    } catch (MBeanException e) {
        throw error(metric.toString(), e);
    } catch (AttributeNotFoundException e) {
        //XXX not all MBeans have a reasonable attribute to
        //determine availability, so just assume if we get this far
        //the MBean exists and is alive.
        if (metric.isAvail()) {
            return new Double(Metric.AVAIL_UP);
        }
        throw attributeNotFound(objectName, metric.getAttributeName(), e);
    } catch (InstanceNotFoundException e) {
        if (metric.isAvail()) {
            return new Double(Metric.AVAIL_DOWN);
        }
        throw objectNotFound(objectName, e);
    } catch (UndeclaredThrowableException e) {
        Throwable cause1 = e.getCause();
        if (cause1 instanceof InvocationTargetException) {
            Throwable cause2 = cause1.getCause();
            if (cause2 instanceof InstanceNotFoundException) {
                throw objectNotFound(objectName, (InstanceNotFoundException) cause2);
            }
        }

        throw e;
    } catch (ReflectionException e) {
        throw error(metric.toString(), e);

    } catch (RuntimeException e) {
        // Temporary fix until availability strings can be mapped
        // in hq-plugin.xml.  Resin wraps AttributeNotFoundException
        if (metric.isAvail()) {
            Throwable cause = e.getCause();
            while (cause != null) {
                if (cause instanceof AttributeNotFoundException) {
                    return new Double(Metric.AVAIL_UP);
                } else if (cause instanceof InstanceNotFoundException) {
                    return new Double(Metric.AVAIL_DOWN);
                }
                cause = cause.getCause();
            }
        }
        throw e;
    }
}

From source file:org.dspace.license.CCLookup.java

/**
    * Passes a set of "answers" to the web service and retrieves a license.
    *//from   w  ww .  ja v a 2  s . com
    * @param licenseURI The uri of the license.
    *
    * Note: does not support localization in 1.5 -- not yet
    *
    * @throws IOException
    *
    * @see CCLicense
    * @see Map
    */
public void issue(String licenseURI) throws IOException {

    // Determine the issue URL
    // Example: http://api.creativecommons.org/rest/1.5/details?
    //  license-uri=http://creativecommons.org/licenses/by-nc-sa/3.0/
    String issueUrl = cc_root + "/details?license-uri=" + licenseURI;

    URL request_url;
    try {
        request_url = new URL(issueUrl);
    } catch (MalformedURLException e) {
        return;
    }
    URLConnection connection = request_url.openConnection();
    // this will not be needed after I'm done TODO: remove
    connection.setDoOutput(true);
    try {
        // parsing document from input stream
        java.io.InputStream stream = connection.getInputStream();
        license_doc = this.parser.build(stream);
    } catch (JDOMException jde) {
        log.warn(jde.getMessage());
    } catch (Exception e) {
        log.warn(e.getCause());
    }
    return;
}