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.cyberway.issue.crawler.frontier.BdbFrontier.java

protected UriUniqFilter deserializeAlreadySeen(final Class<? extends UriUniqFilter> cls, final File dir)
        throws FileNotFoundException, IOException {
    UriUniqFilter uuf = null;//w w  w.  j  a v a 2s.com
    try {
        logger.fine("Started deserializing " + cls.getName() + " of checkpoint recover.");
        uuf = CheckpointUtils.readObjectFromFile(cls, dir);
        logger.fine("Finished deserializing bdbje as part " + "of checkpoint recover.");
    } catch (ClassNotFoundException e) {
        throw new IOException("Failed to deserialize " + cls.getName() + ": " + e.getMessage());
    }
    return uuf;
}

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

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

    String className = "TestLoadClassFromAnotherPath";
    deleteClass(className);//  w  ww. ja  v a2s . co  m
    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);
        classLoader.loadClass(className);
    } catch (ClassNotFoundException cnfe) {
        LOG.error("Should be able to load class " + className, cnfe);
        fail(cnfe.getMessage());
    }
}

From source file:org.pentaho.pat.server.services.impl.SessionServiceImpl.java

public String createConnection(final String userId, final String sessionId, final String driverName,
        final String connectStr, final String username, final String password) throws OlapException {
    this.validateSession(userId, sessionId);

    OlapConnection connection;// w w  w .  j  a  va  2  s. c  o  m
    final String connectionId = UUID.randomUUID().toString();

    try {
        Class.forName(driverName);

        if (username == null && password == null) {
            connection = (OlapConnection) DriverManager.getConnection(connectStr);
        } else {
            connection = (OlapConnection) DriverManager.getConnection(connectStr, username, password);
        }

        final OlapWrapper wrapper = connection;

        final OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class);

        if (olapConnection == null) {
            throw new OlapException(Messages.getString("Services.Session.NullConnection")); //$NON-NLS-1$
        } else {

            sessions.get(userId).get(sessionId).putConnection(connectionId, olapConnection);

            // Obtaining a connection object doesn't mean that the
            // credentials are ok or whatever. We'll test it.
            this.discoveryService.getCubes(userId, sessionId, connectionId);

            return connectionId;

        }

    } catch (ClassNotFoundException e) {
        LOG.error(e);
        throw new OlapException(e.getMessage(), e);
    } catch (SQLException e) {
        LOG.error(e);
        throw new OlapException(e.getMessage(), e);
    } catch (RuntimeException e) {
        // The XMLA driver wraps some exceptions in Runtime stuff.
        // That's on the FIX ME list but not fixed yet... c(T-T)b
        if (e.getCause() instanceof OlapException) {
            throw (OlapException) e.getCause();
        } else {
            throw e;
        }
    }
}

From source file:org.vietspider.net.client.impl.AnonymousHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager connManager = null;
    HttpParams params = getParams();//from  w  w w. j a v  a 2 s. co  m

    ClientConnectionManagerFactory factory = null;

    // Try first getting the factory directly as an object.
    factory = (ClientConnectionManagerFactory) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY);
    if (factory == null) { // then try getting its class name.
        String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
        if (className != null) {
            try {
                Class<?> clazz = Class.forName(className);
                factory = (ClientConnectionManagerFactory) clazz.newInstance();
            } catch (ClassNotFoundException ex) {
                throw new IllegalStateException("Invalid class name: " + className);
            } catch (IllegalAccessException ex) {
                throw new IllegalAccessError(ex.getMessage());
            } catch (InstantiationException ex) {
                throw new InstantiationError(ex.getMessage());
            }
        }
    }

    if (factory != null) {
        connManager = factory.newInstance(params, registry);
    } else {
        connManager = new SingleClientConnManager(getParams(), registry);
    }

    return connManager;
}

From source file:org.apache.cayenne.map.ObjAttribute.java

/**
 * Returns Java class of an object property described by this attribute.
 * Wraps any thrown exceptions into CayenneRuntimeException.
 *///from  ww  w . j  a v  a 2  s.  c o  m
public Class<?> getJavaClass() {
    if (this.getType() == null) {
        return null;
    }

    try {
        return Util.getJavaClass(getType());
    } catch (ClassNotFoundException e) {
        throw new CayenneRuntimeException(
                "Failed to load class for name '" + this.getType() + "': " + e.getMessage(), e);
    }
}

From source file:org.apache.tika.parser.jdbc.SQLite3DBParser.java

@Override
protected Connection getConnection(InputStream stream, Metadata metadata, ParseContext context)
        throws IOException {
    String connectionString = getConnectionString(stream, metadata, context);

    Connection connection = null;
    try {/* w  w  w  . j  a  v a2s  .  c o  m*/
        Class.forName(getJDBCClassName());
    } catch (ClassNotFoundException e) {
        throw new IOExceptionWithCause(e);
    }
    try {
        SQLiteConfig config = new SQLiteConfig();

        //good habit, but effectively meaningless here
        config.setReadOnly(true);
        connection = config.createConnection(connectionString);

    } catch (SQLException e) {
        throw new IOException(e.getMessage());
    }
    return connection;
}

From source file:nonjsp.application.BuildComponentFromTagImpl.java

public UIComponent createComponentForTag(String shortTagName) {
    UIComponent result = null;/*from   w  w  w .  ja v  a2s  .c o m*/
    if (!tagHasComponent(shortTagName)) {
        return result;
    }

    String className = (String) classMap.get(shortTagName);
    Class componentClass;

    // PENDING(edburns): this can be way optimized
    try {
        componentClass = Util.loadClass(className);
        result = (UIComponent) componentClass.newInstance();
    } catch (IllegalAccessException iae) {
        throw new RuntimeException("Can't create instance for " + className + ": " + iae.getMessage());
    } catch (InstantiationException ie) {
        throw new RuntimeException("Can't create instance for " + className + ": " + ie.getMessage());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Can't find class for " + className + ": " + e.getMessage());
    }

    return result;
}

From source file:com.fujitsu.dc.engine.extension.support.ExtensionJarLoader.java

/**
 * jar???JavaScript??? Set??.//from   ww w  .ja  va  2 s .  co  m
 * @param jarPaths  jar?
 * @param filter Extension
 * @return Javascript??????Java?
 * @throws IOException ?????/????
 */
@SuppressWarnings("unchecked")
private Set<Class<? extends Scriptable>> loadPrototypeClassSet(List<URL> jarPaths, ExtensionClassFilter filter)
        throws IOException, DcEngineException {
    scriptableClassSet = new HashSet<Class<? extends Scriptable>>();

    for (URL jarUrl : jarPaths) {
        JarFile jar = null;
        try {
            File jarFile = new File(jarUrl.getPath());
            if (jarFile.isDirectory()) {
                continue;
            }
            jar = new JarFile(jarFile);

            for (Enumeration<JarEntry> ent = jar.entries(); ent.hasMoreElements();) {
                JarEntry entry = ent.nextElement();
                String[] pathAndName = resolveJarEntry(entry.getName());
                if (null == pathAndName) {
                    continue;
                }
                String entryPath = pathAndName[0];
                String entryName = pathAndName[1];
                if (null == entryPath || null == entryName) {
                    continue;
                }
                //   jar??"/" ????????
                entryPath = entryPath.replaceAll("\\/", "\\.");
                // ??? JavaScript????? filter??????
                if (filter.accept(entryPath, entryName)) {
                    String className = entryPath + "." + entryName;
                    try {
                        Class<?> cl = classloader.loadClass(className);
                        if (ScriptableObject.class.isAssignableFrom(cl)
                                || Scriptable.class.isAssignableFrom(cl)) {
                            scriptableClassSet.add((Class<? extends Scriptable>) cl);
                            log.info(String.format("Info: Extension class %s is revealed to JavaScript.",
                                    className));
                            // OK.
                            continue;
                        }
                        // ScriptableObject/Scriptable????????JavaScript??????
                        log.info(String.format("Info: Extension class %s is not derived from "
                                + "ScriptableObject class or does not implment Scriptable interface. Ignored.",
                                className));
                    } catch (ClassNotFoundException e) {
                        log.warn(String.format("Warn: Extension class %s is not found in classLoader: %s",
                                className, e.getMessage()), e);
                    } catch (NoClassDefFoundError e) {
                        log.warn(String.format("Warn: Extension class %s is not found in classLoader: %s",
                                className, e.getMessage()), e);
                    } catch (Exception e) {
                        log.warn(String.format("Warn: Extension class %s cannot be loaded into classLoader: %s "
                                + "or the jar content is invalid.", className, e.getMessage()), e);
                    }
                }
            }
        } catch (RuntimeException e) {
            log.warn(String.format("Warn: Failed to handle Extension jar file %s: %s", jarUrl.toString(),
                    e.getMessage()), e);
        } catch (Exception e) {
            log.warn(String.format("Warn: Failed to handle Extension jar file %s: %s", jarUrl.toString(),
                    e.getMessage()), e);
            continue;
        } finally {
            IOUtils.closeQuietly(jar);
        }
    }
    return scriptableClassSet;
}

From source file:io.personium.engine.extension.support.ExtensionJarLoader.java

/**
 * jar???JavaScript??? Set??.//from  www . j a v a 2 s. c  om
 * @param jarPaths  jar?
 * @param filter Extension
 * @return Javascript??????Java?
 * @throws IOException ?????/????
 */
@SuppressWarnings("unchecked")
private Set<Class<? extends Scriptable>> loadPrototypeClassSet(List<URL> jarPaths, ExtensionClassFilter filter)
        throws IOException, PersoniumEngineException {
    scriptableClassSet = new HashSet<Class<? extends Scriptable>>();

    for (URL jarUrl : jarPaths) {
        JarFile jar = null;
        try {
            File jarFile = new File(jarUrl.getPath());
            if (jarFile.isDirectory()) {
                continue;
            }
            jar = new JarFile(jarFile);

            for (Enumeration<JarEntry> ent = jar.entries(); ent.hasMoreElements();) {
                JarEntry entry = ent.nextElement();
                String[] pathAndName = resolveJarEntry(entry.getName());
                if (null == pathAndName) {
                    continue;
                }
                String entryPath = pathAndName[0];
                String entryName = pathAndName[1];
                if (null == entryPath || null == entryName) {
                    continue;
                }
                //   jar??"/" ????????
                entryPath = entryPath.replaceAll("\\/", "\\.");
                // ??? JavaScript????? filter??????
                if (filter.accept(entryPath, entryName)) {
                    String className = entryPath + "." + entryName;
                    try {
                        Class<?> cl = classloader.loadClass(className);
                        if (ScriptableObject.class.isAssignableFrom(cl)
                                || Scriptable.class.isAssignableFrom(cl)) {
                            scriptableClassSet.add((Class<? extends Scriptable>) cl);
                            log.info(String.format("Info: Extension class %s is revealed to JavaScript.",
                                    className));
                            // OK.
                            continue;
                        }
                        // ScriptableObject/Scriptable????????JavaScript??????
                        log.info(String.format("Info: Extension class %s is not derived from "
                                + "ScriptableObject class or does not implment Scriptable interface. Ignored.",
                                className));
                    } catch (ClassNotFoundException e) {
                        log.warn(String.format("Warn: Extension class %s is not found in classLoader: %s",
                                className, e.getMessage()), e);
                    } catch (NoClassDefFoundError e) {
                        log.warn(String.format("Warn: Extension class %s is not found in classLoader: %s",
                                className, e.getMessage()), e);
                    } catch (Exception e) {
                        log.warn(String.format("Warn: Extension class %s cannot be loaded into classLoader: %s "
                                + "or the jar content is invalid.", className, e.getMessage()), e);
                    }
                }
            }
        } catch (RuntimeException e) {
            log.warn(String.format("Warn: Failed to handle Extension jar file %s: %s", jarUrl.toString(),
                    e.getMessage()), e);
        } catch (Exception e) {
            log.warn(String.format("Warn: Failed to handle Extension jar file %s: %s", jarUrl.toString(),
                    e.getMessage()), e);
            continue;
        } finally {
            IOUtils.closeQuietly(jar);
        }
    }
    return scriptableClassSet;
}

From source file:lu.softec.xwiki.macro.internal.ClassRunnerMacro.java

protected String execute(ClassLoader loader, String className, ClassRunnerMacroParameters parameters,
        Object xcontext) throws MacroExecutionException {
    StringWriter stringWriter = new StringWriter();
    boolean hasArgs = (parameters.getRawProperties() != null);
    Map<String, Object> args = (hasArgs) ? parameters.getRawProperties() : new LinkedHashMap<String, Object>();

    Class<?> klass;//from   w  ww  .  jav  a  2  s. co m
    try {
        klass = loader.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new MacroExecutionException(e.getMessage(), e);
    }

    Method[] methods = klass.getMethods();
    Method run1 = null;
    Method run2 = null;
    Method run3 = null;
    Method setContext1 = null;
    Method setContext2 = null;
    Method getParser = null;
    for (Method m : methods) {
        if (m.getName().equals("run")) {
            Class<?>[] types = m.getParameterTypes();
            if (types.length == 1 && types[0].isAssignableFrom(stringWriter.getClass())) {
                run1 = m;
            } else if (types.length == 2 && types[0].isAssignableFrom(stringWriter.getClass())
                    && types[1].isAssignableFrom(xcontext.getClass())) {
                run2 = m;
            } else if (types.length == 3 && types[0].isAssignableFrom(stringWriter.getClass())
                    && types[1].isAssignableFrom(args.getClass())
                    && types[2].isAssignableFrom(xcontext.getClass())) {
                run3 = m;
            }
        } else if (m.getName().equals("setContext")) {
            Class<?>[] types = m.getParameterTypes();
            if (types.length == 1 && types[0].isAssignableFrom(xcontext.getClass())) {
                setContext1 = m;
            } else if (types.length == 2 && types[0].isAssignableFrom(args.getClass())
                    && types[1].isAssignableFrom(xcontext.getClass())) {
                setContext2 = m;
            }
        } else if (m.getName().equals("getParser")) {
            Class<?>[] types = m.getParameterTypes();
            if (types.length == 0) {
                getParser = m;
            }
        }
        if (run2 != null && run3 != null && setContext1 != null && setContext2 != null && getParser != null)
            break;
    }

    if (run2 == null && run3 == null) {
        throw new MacroExecutionException(
                "Unable to find the appropriate run(Writer,XWikiContext) or run(Writer,Map,XWikiContext) method in the class.");
    }

    try {
        Object obj = klass.newInstance();
        if (setContext2 != null && (hasArgs || setContext1 == null)) {
            setContext2.invoke(obj, args, xcontext);
        } else if (setContext1 != null) {
            setContext1.invoke(obj, xcontext);
        }
        if (setContext2 != null || setContext1 != null) {
            if (getParser != null) {
                String parser = null;
                parser = (String) getParser.invoke(obj);
                if (parser != null) {
                    parameters.setParser(parser);
                }
            }
            run1.invoke(obj, stringWriter);
        } else {
            if (run3 != null && (hasArgs || run2 == null)) {
                run3.invoke(obj, stringWriter, args, xcontext);
            } else {
                run2.invoke(obj, stringWriter, xcontext);
            }
        }
    } catch (Exception e) {
        throw new MacroExecutionException(e.getMessage(), e);
    }

    return (stringWriter.toString());
}