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:de.micromata.genome.util.runtime.config.JdbcLocalSettingsConfigModel.java

private boolean checkDbUrl(ValContext ctx, String jdbcServiceId, String driver, String url, String user,
        String pass) {//from  ww w  .j ava  2 s  .  co  m
    JdbProviderService service = null;
    if (StringUtils.isNotBlank(jdbcServiceId) == true) {
        service = JdbProviderServices.findJdbcServiceById(jdbcServiceId);
    }
    if (service == null) {
        service = JdbProviderServices.findJdbcServiceByJdbDriver(driver);
    }
    if (service != null) {
        return service.tryConnect(this, ctx);
    }
    try {
        Class.forName(driver);
        try (Connection con = DriverManager.getConnection(url, user, pass)) {
            try (Statement stmt = con.createStatement()) {
                ctx.directInfo(null, "Created DB Connection....");
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
        ctx.directError(null, "Cannot find db driver: " + driver);
        return false;
    } catch (SQLException e) {
        ctx.directError(null, "Cannot create connection: " + e.getMessage());
        SQLException ne = e.getNextException();
        if (ne != null && ne != e) {
            ctx.directError(null, ne.getMessage(), ne);
        } else {
            ctx.directError(null, e.getMessage(), e);
        }
        return false;
    }
}

From source file:org.apache.tajo.util.metrics.TajoSystemMetrics.java

private void setMetricsReporter(String groupName) {
    // reporter name -> class name
    Map<String, String> reporters = new HashMap<>();

    List<String> reporterNames = metricsProps.getList(groupName + ".reporters");
    if (reporterNames.isEmpty()) {
        LOG.warn("No property " + groupName + ".reporters in " + metricsPropertyFileName);
        return;/*ww  w.  ja  v a2s.  co  m*/
    }

    Map<String, String> allReporterProperties = new HashMap<>();

    Iterator<String> keys = metricsProps.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = metricsProps.getString(key);
        if (key.indexOf("reporter.") == 0) {
            String[] tokens = key.split("\\.");
            if (tokens.length == 2) {
                reporters.put(tokens[1], value);
            }
        } else if (key.indexOf(groupName + ".") == 0) {
            String[] tokens = key.split("\\.");
            if (tokens.length > 2) {
                allReporterProperties.put(key, value);
            }
        }
    }

    synchronized (metricsReporters) {
        for (String eachReporterName : reporterNames) {
            if ("null".equals(eachReporterName)) {
                continue;
            }
            String reporterClass = reporters.get(eachReporterName);
            if (reporterClass == null) {
                LOG.warn("No metrics reporter definition[" + eachReporterName + "] in "
                        + metricsPropertyFileName);
                continue;
            }

            Map<String, String> eachMetricsReporterProperties = findMetircsProperties(allReporterProperties,
                    groupName + "." + eachReporterName);

            try {
                Object reporterObject = Class.forName(reporterClass).newInstance();
                if (!(reporterObject instanceof TajoMetricsScheduledReporter)) {
                    LOG.warn(reporterClass + " is not subclass of "
                            + TajoMetricsScheduledReporter.class.getCanonicalName());
                    continue;
                }
                TajoMetricsScheduledReporter reporter = (TajoMetricsScheduledReporter) reporterObject;
                reporter.init(metricRegistry, groupName, hostAndPort, eachMetricsReporterProperties);
                reporter.start();

                metricsReporters.add(reporter);
                LOG.info("Started metrics reporter " + reporter.getClass().getCanonicalName() + " for "
                        + groupName);
            } catch (ClassNotFoundException e) {
                LOG.warn("No metrics reporter class[" + eachReporterName + "], required class= "
                        + reporterClass);
                continue;
            } catch (Exception e) {
                LOG.warn("Can't initiate metrics reporter class[" + eachReporterName + "]" + e.getMessage(), e);
                continue;
            }
        }
    }
}

From source file:org.apache.avalon.fortress.tools.FortressBean.java

/**
 * Use reflection to set up commons logging. If commons logging is available, it will be set up;
 * if it is not available, this section is ignored. This needs version 1.0.4 (or later) of commons
 * logging, earlier versions do not have avalon support.
 *//*from w ww  . j  a v  a2 s .  c  o  m*/
private void initializeCommonsLogging(ClassLoader cl) {
    try {
        //if commons logging is available, set the static logger for commons logging
        Class commonsLoggerClass;
        if (cl != null) {
            commonsLoggerClass = cl.loadClass(COMMONS_AVALON_LOGGER);
        } else {
            commonsLoggerClass = Class.forName(COMMONS_AVALON_LOGGER);
        }
        Method setDefaultLoggerMethod = commonsLoggerClass.getMethod("setDefaultLogger",
                new Class[] { Logger.class });
        setDefaultLoggerMethod.invoke(null, new Object[] { cm.getLogger() });
        //set the system property to use avalon logger
        System.setProperty(COMMONS_LOG_PROPERTY, COMMONS_AVALON_LOGGER);
        if (getLogger().isInfoEnabled())
            getLogger().info("AvalonLogger found, commons logging redirected to Avalon logs");
    } catch (ClassNotFoundException e) {
        if (getLogger().isInfoEnabled())
            getLogger().info("AvalonLogger not found, commons logging not redirected");
    } catch (Exception e) {
        if (getLogger().isDebugEnabled())
            getLogger().debug("error while initializing commons logging: " + e.getClass().getName() + ", "
                    + e.getMessage());
    }
}

From source file:com.aurel.track.plugin.PluginManager.java

public Object getPluginClass(String pluginType, String pluginID) {
    PluginDescriptor pluginDescriptor = getPluginDescriptor(pluginType, pluginID);
    if (pluginDescriptor != null) {
        String pluginClassName = pluginDescriptor.getTheClassName();

        Class pluginClass = null;
        if (pluginClassName == null) {
            LOGGER.warn("No class specified for pluginType " + pluginType + " and plugin " + pluginID);
            return null;
        }/*from w  w w  .j  a  va2 s. c o m*/
        try {
            pluginClass = Class.forName(pluginClassName);
        } catch (ClassNotFoundException e) {
            LOGGER.error("The plugin class " + pluginClassName + "  not found found in the classpath "
                    + e.getMessage());
        }
        if (pluginClass != null) {
            try {
                return pluginClass.newInstance();
            } catch (Exception e) {
                LOGGER.error("Instantiating the plugin class class " + pluginClassName + "  failed with "
                        + e.getMessage());
            }
        }
    }
    return null;
}

From source file:org.apache.camel.maven.DocumentGeneratorMojo.java

private VelocityContext getDocumentContext() throws MavenReportException {
    final VelocityContext context = new VelocityContext();
    context.put("helper", this);

    // project GAV
    context.put("groupId", project.getGroupId());
    context.put("artifactId", project.getArtifactId());
    context.put("version", project.getVersion());

    // component URI format
    // look for single API, no endpoint-prefix
    @SuppressWarnings("unchecked")
    final Set<String> apiNames = new TreeSet<String>(collection.getApiNames());
    context.put("apiNames", apiNames);
    String suffix;/* ww w  . j a v a 2 s  .c  om*/
    if (apiNames.size() == 1 && ((Set) apiNames).contains("")) {
        suffix = "://endpoint?[options]";
    } else {
        suffix = "://endpoint-prefix/endpoint?[options]";
    }
    context.put("uriFormat", scheme + suffix);

    // API helpers
    final Map<String, ApiMethodHelper> apiHelpers = new TreeMap<String, ApiMethodHelper>();
    for (Object element : collection.getApiHelpers().entrySet()) {
        Map.Entry entry = (Map.Entry) element;
        apiHelpers.put(((ApiName) entry.getKey()).getName(), (ApiMethodHelper) entry.getValue());
    }
    context.put("apiHelpers", apiHelpers);

    // API methods and endpoint configurations
    final Map<String, Class<? extends ApiMethod>> apiMethods = new TreeMap<String, Class<? extends ApiMethod>>();
    final Map<String, Class<?>> apiConfigs = new TreeMap<String, Class<?>>();
    for (Object element : collection.getApiMethods().entrySet()) {
        Map.Entry entry = (Map.Entry) element;
        final String name = ((ApiName) entry.getValue()).getName();

        @SuppressWarnings("unchecked")
        Class<? extends ApiMethod> apiMethod = (Class<? extends ApiMethod>) entry.getKey();
        apiMethods.put(name, apiMethod);

        Class<?> configClass;
        try {
            configClass = getProjectClassLoader().loadClass(getEndpointConfigName(apiMethod));
        } catch (ClassNotFoundException e) {
            throw new MavenReportException(e.getMessage(), e);
        } catch (MojoExecutionException e) {
            throw new MavenReportException(e.getMessage(), e);
        }
        apiConfigs.put(name, configClass);
    }
    context.put("apiMethods", apiMethods);
    context.put("apiConfigs", apiConfigs);

    // API component properties
    context.put("scheme", this.scheme);
    context.put("componentName", this.componentName);
    Class<?> configClass;
    try {
        configClass = getProjectClassLoader().loadClass(getComponentConfig());
    } catch (ClassNotFoundException e) {
        throw new MavenReportException(e.getMessage(), e);
    } catch (MojoExecutionException e) {
        throw new MavenReportException(e.getMessage(), e);
    }
    context.put("componentConfig", configClass);
    // get declared and derived fields for component config
    // use get/set methods instead of fields, since this class could inherit others, that have private fields
    // so getDeclaredFields() won't work, like it does for generated endpoint config classes!!!
    final Map<String, String> configFields = new TreeMap<String, String>();
    do {
        IntrospectionSupport.ClassInfo classInfo = IntrospectionSupport.cacheClass(configClass);
        for (IntrospectionSupport.MethodInfo method : classInfo.methods) {
            if (method.isSetter) {
                configFields.put(method.getterOrSetterShorthandName,
                        getCanonicalName(method.method.getParameterTypes()[0]));
            }
        }
        configClass = configClass.getSuperclass();
    } while (configClass != null && !configClass.equals(Object.class));
    context.put("componentConfigFields", configFields);

    return context;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.excelimport.EntityDataImporter.java

/**
 * @param typeName/*from  w ww.  ja  v  a 2  s  .  c  o m*/
 * @param cellValue
 * @return the enum value for the given typeName and the enum value given as String in the cell value;
 *         or null if the value is not found.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object resolveJavaEnum(String typeName, Object cellValue) {
    Object result = null;
    try {
        Class<?> clazz = Class.forName(typeName);

        if (clazz.isEnum()) {
            return Enum.valueOf(((Class<Enum>) clazz), cellValue.toString());
        } else {
            logError("Type {0} is not an enum. Can not find value for {1}", typeName, cellValue.toString());
        }
    } catch (ClassNotFoundException e) {
        logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(),
                e.getMessage());
    } catch (SecurityException e) {
        logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(),
                e.getMessage());
    } catch (IllegalArgumentException e) {
        logError("Error setting {0} to {1}: {2} {3}", typeName, cellValue.toString(), e.getClass().getName(),
                e.getMessage());
    }
    return result;
}

From source file:com.nextep.datadesigner.vcs.services.VCSFiles.java

/**
 * Write the specified file to the given repository file with Oracle-specific Blob support.
 * //from  ww w. jav a  2  s.c  o  m
 * @param conn Oracle connection
 * @param file repository file which must have been created
 * @param localFile local file to dump into the repository file
 * @throws SQLException when any database connection problems occurs
 */
private void writeOracleBlob(Connection conn, IRepositoryFile file, File localFile) throws SQLException {
    PreparedStatement stmt = null;
    long size = 0;

    try {
        /*
         * Columns names in the SET clause cannot be qualified with an alias name because it
         * would fail in Postgres.
         */
        stmt = conn.prepareStatement("UPDATE rep_files rf " //$NON-NLS-1$
                + "  SET file_content = ? " //$NON-NLS-1$
                + "    , filesize = ? " //$NON-NLS-1$
                + "WHERE rf.file_id = ? "); //$NON-NLS-1$

        OutputStream os = null;
        FileInputStream is = null;
        BLOB tempBlob = null;

        try {
            // Get the oracle connection class for checking
            Class<?> oracleConnectionClass = Class.forName("oracle.jdbc.OracleConnection"); //$NON-NLS-1$

            // Make sure connection object is right type
            if (!oracleConnectionClass.isAssignableFrom(conn.getClass())) {
                throw new HibernateException(VCSMessages.getString("files.invalidOracleConnection") //$NON-NLS-1$
                        + VCSMessages.getString("files.invalidOracleConnection.2") //$NON-NLS-1$
                        + conn.getClass().getName());
            }

            // Create our temp BLOB
            tempBlob = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION);
            tempBlob.open(BLOB.MODE_READWRITE);
            os = tempBlob.getBinaryOutputStream();
            is = new FileInputStream(localFile);

            // Large 10K buffer for efficient read
            byte[] buffer = new byte[10240];
            int bytesRead = 0;

            while ((bytesRead = is.read(buffer)) >= 0) {
                os.write(buffer, 0, bytesRead);
                size += bytesRead;
            }
        } catch (ClassNotFoundException cnfe) {
            // could not find the class with reflection
            throw new ErrorException(VCSMessages.getString("files.classUnresolved") //$NON-NLS-1$
                    + cnfe.getMessage());
        } catch (FileNotFoundException fnfe) {
            throw new ErrorException(VCSMessages.getString("files.fileUnresolved")); //$NON-NLS-1$
        } catch (IOException ioe) {
            throw new ErrorException(VCSMessages.getString("files.readProblem"), ioe); //$NON-NLS-1$
        } finally {
            safeClose(os);
            safeClose(is);
            if (tempBlob != null) {
                tempBlob.close();
            }
        }
        stmt.setBlob(1, tempBlob);
        stmt.setLong(2, size);
        stmt.setLong(3, file.getUID().rawId());
        stmt.execute();
    } finally {
        if (stmt != null) {
            stmt.close();
        }
        file.setFileSizeKB(size / 1024);
    }
}

From source file:net.sourceforge.dita4publishers.tools.mapreporter.MapBosReporter.java

@SuppressWarnings("unchecked")
protected DitaBosReporter getBosReporter(PrintStream outStream) throws Exception {
    String reporterClass = TextDitaBosReporter.class.getCanonicalName();
    if (commandLine.hasOption(BOS_REPORTER_CLASS_OPTION_ONE_CHAR))
        reporterClass = commandLine.getOptionValue(BOS_REPORTER_CLASS_OPTION_ONE_CHAR);
    Class<? extends DitaBosReporter> clazz;
    try {/*from  www .j  a  v a2 s.  com*/
        clazz = (Class<? extends DitaBosReporter>) Class.forName(reporterClass);
    } catch (ClassNotFoundException e) {
        System.err.println(
                "BOS reporter class \"" + reporterClass + "\" not found. Check class name and class path.");
        throw e;
    }
    DitaBosReporter reporter;
    try {
        reporter = clazz.newInstance();
    } catch (Exception e) {
        System.err.println(
                "Failed to create instance of BOS reporter class \"" + reporterClass + "\": " + e.getMessage());
        throw e;
    }
    reporter.setPrintStream(outStream);
    return reporter;
}

From source file:org.apache.torque.generator.configuration.outlet.JavaOutletSaxHandler.java

/**
 * Instantiates a java outlet./*from   ww  w.  j  a v  a 2 s.  c  o m*/
 *
 * @param outletName the name for the outlet which configuration
 *        will be read in by the generated SaxHandlerFactory,
 *        or null if the name of the outlet should be determined from
 *        the parsed xml.
 * @param uri - The Namespace URI, or the empty string if the
 *        element has no Namespace URI or if Namespace processing is not
 *        being performed.
 * @param localName - The local name (without prefix), or
 *        the empty string if Namespace processing is not being performed.
 * @param rawName - The qualified name (with prefix), or the empty string if
 *        qualified names are not available.
 * @param attributes - The attributes attached to the element.
 *          If there are no attributes, it shall be an empty Attributes
 *          object.
 *
 * @return the created outlet, not null.
 *
 * @throws SAXException if an error occurs during creation.
 */
protected Outlet createOutlet(QualifiedName outletName, String uri, String localName, String rawName,
        Attributes attributes) throws SAXException {
    if (outletName == null) {
        String nameAttribute = attributes.getValue(OUTLET_NAME_ATTRIBUTE);
        if (nameAttribute == null) {
            throw new SAXException("The attribute " + OUTLET_NAME_ATTRIBUTE + " must be set on the element "
                    + rawName + " for Java Outlets");
        }
        outletName = new QualifiedName(nameAttribute);
    }

    String className;
    {
        className = attributes.getValue(OUTLET_CLASS_ATTRIBUTE);
        if (className == null) {
            throw new SAXException("The attribute " + OUTLET_CLASS_ATTRIBUTE + " must be set on the element "
                    + rawName + " for java Outlets");
        }
    }

    Class<?> outletClass;
    try {
        outletClass = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new SAXException("Error  while initializing the java outlet " + outletName
                + " : Could not load class " + className, e);
    } catch (ExceptionInInitializerError e) {
        log.error("Error  while initializing the java outlet " + outletName + " : Could not initialize class "
                + className + " : " + e.getMessage());
        throw e;
    } catch (LinkageError e) {
        log.error("Error  while initializing the java outlet " + outletName + " : Could not link class "
                + className + " : " + e.getMessage());
        throw e;
    }

    Outlet result;
    try {
        Constructor<?> constructor = outletClass.getConstructor(QualifiedName.class);
        result = (Outlet) constructor.newInstance(outletName);
    } catch (NoSuchMethodException e) {
        throw new SAXException("Error  while instantiating the java outlet " + outletName + " : The class "
                + className + " has no constructor which takes a qualified name", e);
    } catch (ClassCastException e) {
        throw new SAXException("Error  while instantiating the java outlet " + outletName + " : The class "
                + className + " is not an instance of " + Outlet.class.getName(), e);
    } catch (IllegalAccessException e) {
        throw new SAXException("Error  while instantiating the java outlet " + outletName
                + " : The constructor of class " + className + " could not be accessed", e);
    } catch (InvocationTargetException e) {
        throw new SAXException("Error  while instantiating the java outlet " + outletName
                + " : The constructor of class " + className + " could not be called", e);
    } catch (InstantiationException e) {
        throw new SAXException(
                "Error  while instantiating the java outlet " + outletName + " : The class " + className
                        + " represents an abstract class, " + "an interface, an array class, a primitive type, "
                        + "or void, or the class has no parameterless constructor, "
                        + "or the instantiation fails for some other reason.",
                e);
    } catch (SecurityException e) {
        throw new SAXException("Error  while instantiating the java outlet " + outletName
                + " : The security manager denies instantiation", e);
    }

    return result;
}

From source file:net.sourceforge.dita4publishers.tools.mapreporter.MapBosReporter.java

@SuppressWarnings("unchecked")
protected KeySpaceReporter getKeyspaceReporter(PrintStream outStream) throws Exception {
    String reporterClass = TextKeySpaceReporter.class.getCanonicalName();
    if (commandLine.hasOption(KEYSPACE_REPORTER_CLASS_OPTION_ONE_CHAR))
        reporterClass = commandLine.getOptionValue(KEYSPACE_REPORTER_CLASS_OPTION_ONE_CHAR);
    Class<? extends KeySpaceReporter> clazz;
    try {//from  w  w w. j ava2  s .c  om
        clazz = (Class<? extends KeySpaceReporter>) Class.forName(reporterClass);
    } catch (ClassNotFoundException e) {
        System.err.println("Key space reporter class \"" + reporterClass
                + "\" not found. Check class name and class path.");
        throw e;
    }
    KeySpaceReporter reporter;
    try {
        reporter = clazz.newInstance();
    } catch (Exception e) {
        System.err.println("Failed to create instance of key space reporter class \"" + reporterClass + "\": "
                + e.getMessage());
        throw e;
    }
    reporter.setPrintStream(outStream);
    return reporter;
}