Example usage for java.lang ClassNotFoundException getMessage

List of usage examples for java.lang ClassNotFoundException getMessage

Introduction

In this page you can find the example usage for java.lang ClassNotFoundException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.ephesoft.gxt.systemconfig.server.SystemConfigServiceImpl.java

@Override
public boolean testMSSQLAlwaysONConnection(String databaseName, String connectionURL) {
    boolean connectionSuccessful = false;
    if (!StringUtil.isNullOrEmpty(databaseName) && !StringUtil.isNullOrEmpty(connectionURL)) {
        java.sql.Connection conn = null;
        try {// www  . j a v  a  2  s.c  o  m
            Class.forName(ConnectionType.MSSQL_ALWAYSON.getDriver());
            conn = DriverManager.getConnection(connectionURL);
            if (conn != null) {
                connectionSuccessful = true;
            }
        } catch (SQLException sqlException) {
            log.error("Unable to make connection" + sqlException.getMessage());
        } catch (ClassNotFoundException classNotFoundException) {
            // TODO Auto-generated catch block
            log.error("Unable to make connection" + classNotFoundException.getMessage());
        } finally {
            try {
                if (conn != null) {
                    conn.close();

                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    return connectionSuccessful;
}

From source file:org.codehaus.mojo.webstart.JnlpMojo.java

private boolean artifactContainsClass(Artifact artifact, final String mainClass) throws MalformedURLException {
    boolean containsClass = true;

    // JarArchiver.grabFilesAndDirs()
    ClassLoader cl = new java.net.URLClassLoader(new URL[] { artifact.getFile().toURL() });
    Class c = null;//from   w  ww .j a va  2 s. c om
    try {
        c = Class.forName(mainClass, false, cl);
    } catch (ClassNotFoundException e) {
        getLog().debug("artifact " + artifact + " doesn't contain the main class: " + mainClass);
        containsClass = false;
    } catch (Throwable t) {
        getLog().info("artifact " + artifact + " seems to contain the main class: " + mainClass
                + " but the jar doesn't seem to contain all dependencies " + t.getMessage());
    }

    if (c != null) {
        getLog().debug("Checking if the loaded class contains a main method.");

        try {
            c.getMethod("main", new Class[] { String[].class });
        } catch (NoSuchMethodException e) {
            getLog().warn("The specified main class (" + mainClass
                    + ") doesn't seem to contain a main method... Please check your configuration."
                    + e.getMessage());
        } catch (NoClassDefFoundError e) {
            // undocumented in SDK 5.0. is this due to the ClassLoader lazy loading the Method thus making this a case tackled by the JVM Spec (Ref 5.3.5)!
            // Reported as Incident 633981 to Sun just in case ...
            getLog().warn("Something failed while checking if the main class contains the main() method. "
                    + "This is probably due to the limited classpath we have provided to the class loader. "
                    + "The specified main class (" + mainClass
                    + ") found in the jar is *assumed* to contain a main method... " + e.getMessage());
        } catch (Throwable t) {
            getLog().error("Unknown error: Couldn't check if the main class has a main method. "
                    + "The specified main class (" + mainClass
                    + ") found in the jar is *assumed* to contain a main method...", t);
        }
    }

    return containsClass;
}

From source file:com.netspective.commons.xdm.XmlDataModelSchema.java

protected Object createElement(XdmParseContext pc, String alternateClassName, Object element,
        String elementName) throws DataModelException, UnsupportedElementException {
    try {/*from w w  w  .j  av a  2s. c om*/
        if (alternateClassName != null) {
            Class cls = null;
            try {
                cls = Class.forName(alternateClassName);
            } catch (ClassNotFoundException e) {
                pc.addError("Class '" + alternateClassName + "' for element '" + elementName + "' not found at "
                        + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ". "
                        + e.getMessage());
                log.error(e);
                if (pc.isThrowErrorException())
                    throw new DataModelException(pc, e);
                else {
                    NestedCreator nc = (NestedCreator) nestedCreators.get(elementName);
                    if (nc != null)
                        return nc.create(element);
                }
            }

            NestedAltClassCreator nac = (NestedAltClassCreator) nestedAltClassNameCreators.get(elementName);
            if (nac != null)
                return nac.create(element, cls);
            else {
                // check to make sure that either a storer or creator is available to ensure it's a valid tag
                if (nestedCreators.get(elementName) != null || nestedStorers.get(elementName) != null)
                    return cls.newInstance();

                UnsupportedElementException e = new UnsupportedElementException(this, pc, element, elementName);
                if (pc != null) {
                    pc.addError(e);
                    if (pc.isThrowErrorException())
                        throw e;
                    else
                        return null;
                } else
                    return null;
            }
        } else {
            NestedCreator nc = (NestedCreator) nestedCreators.get(elementName);
            if (nc != null)
                return nc.create(element);
        }
    } catch (InvocationTargetException ite) {
        pc.addError("Could not create class '" + alternateClassName + "' for element '" + elementName + "' at "
                + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ": "
                + ite.getMessage());
        log.error(ite);
        if (pc.isThrowErrorException()) {
            Throwable t = ite.getTargetException();
            if (t instanceof DataModelException) {
                throw (DataModelException) t;
            }
            throw new DataModelException(pc, t);
        }
    } catch (Exception e) {
        pc.addError("Could not create class '" + alternateClassName + "' for element '" + elementName + "' at "
                + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ": "
                + e.getMessage());
        log.error(e);
        if (pc.isThrowErrorException())
            throw new DataModelException(pc, e);
    }

    // if the element is being defined as a sub-element but has an attribute of the same name, it's a convenience attribute setter
    AttributeSetter as = (AttributeSetter) attributeSetters.get(elementName);
    if (as != null)
        return element;
    else {
        // see if we're trying to set a named flag as a sub-element
        for (Iterator i = flagsAttributeAccessors.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();
            AttributeAccessor accessor = (AttributeAccessor) entry.getValue();
            Object returnVal = null;
            try {
                returnVal = accessor.get(pc, element);
            } catch (Exception e) {
            }

            if (returnVal instanceof XdmBitmaskedFlagsAttribute)
                return element;
        }

        UnsupportedElementException e = new UnsupportedElementException(this, pc, element, elementName);
        if (pc != null) {
            pc.addError(e);
            if (pc.isThrowErrorException())
                throw e;
            else
                return null;
        } else
            return null;
    }
}

From source file:ch.entwine.weblounge.common.impl.site.SiteImpl.java

/**
 * Loads the integration test classes from the class path and publishes them
 * to the OSGi registry./*from   ww  w . j ava2 s  .  co  m*/
 * 
 * @param path
 *          the bundle path to load classes from
 * @param bundle
 *          the bundle
 */
private List<IntegrationTest> loadIntegrationTestClasses(String path, Bundle bundle) {
    List<IntegrationTest> tests = new ArrayList<IntegrationTest>();

    // Load the classes in question
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    Enumeration<?> entries = bundle.findEntries("/", "*.class", true);
    if (entries == null) {
        return tests;
    }

    // Look at the classes and instantiate those that implement the integration
    // test interface.
    while (entries.hasMoreElements()) {
        URL url = (URL) entries.nextElement();
        Class<?> c = null;
        String className = url.getPath();
        try {
            className = className.substring(1, className.indexOf(".class"));
            className = className.replace('/', '.');
            c = loader.loadClass(className);
            boolean implementsInterface = Arrays.asList(c.getInterfaces()).contains(IntegrationTest.class);
            boolean extendsBaseClass = false;
            if (c.getSuperclass() != null) {
                extendsBaseClass = IntegrationTestBase.class.getName().equals(c.getSuperclass().getName());
            }
            if (!implementsInterface && !extendsBaseClass)
                continue;
            IntegrationTest test = (IntegrationTest) c.newInstance();
            test.setSite(this);
            tests.add(test);
        } catch (ClassNotFoundException e) {
            throw new IllegalStateException("Implementation " + className + " for integration test of class '"
                    + identifier + "' not found", e);
        } catch (NoClassDefFoundError e) {
            // We are trying to load each and every class here, so we may as well
            // see classes that are not meant to be loaded
            logger.debug("The related class " + e.getMessage() + " for potential test case implementation "
                    + className + " could not be found");
        } catch (InstantiationException e) {
            throw new IllegalStateException("Error instantiating impelementation " + className
                    + " for integration test '" + identifier + "'", e);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException("Access violation instantiating implementation " + className
                    + " for integration test '" + identifier + "'", e);
        } catch (Throwable t) {
            throw new IllegalStateException(
                    "Error loading implementation " + className + " for integration test '" + identifier + "'",
                    t);
        }

    }
    return tests;
}

From source file:de.bangl.lm.LotManagerPlugin.java

/**
 *
 *//*from  ww  w.  j  a  v  a2  s . c  om*/
@Override
public void onEnable() {
    this.server = getServer();
    this.pm = this.server.getPluginManager();

    Plugin ess = pm.getPlugin("Essentials");
    if (ess != null && ess instanceof Essentials) {
        this.hasEssentials = true;
        this.ess = (Essentials) ess;
    }

    if (!setupEconomy()) {
        logError("Disabled due to no Vault dependency found!");
        setEnabled(false);
        return;
    }
    try {
        this.lots = new LotManagerDatabase();
    } catch (Exception e3) {
        logError(e3.getMessage());
    }
    new File(this.dataFolder).mkdir();
    loadConfig();
    try {
        this.lots.sqlClass();
    } catch (ClassNotFoundException e) {
        logError("MySQL Class not loadable!");
        setEnabled(false);
    }
    try {
        this.lots.connect();
    } catch (SQLException e) {
        logError("MySQL connection failed!");
        setEnabled(false);
    }
    if (this.lots.getConnection() == null) {
        logInfo("Connection failed.");
        setEnabled(false);
        return;
    }
    try {
        if (!this.lots.checkTables()) {
            logInfo("Tables not found. created.");
            this.lots.Disconnect();
            setEnabled(false);
            return;
        }
    } catch (ClassNotFoundException e) {
        logError("Tablecheck failed!");
        setEnabled(false);
    } catch (SQLException e) {
        logError("Tablecheck failed!");
        setEnabled(false);
    }
    try {
        this.lots.load();
    } catch (ClassNotFoundException e) {
        logError(e.getMessage());
    } catch (SQLException e) {
        logError(e.getMessage());
    }
    try {
        this.wg = new WorldGuardWrapper(this.pm, this.server.getWorlds());
        if (this.wg == null) {
            logError("WorldGuardWrapper is null :O");
            setEnabled(false);
            return;
        }
        if (this.wg.getWG() == null) {
            logError("WorldGuardPlugin is null :O");
            setEnabled(false);
            return;
        }
        for (World world : this.server.getWorlds()) {
            if (world == null) {
                logError("World is null :O");
                setEnabled(false);
                return;
            }

            if (this.wg.getRegionManager(world) == null) {
                logError("RegionManager of " + world.getName() + " is null :O");
                setEnabled(false);
                return;
            }
        }
    } catch (ClassNotFoundException e1) {
        logError("Wasn't able get a connection to the WorldGuard API.");
        setEnabled(false);
        return;
    }
    if (this.signsFile.exists()) {
        loadSigns();
    }
    this.pm.registerEvents(this.eventListener, this);
}

From source file:com.haulmont.cuba.core.config.ConfigStorageCommon.java

/**
 * Method returns a result of config method invocation
 * @param classFQN fully qualified configuration interface name
 * @param methodName config getter method name
 * @param userLogin parameter is used for authentication if there is no security context bound to the current thread
 *                  and configuration method source is DATABASE
 * @param userPassword see userLogin parameter description
 * @return configuration method invocation result
 *//*from  ww w  .j a  v  a  2  s .  co m*/
public String getConfigValue(String classFQN, String methodName, String userLogin, String userPassword) {
    Class<?> aClass;
    try {
        aClass = Class.forName(classFQN);
    } catch (ClassNotFoundException e) {
        return String
                .format("Class %s not found.\nPlease ensure that you entered a fully qualified class name and "
                        + "that you class is in a proper application module (core, web or portal).", classFQN);
    }

    if (Config.class.isAssignableFrom(aClass)) {
        Config config = configuration.getConfig((Class<? extends Config>) aClass);
        Method method;
        boolean logoutRequired = false;
        try {
            method = aClass.getMethod(methodName);

            //if there is no security context bound to the current thread and the source of the config method is
            //DATABASE, then login attempt with 'userLogin' and 'userPassword' will be made
            if (AppContext.getSecurityContext() == null) {
                SourceType sourceType;
                Source methodSourceAnnotation = method.getAnnotation(Source.class);
                if (methodSourceAnnotation != null) {
                    sourceType = methodSourceAnnotation.type();
                } else {
                    Source classSourceAnnotation = aClass.getAnnotation(Source.class);
                    sourceType = classSourceAnnotation.type();
                }

                if (sourceType != null && sourceType == SourceType.DATABASE) {
                    if (Strings.isNullOrEmpty(userLogin)) {
                        return "No security context bound to the current thread. Please specify the user name.";
                    } else {
                        try {
                            Map<String, Locale> availableLocales = configuration.getConfig(GlobalConfig.class)
                                    .getAvailableLocales();
                            Locale defaultLocale = availableLocales.values().iterator().next();

                            TrustedClientCredentials credentials = new TrustedClientCredentials(userLogin,
                                    userPassword, defaultLocale);

                            UserSession session = authenticationService.login(credentials).getSession();
                            AppContext.setSecurityContext(new SecurityContext(session));
                            logoutRequired = true;
                        } catch (LoginException e) {
                            log.error(ExceptionUtils.getStackTrace(e));
                            return "Login error: " + e.getMessage();
                        }
                    }
                }
            }

            Object result = method.invoke(config);
            return result == null ? null : result.toString();
        } catch (NoSuchMethodException e) {
            return String.format("Method %s() not found in class %s", methodName, classFQN);
        } catch (InvocationTargetException | IllegalAccessException e) {
            return ExceptionUtils.getStackTrace(e);
        } finally {
            if (logoutRequired) {
                try {
                    authenticationService.logout();
                } finally {
                    AppContext.setSecurityContext(null);
                }
            }
        }
    } else {
        return String.format("Class %s is not an implementation of Config interface", classFQN);
    }
}

From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java

/**
 * Returns the access control list (ACL) for the given resource identifier if
 * it exists; otherwise, throw a ResourceNotFoundException.
 * //from   w w  w. j  a  v a2  s.c  o  m
 * @param resourceId      The resource identifier
 * @return  an XML string representing the access control list. The string includes
 *          an entry for the owner/submitter although that entry does not appear
 *          in the access_matrix table (the owner/submitter is stored only in the 
 *          resource_registry table).
 * @throws ClassNotFoundException
 * @throws SQLException
 * @throws UnauthorizedException
 * @throws ResourceNotFoundException
 * @throws Exception
 */
public String readResourceAcl(String resourceId) throws ClassNotFoundException, SQLException,
        UnauthorizedException, ResourceNotFoundException, Exception {

    String acl = null;

    try {
        DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword);

        boolean hasResource = dataPackageRegistry.hasResource(resourceId);
        if (!hasResource) {
            String gripe = "Resource not found: " + resourceId;
            throw new ResourceNotFoundException(gripe);
        }

        acl = dataPackageRegistry.getResourceAcl(resourceId);
        if (acl == null) {
            String gripe = "An access control list (ACL) does not exist for this resource: " + resourceId;
            throw new ResourceNotFoundException(gripe);
        }

    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
        throw (e);
    } catch (SQLException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }

    return acl;

}

From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java

/**
 * Returns the SHA-1 checksum for the given resource identifier if
 * it exists; otherwise, throw a ResourceNotFoundException.
 * /* w ww.  j a  va  2 s .  co m*/
 * @param resourceId   the resource identifier
 * @param authToken    the authorization token
 * @return the SHA-1 checksum string
 * @throws ClassNotFoundException
 * @throws SQLException
 * @throws UnauthorizedException
 * @throws ResourceNotFoundException
 * @throws Exception
 */
public String readResourceChecksum(String resourceId, AuthToken authToken) throws ClassNotFoundException,
        SQLException, UnauthorizedException, ResourceNotFoundException, Exception {

    String checksum = null;
    String user = authToken.getUserId();

    try {
        DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword);

        /*
         * Check whether user is authorized to read the data package report
         */
        Authorizer authorizer = new Authorizer(dataPackageRegistry);
        boolean isAuthorized = authorizer.isAuthorized(authToken, resourceId, Rule.Permission.read);
        if (!isAuthorized) {
            String gripe = "User " + user + " does not have permission to read the checksum for this resource: "
                    + resourceId;
            throw new UnauthorizedException(gripe);
        }

        checksum = dataPackageRegistry.getResourceShaChecksum(resourceId);

        if (checksum == null) {
            String gripe = "A checksum does not exist for this resource: " + resourceId;
            throw new ResourceNotFoundException(gripe);
        }

    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
        throw (e);
    } catch (SQLException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }

    return checksum;

}

From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java

/**
 * Returns the size value (in bytes) for the given resource identifier if
 * it exists; otherwise, throw a ResourceNotFoundException.
 * //from w  ww.  j a v a  2  s.  c o  m
 * @param resourceId   the resource identifier
 * @param authToken    the authorization token
 * @return the size value (in bytes)
 * @throws ClassNotFoundException
 * @throws SQLException
 * @throws UnauthorizedException
 * @throws ResourceNotFoundException
 * @throws Exception
 */
public Long readResourceSize(String resourceId, AuthToken authToken) throws ClassNotFoundException,
        SQLException, UnauthorizedException, ResourceNotFoundException, Exception {

    Long resourceSize = null;
    String user = authToken.getUserId();

    try {
        DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword);

        /*
         * Check whether user is authorized to read the data package report
         */
        Authorizer authorizer = new Authorizer(dataPackageRegistry);
        boolean isAuthorized = authorizer.isAuthorized(authToken, resourceId, Rule.Permission.read);
        if (!isAuthorized) {
            String gripe = "User " + user
                    + " does not have permission to read the size value for this resource: " + resourceId;
            throw new UnauthorizedException(gripe);
        }

        resourceSize = dataPackageRegistry.getResourceSize(resourceId);

        if (resourceSize == null) {
            String gripe = "A size value does not exist for this resource: " + resourceId;
            throw new ResourceNotFoundException(gripe);
        }

    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
        throw (e);
    } catch (SQLException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }

    return resourceSize;

}

From source file:edu.lternet.pasta.datapackagemanager.DataPackageManager.java

/**
 * Returns the Digital Object Identifier for the given resource identifier if
 * it exists; otherwise, throw a ResourceNotFoundException.
 * //  w  ww .ja va 2 s .  c  o  m
 * @param resourceId   the resource identifier
 * @param authToken    the authorization token
 * @return the Digital Object Identifier (DOI) value
 * @throws ClassNotFoundException
 * @throws SQLException
 * @throws UnauthorizedException
 * @throws ResourceNotFoundException
 * @throws Exception
 */
public String readResourceDoi(String resourceId, AuthToken authToken) throws ClassNotFoundException,
        SQLException, UnauthorizedException, ResourceNotFoundException, Exception {

    String doi = null;
    String user = authToken.getUserId();

    try {
        DataPackageRegistry dataPackageRegistry = new DataPackageRegistry(dbDriver, dbURL, dbUser, dbPassword);

        /*
         * Check whether user is authorized to read the data package report
         */
        Authorizer authorizer = new Authorizer(dataPackageRegistry);
        boolean isAuthorized = authorizer.isAuthorized(authToken, resourceId, Rule.Permission.read);
        if (!isAuthorized) {
            String gripe = "User " + user + " does not have permission to read the DOI for this resource: "
                    + resourceId;
            throw new UnauthorizedException(gripe);
        }

        doi = dataPackageRegistry.getDoi(resourceId);

        if (doi == null) {
            String gripe = "A DOI does not exist for this resource: " + resourceId;
            throw new ResourceNotFoundException(gripe);
        }

    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
        throw (e);
    } catch (SQLException e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }

    return doi;

}