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:io.swagger.inflector.config.Configuration.java

public Configuration exceptionMapper(String className) {
    Class<?> cls;//from   ww  w  . j a  v  a  2s .c  om
    try {
        ClassLoader classLoader = Configuration.class.getClassLoader();
        cls = classLoader.loadClass(className);
        exceptionMappers.add(cls);
    } catch (ClassNotFoundException e) {
        LOGGER.error("unable to add exception mapper for `" + className + "`, " + e.getMessage());
    }
    return this;
}

From source file:de.micromata.genome.gwiki.jetty.GWikiStarterConfig.java

private boolean checkDbUrl(ValidationContext ctx, String driver, String url, String user, String pass) {
    try {/*from ww w . j a v  a  2 s  . c  o  m*/
        Class.forName(driver);
        try (Connection con = DriverManager.getConnection(url, user, pass)) {
            try (Statement stmt = con.createStatement()) {
                ctx.info("Created DB Connection....");
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
        ctx.error("Cannot find db driver: " + driver);
        LOG.error(e);
        return false;
    } catch (SQLException e) {
        ctx.error("Cannot create connection: " + e.getMessage());
        SQLException ne = e.getNextException();
        if (ne != null && ne != e) {
            ctx.error(ne.getMessage());

        }
        LOG.error(e);
        return false;
    }
}

From source file:org.displaytag.export.ExportViewFactory.java

/**
 * Register a new Export View, associated with a Media Type. If another export view is currently associated with the
 * given media type it's replaced./*from  w  w  w .  j  a  va2 s .co  m*/
 * @param name media name
 * @param viewClassName export view class name
 */
public void registerExportView(String name, String viewClassName) {
    Class exportClass;
    try {
        exportClass = ReflectHelper.classForName(viewClassName);
    } catch (ClassNotFoundException e) {
        log.error(Messages.getString("ExportViewFactory.classnotfound", //$NON-NLS-1$
                new Object[] { name, viewClassName }));
        return;
    } catch (NoClassDefFoundError e) {
        log.warn(Messages.getString("ExportViewFactory.noclassdef" //$NON-NLS-1$
                , new Object[] { name, viewClassName, e.getMessage() }));
        return;
    }

    try {
        exportClass.newInstance();
    } catch (InstantiationException e) {
        log.error(Messages.getString("ExportViewFactory.instantiationexception", //$NON-NLS-1$
                new Object[] { name, viewClassName, e.getMessage() }));
        return;
    } catch (IllegalAccessException e) {
        log.error(Messages.getString("ExportViewFactory.illegalaccess", //$NON-NLS-1$
                new Object[] { name, viewClassName, e.getMessage() }));
        return;
    } catch (NoClassDefFoundError e) {
        log.warn(Messages.getString("ExportViewFactory.noclassdef" //$NON-NLS-1$
                , new Object[] { name, viewClassName, e.getMessage() }));
        return;
    }

    MediaTypeEnum media = MediaTypeEnum.registerMediaType(name);
    viewClasses.put(media, exportClass);

    if (log.isDebugEnabled()) {
        log.debug(Messages.getString("ExportViewFactory.added", //$NON-NLS-1$ 
                new Object[] { media, viewClassName }));
    }
}

From source file:edu.vt.middleware.gator.server.LoggingEventHandler.java

/** {@inheritDoc}. */
public void run() {
    isRunning = true;//  www. j av  a  2  s  .co  m
    logger.info("Ready to handle remote logging events from socket.");

    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
        while (isRunning) {
            final Object event;
            try {
                event = ois.readObject();
            } catch (ClassNotFoundException e) {
                logger.warn(String.format("Unknown logging event of type %s. "
                        + "Install integration module for corresponding logging engine "
                        + "to resolve this problem.", e.getMessage()));
                break;
            }
            loggingEventCount++;
            if (loggingEngine.supports(event)) {
                if (eventLogger.isTraceEnabled()) {
                    eventLogger.info("Read logging event from socket: " + loggingEngine.toString(event));
                }
                loggingEngine.handleEvent(getRemoteAddress(), event);
            } else {
                logger.warn(loggingEngine + " does not support " + event);
            }

            // Attempt to call registered listeners
            for (LoggingEventListener listener : getLoggingEventListeners()) {
                executor.execute(new LoggingEventReceivedEvent(listener, event));
            }
        }
    } catch (EOFException e) {
        logger.info("End of stream detected. Quitting.");
    } catch (SocketException e) {
        logger.info("Underlying socket is closed. Quitting.");
    } catch (Exception e) {
        logger.error("Unexpected exception. Quitting.", e);
    } finally {
        closeStreamIfNecessary(ois);
        closeSocketIfNecessary();
        loggingEngine.shutdown();
        loggingEngine = null;
        isRunning = false;
    }
}

From source file:org.apache.hadoop.hbase.util.TestDynamicClassLoader.java

@Test
public void testLoadClassFromLocalPath() throws Exception {
    ClassLoader parent = TestDynamicClassLoader.class.getClassLoader();
    DynamicClassLoader classLoader = new DynamicClassLoader(conf, parent);

    String className = "TestLoadClassFromLocalPath";
    deleteClass(className);//from  w ww  .  j a  va  2s  . c om
    try {
        classLoader.loadClass(className);
        fail("Should not be able to load class " + className);
    } catch (ClassNotFoundException cnfe) {
        // expected, move on
    }

    try {
        String folder = TEST_UTIL.getDataTestDir().toString();
        ClassLoaderTestHelper.buildJar(folder, className, null, ClassLoaderTestHelper.localDirPath(conf));
        classLoader.loadClass(className);
    } catch (ClassNotFoundException cnfe) {
        LOG.error("Should be able to load class " + className, cnfe);
        fail(cnfe.getMessage());
    }
}

From source file:com.concursive.connect.indexer.LuceneIndexer.java

private Object getObjectIndexer(String className) {
    Object classRef = null;/*from   ww  w.  j  a v  a 2s. c  o  m*/
    if (classes.containsKey(className)) {
        classRef = classes.get(className);
    } else {
        try {
            classRef = Class.forName(className).newInstance();
            classes.put(className, classRef);
        } catch (ClassNotFoundException cnfe) {
            LOG.warn("Class Not Found Exception. MESSAGE = " + cnfe.getMessage(), cnfe);
        } catch (InstantiationException ie) {
            LOG.error("Instantiation Exception. MESSAGE = " + ie.getMessage(), ie);
        } catch (IllegalAccessException iae) {
            LOG.error("Illegal Argument Exception. MESSAGE = " + iae.getMessage(), iae);
        }
    }
    return classRef;
}

From source file:com.insprise.common.db.DefaultConnectionPool.java

/**
* Gets a connection./*  w  w  w  .  j  a  va  2 s . c om*/
* A shortcut for: getDataSource().getConnection(). After using the connection, always remember to close it.
* <p>
* <code><pre>
* Connection conn = null;
* try {
*   conn = pool.getConnection();
*   ...
* }catch(Exception e) {
*   ...
* }finally{
*   &lt;b&gt;conn.close();&lt;/b&gt; // return the connection to the pool.
* }
* </pre></code>
* @param readOnly Whether the connection should be read only or not.
* @return getDataSource().getConnection().
* @throws SQLException
*/
public Connection getConnection(boolean readOnly) throws SQLException {
    if (sourceType == SourceType.DRIVER_MANAGER) {
        if (!initialized) {
            synchronized (this) {
                if (!initialized) {
                    try {
                        setupPool();
                    } catch (ClassNotFoundException e) {
                        throw new SQLException(e.getMessage(), e);
                    }
                }
                initialized = true;
            }
        }
    }

    Connection conn = dataSource.getConnection();
    conn.setReadOnly(readOnly);
    if (readOnly) {
        conn.setAutoCommit(true); // auto commit read only.
    }

    return conn;
}

From source file:com.ottogroup.bi.spqr.operator.esper.EsperOperator.java

/**
 * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties)
 *///from   www . j av  a2 s  .c o m
public void initialize(Properties properties)
        throws RequiredInputMissingException, ComponentInitializationFailedException {

    if (properties == null)
        throw new RequiredInputMissingException("Missing required properties");

    /////////////////////////////////////////////////////////////////////////////////
    // fetch an validate properties
    Set<String> esperQueryStrings = new HashSet<>();
    for (int i = 1; i < Integer.MAX_VALUE; i++) {
        String tmpStr = properties.getProperty(CFG_ESPER_STATEMENT_PREFIX + i);
        if (StringUtils.isBlank(tmpStr))
            break;
        esperQueryStrings.add(StringUtils.trim(tmpStr));
    }
    if (esperQueryStrings.isEmpty())
        throw new RequiredInputMissingException("Missing required ESPER statement(s)");
    /////////////////////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////////////
    // fetch event configuration
    Map<String, Map<String, String>> eventConfiguration = new HashMap<>();
    for (int i = 1; i < Integer.MAX_VALUE; i++) {
        final String typeDefEvent = StringUtils
                .trim(properties.getProperty(CFG_ESPER_TYPE_DEF_PREFIX + i + CFG_ESPER_TYPE_DEF_EVENT_SUFFIX));
        if (StringUtils.isBlank(typeDefEvent))
            break;
        final String typeDefName = StringUtils
                .trim(properties.getProperty(CFG_ESPER_TYPE_DEF_PREFIX + i + CFG_ESPER_TYPE_DEF_NAME_SUFFIX));
        final String typeDefType = StringUtils
                .trim(properties.getProperty(CFG_ESPER_TYPE_DEF_PREFIX + i + CFG_ESPER_TYPE_DEF_TYPE_SUFFIX));

        if (StringUtils.isBlank(typeDefName) || StringUtils.isBlank(typeDefType))
            throw new RequiredInputMissingException(
                    "Missing type def name or type for event '" + typeDefEvent + "' at position " + i);

        Map<String, String> ec = eventConfiguration.get(typeDefEvent);
        if (ec == null)
            ec = new HashMap<>();
        ec.put(typeDefName, typeDefType);
        eventConfiguration.put(typeDefEvent, ec);

    }
    ///////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////
    // create esper configuration

    Configuration esperConfiguration = new Configuration();
    for (final String event : eventConfiguration.keySet()) {
        Map<String, String> ec = eventConfiguration.get(event);
        if (ec != null && !ec.isEmpty()) {
            Map<String, Object> typeDefinition = new HashMap<>();
            for (final String typeDefName : ec.keySet()) {
                final String typeDefType = ec.get(typeDefName);
                try {
                    typeDefinition.put(typeDefName, Class.forName(typeDefType));
                } catch (ClassNotFoundException e) {
                    throw new ComponentInitializationFailedException("Failed to lookup provided type '"
                            + typeDefType + "' for event '" + event + "'. Error: " + e.getMessage());
                }
            }
            esperConfiguration.addEventType(event, typeDefinition);
        }
    }

    Map<String, Object> spqrDefaultTypeDefinition = new HashMap<>();
    spqrDefaultTypeDefinition.put(SPQR_EVENT_TIMESTAMP_FIELD, Long.class);
    spqrDefaultTypeDefinition.put(SPQR_EVENT_BODY_FIELD, Map.class);
    esperConfiguration.addEventType(DEFAULT_INPUT_EVENT, spqrDefaultTypeDefinition);
    esperConfiguration.addEventType(DEFAULT_OUTPUT_EVENT, spqrDefaultTypeDefinition);
    ///////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////
    // initialize service provider, submit statements and retrieve runtime 
    this.esperServiceProvider = EPServiceProviderManager.getDefaultProvider(esperConfiguration);
    this.esperServiceProvider.initialize();

    for (final String qs : esperQueryStrings) {
        try {
            EPStatement esperStatement = this.esperServiceProvider.getEPAdministrator().createEPL(qs);
            esperStatement.setSubscriber(this);
        } catch (EPStatementException e) {
            throw new ComponentInitializationFailedException(
                    "Failed to parse query into ESPER statement. Error: " + e.getMessage(), e);
        }
    }

    this.esperRuntime = this.esperServiceProvider.getEPRuntime();
    ///////////////////////////////////////////////////////////////////////////////////
}

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

private VelocityContext getEndpointContext(List<ApiMethodParser.ApiMethodModel> models)
        throws MojoExecutionException {
    VelocityContext context = getCommonContext(models);
    context.put("configName", getConfigName());
    context.put("componentName", componentName);
    context.put("componentPackage", componentPackage);

    // generate parameter names and types for configuration, sorted by parameter name
    Map<String, ApiMethodParser.Argument> parameters = new TreeMap<String, ApiMethodParser.Argument>();
    for (ApiMethodParser.ApiMethodModel model : models) {
        for (ApiMethodParser.Argument argument : model.getArguments()) {

            final String name = argument.getName();
            final Class<?> type = argument.getType();
            final String typeName = type.getCanonicalName();
            if (!parameters.containsKey(name)
                    && (propertyNamePattern == null || !propertyNamePattern.matcher(name).matches())
                    && (propertyTypePattern == null || !propertyTypePattern.matcher(typeName).matches())) {
                parameters.put(name, argument);
            }//from   ww  w. j  a va 2 s.  c om
        }
    }

    // add custom parameters
    if (extraOptions != null && extraOptions.length > 0) {
        for (ExtraOption option : extraOptions) {
            final String name = option.getName();
            final String argWithTypes = option.getType().replaceAll(" ", "");
            final int rawEnd = argWithTypes.indexOf('<');
            String typeArgs = null;
            Class<?> argType;
            try {
                if (rawEnd != -1) {
                    argType = getProjectClassLoader().loadClass(argWithTypes.substring(0, rawEnd));
                    typeArgs = argWithTypes.substring(rawEnd + 1, argWithTypes.lastIndexOf('>'));
                } else {
                    argType = getProjectClassLoader().loadClass(argWithTypes);
                }
            } catch (ClassNotFoundException e) {
                throw new MojoExecutionException(String.format("Error loading extra option [%s %s] : %s",
                        argWithTypes, name, e.getMessage()), e);
            }
            parameters.put(name, new ApiMethodParser.Argument(name, argType, typeArgs));
        }
    }

    context.put("parameters", parameters);
    return context;
}

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

private void loadApiCollection() throws MavenReportException {
    try {//  www.j  a  v  a 2s.c  om
        final Class<?> collectionClass = getProjectClassLoader()
                .loadClass(outPackage + "." + componentName + "ApiCollection");
        final Method getCollection = collectionClass.getMethod("getCollection");
        this.collection = (ApiCollection) getCollection.invoke(null);
    } catch (ClassNotFoundException e) {
        throw new MavenReportException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        throw new MavenReportException(e.getMessage(), e);
    } catch (InvocationTargetException e) {
        throw new MavenReportException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new MavenReportException(e.getMessage(), e);
    } catch (MojoExecutionException e) {
        throw new MavenReportException(e.getMessage(), e);
    }
}