List of usage examples for java.lang ClassNotFoundException getMessage
public String getMessage()
From source file:org.apache.accumulo.core.util.shell.commands.ScanCommand.java
protected Class<? extends Formatter> getFormatter(final CommandLine cl, final String tableName, final Shell shellState) throws IOException { try {/* w w w . j a va2 s . c om*/ if (cl.hasOption(formatterOpt.getOpt())) { return AccumuloVFSClassLoader.loadClass(cl.getOptionValue(formatterOpt.getOpt()), Formatter.class); } else if (cl.hasOption(formatterInterpeterOpt.getOpt())) { return AccumuloVFSClassLoader.loadClass(cl.getOptionValue(formatterInterpeterOpt.getOpt()), Formatter.class); } } catch (ClassNotFoundException e) { shellState.getReader().println("Formatter class could not be loaded.\n" + e.getMessage()); } return shellState.getFormatter(tableName); }
From source file:org.apache.myfaces.renderkit.html.util.MyFacesResourceLoader.java
/** * Given a URI of form "{partial.class.name}/{resourceName}", locate the * specified file within the current classpath and write it to the * response object.// ww w. j a v a 2 s. c o m * <p> * The partial class name has "org.apache.myfaces.custom." prepended * to it to form the fully qualified classname. This class object is * loaded, and Class.getResourceAsStream is called on it, passing * a uri of "resource/" + {resourceName}. * <p> * The data written to the response stream includes http headers * which define the mime content-type; this is deduced from the * filename suffix of the resource. * <p> * @see org.apache.myfaces.renderkit.html.util.ResourceLoader#serveResource(javax.servlet.ServletContext, * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String) */ public void serveResource(ServletContext context, HttpServletRequest request, HttpServletResponse response, String resourceUri) throws IOException { String[] uriParts = resourceUri.split("/", 2); String component = uriParts[0]; if (component == null || component.trim().length() == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request"); log.error("Could not find parameter for component to load a resource."); return; } Class componentClass; String className = ORG_APACHE_MYFACES_CUSTOM + "." + component; try { componentClass = loadComponentClass(className); } catch (ClassNotFoundException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); log.error("Could not find the class for component " + className + " to load a resource."); return; } String resource = uriParts[1]; if (resource == null || resource.trim().length() == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No resource defined"); log.error("No resource defined component class " + className); return; } InputStream is = null; try { ResourceProvider resourceProvider; if (ResourceProvider.class.isAssignableFrom(componentClass)) { try { resourceProvider = (ResourceProvider) componentClass.newInstance(); } catch (InstantiationException e) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Unable to instantiate resource provider for resource " + resource + " for component " + component); log.error("Unable to instantiate resource provider for resource " + resource + " for component " + component, e); return; } catch (IllegalAccessException e) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Unable to instantiate resource provider for resource " + resource + " for component " + component); log.error("Unable to instantiate resource provider for resource " + resource + " for component " + component, e); return; } } else { resourceProvider = new DefaultResourceProvider(componentClass); } if (!resourceProvider.exists(context, resource)) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unable to find resource " + resource + " for component " + component + ". Check that this file is available " + "in the classpath in sub-directory " + "/resource of the package-directory."); log.error("Unable to find resource " + resource + " for component " + component + ". Check that this file is available " + "in the classpath in sub-directory " + "/resource of the package-directory."); } else { // URLConnection con = url.openConnection(); long lastModified = resourceProvider.getLastModified(context, resource); if (lastModified < 1) { // fallback lastModified = getLastModified(); } long browserDate = request.getDateHeader("If-Modified-Since"); if (browserDate > -1) { // normalize to seconds - this should work with any os lastModified = (lastModified / 1000) * 1000; browserDate = (browserDate / 1000) * 1000; if (lastModified == browserDate) { // the browser already has the correct version response.setStatus(HttpURLConnection.HTTP_NOT_MODIFIED); return; } } int contentLength = resourceProvider.getContentLength(context, resource); String contentEncoding = resourceProvider.getEncoding(context, resource); is = resourceProvider.getInputStream(context, resource); defineContentHeaders(request, response, resource, contentLength, contentEncoding); defineCaching(request, response, resource, lastModified); writeResource(request, response, is); } } finally { // nothing to do here.. } }
From source file:org.carlspring.tools.csv.dao.CSVDao.java
public Connection getConnection() throws SQLException { Connection connection = null; try {/*from w w w.j a v a 2s. c om*/ Class.forName(getDriver()); connection = DriverManager.getConnection(getJdbcURL(), getUsername(), getPassword()); } catch (ClassNotFoundException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } return connection; }
From source file:org.apache.lens.server.session.TestSessionClassLoaders.java
/** * Check that any added resources to the session are available after database is switched * @throws Exception//from w ww. j a va 2s. c om */ @Test public void testClassLoaderMergeAfterAddResources() throws Exception { LensSessionHandle sessionHandle = sessionService.openSession("foo", "bar", new HashMap<String, String>()); LensSessionImpl session = sessionService.getSession(sessionHandle); session.setDbResService(sessionService.getDatabaseResourceService()); File sessionJar = new File("testdata/test2.jar"); String sessionJarLocation = "file://" + sessionJar.getAbsolutePath(); session.setCurrentDatabase("default"); sessionService.addResource(sessionHandle, "jar", sessionJarLocation); session.addResource("jar", sessionJarLocation); session.setCurrentDatabase("default"); boolean loadedSessionClass = false; boolean loadedDBClass = false; try { LOG.info("@@@ TEST 1"); sessionService.acquire(sessionHandle); ClassLoader dbClassLoader = session.getClassLoader("default"); Assert.assertTrue(Thread.currentThread().getContextClassLoader() == dbClassLoader); // testClass2 should be loaded since test2.jar is added to the session Class testClass2 = dbClassLoader.loadClass("ClassLoaderTestClass2"); //Class testClass2 = Class.forName("ClassLoaderTestClass2", true, dbClassLoader); loadedSessionClass = true; // class inside 'test.jar' should fail to load since its not added to default DB. Class clz = Class.forName("ClassLoaderTestClass", true, Thread.currentThread().getContextClassLoader()); loadedDBClass = true; } catch (ClassNotFoundException cnf) { LOG.error(cnf.getMessage(), cnf); Assert.assertTrue(loadedSessionClass); Assert.assertFalse(loadedDBClass); } finally { sessionService.release(sessionHandle); } // check loading on cube metastore client loadedSessionClass = false; loadedDBClass = false; try { LOG.info("@@@ TEST 1 - cube client"); sessionService.acquire(sessionHandle); // testClass2 should be loaded since test2.jar is added to the session Class testClass2 = session.getCubeMetastoreClient().getConf().getClassByName("ClassLoaderTestClass2"); //Class testClass2 = Class.forName("ClassLoaderTestClass2", true, dbClassLoader); loadedSessionClass = true; // class inside 'test.jar' should fail to load since its not added to default DB. Class clz = session.getCubeMetastoreClient().getConf().getClassByName("ClassLoaderTestClass"); loadedDBClass = true; } catch (ClassNotFoundException cnf) { LOG.error(cnf.getMessage(), cnf); Assert.assertTrue(loadedSessionClass); Assert.assertFalse(loadedDBClass); } finally { sessionService.release(sessionHandle); } LOG.info("@@@ TEST 2"); session.setCurrentDatabase(DB1); loadedSessionClass = false; loadedDBClass = false; try { sessionService.acquire(sessionHandle); // testClass2 should be loaded since test2.jar is added to the session URLClassLoader urlClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); Class testClass2 = Class.forName("ClassLoaderTestClass2", true, Thread.currentThread().getContextClassLoader()); // class inside 'test.jar' should also load since its added to DB1 loadedSessionClass = true; Class clz = Class.forName("ClassLoaderTestClass", true, Thread.currentThread().getContextClassLoader()); loadedDBClass = true; } finally { sessionService.release(sessionHandle); } Assert.assertTrue(loadedSessionClass); Assert.assertTrue(loadedDBClass); LOG.info("@@@ TEST 2 - cube client"); loadedSessionClass = false; loadedDBClass = false; try { sessionService.acquire(sessionHandle); Class testClass2 = session.getCubeMetastoreClient().getConf().getClassByName("ClassLoaderTestClass2"); // class inside 'test.jar' should also load since its added to DB1 loadedSessionClass = true; Class clz = session.getCubeMetastoreClient().getConf().getClassByName("ClassLoaderTestClass"); loadedDBClass = true; } finally { sessionService.release(sessionHandle); } Assert.assertTrue(loadedSessionClass); Assert.assertTrue(loadedDBClass); // Switch back to default DB, again the test2.jar should be available, test.jar should not be available LOG.info("@@@ TEST 3"); session.setCurrentDatabase("default"); loadedSessionClass = false; loadedDBClass = false; try { sessionService.acquire(sessionHandle); // testClass2 should be loaded since test2.jar is added to the session Class testClass2 = Class.forName("ClassLoaderTestClass2", true, Thread.currentThread().getContextClassLoader()); // class inside 'test.jar' should fail to load since its not added to default DB. loadedSessionClass = true; Class clz = Class.forName("ClassLoaderTestClass", true, Thread.currentThread().getContextClassLoader()); loadedDBClass = true; } catch (ClassNotFoundException cnf) { Assert.assertTrue(loadedSessionClass); Assert.assertFalse(loadedDBClass); } finally { sessionService.release(sessionHandle); } LOG.info("@@@ TEST 3 -- cube client"); session.setCurrentDatabase("default"); loadedSessionClass = false; loadedDBClass = false; try { sessionService.acquire(sessionHandle); // testClass2 should be loaded since test2.jar is added to the session Class testClass2 = session.getCubeMetastoreClient().getConf().getClassByName("ClassLoaderTestClass2"); //Class testClass2 = Class.forName("ClassLoaderTestClass2", true, dbClassLoader); loadedSessionClass = true; // class inside 'test.jar' should fail to load since its not added to default DB. Class clz = session.getCubeMetastoreClient().getConf().getClassByName("ClassLoaderTestClass"); loadedDBClass = true; } catch (ClassNotFoundException cnf) { LOG.error(cnf.getMessage(), cnf); Assert.assertTrue(loadedSessionClass); Assert.assertFalse(loadedDBClass); } finally { sessionService.release(sessionHandle); } sessionService.closeSession(sessionHandle); }
From source file:com.mapd.bench.BenchmarkCloud.java
void doWork(String[] args, int query) { //Grab parameters from args // parm0 number of iterations per query // parm1 file containing sql queries {contains quoted query, expected result count] // parm2 table name // parm3 run label // parm4 gpu count // parm5 optional query and result machine // parm6 optional DB URL // parm7 optional JDBC Driver class name // parm8 optional user // parm9 optional passwd int iterations = Integer.valueOf(args[0]); logger.debug("Iterations per query is " + iterations); String queryFile = args[1];/*from ww w.j ava 2 s. c o m*/ tableName = args[2]; label = args[3]; gpuCount = args[4]; //int expectedResults = Integer.valueOf(args[2]); queryResultMachine = (args.length > 5) ? args[5] : QUERY_RESULT_MACHINE; url = (args.length > 6) ? args[6] : DB_URL; driver = (args.length > 7) ? args[7] : JDBC_DRIVER; iUser = (args.length > 8) ? args[8] : USER; iPasswd = (args.length > 9) ? args[9] : PASS; //register the driver try { //Register JDBC driver Class.forName(driver); } catch (ClassNotFoundException ex) { logger.error("Could not load class " + driver + " " + ex.getMessage()); System.exit(1); } UUID uuid = UUID.randomUUID(); rid = uuid.toString(); java.util.Date date = new java.util.Date(); Timestamp t = new Timestamp(date.getTime()); rTimestamp = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(t); System.out.println("run id is " + rid + " date is " + rTimestamp); // read from query file and execute queries String sCurrentLine; List<String> resultArray = new ArrayList(); Map<String, String> queryIDMap = new LinkedHashMap(); BufferedReader br; try { br = new BufferedReader(new FileReader(queryFile)); while ((sCurrentLine = br.readLine()) != null) { queryIDMap.put(sCurrentLine, null); } br.close(); } catch (FileNotFoundException ex) { logger.error("Could not find file " + queryFile + " " + ex.getMessage()); System.exit(2); } catch (IOException ex) { logger.error("IO Exeception " + ex.getMessage()); System.exit(3); } bencherCon = getConnection("jdbc:mapd:" + queryResultMachine + ":9091:mapd", "mapd", "HyperInteractive"); getQueries(queryIDMap, bencherCon, tableName); runQueries(resultArray, queryIDMap, iterations); // if all completed ok store the results storeResults(); // All done dump out results System.out.println(header2); for (String s : resultArray) { System.out.println(s); } }
From source file:net.mojodna.sprout.SproutAutoLoaderPlugIn.java
private void autoloadFromDirectory(final ClassLoader loader, final int baseLength, File directory) { File[] files = directory.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i];// w w w.java 2 s . co m if (file.isDirectory()) { autoloadFromDirectory(loader, baseLength, file); } else { String path = file.getPath(); if (path.endsWith(".class")) { int length = path.length(); String className = path.substring(baseLength, length - 6).replace('/', '.'); try { Class c = loader.loadClass(className); if (decendsFrom(ActionForm.class, c)) { loadForm(c); } else if (decendsFrom(org.apache.struts.action.Action.class, c)) { loadAction(c); } } catch (ClassNotFoundException ex) { log.error("Failed to load class, " + ex.getMessage()); } } } } }
From source file:gaffer.store.schema.Schema.java
public void setVertexSerialiserClass(final String vertexSerialiserClass) { if (null == vertexSerialiserClass) { this.vertexSerialiser = DEFAULT_VERTEX_SERIALISER; } else {//from www . j a v a 2 s. c om Class<? extends Serialisation> serialiserClass; try { serialiserClass = Class.forName(vertexSerialiserClass).asSubclass(Serialisation.class); } catch (ClassNotFoundException e) { throw new SchemaException(e.getMessage(), e); } try { setVertexSerialiser(serialiserClass.newInstance()); } catch (IllegalAccessException | IllegalArgumentException | SecurityException | InstantiationException e) { throw new SchemaException(e.getMessage(), e); } } }
From source file:org.apache.accumulo.core.util.shell.commands.ScanCommand.java
protected ScanInterpreter getInterpreter(final CommandLine cl, final String tableName, final Shell shellState) throws Exception { Class<? extends ScanInterpreter> clazz = null; try {/* ww w . j ava 2 s .co m*/ if (cl.hasOption(interpreterOpt.getOpt())) { clazz = AccumuloVFSClassLoader.loadClass(cl.getOptionValue(interpreterOpt.getOpt()), ScanInterpreter.class); } else if (cl.hasOption(formatterInterpeterOpt.getOpt())) { clazz = AccumuloVFSClassLoader.loadClass(cl.getOptionValue(formatterInterpeterOpt.getOpt()), ScanInterpreter.class); } } catch (ClassNotFoundException e) { shellState.getReader().println("Interpreter class could not be loaded.\n" + e.getMessage()); } if (clazz == null) clazz = InterpreterCommand.getCurrentInterpreter(tableName, shellState); if (clazz == null) clazz = DefaultScanInterpreter.class; return clazz.newInstance(); }
From source file:org.commonjava.aprox.core.expire.DatabaseLifecycleActions.java
@Override public void stop() throws AproxLifecycleException { final String dbDriver = schedulerConfig.getDbDriver(); if (dbDriver.startsWith(APACHEDB_DRIVER_SUPER_PACKAGE)) { final String url = APACHEDB_SHUTDOWN_URL; Connection connection = null; try {//w ww . j a v a2s.c o m Thread.currentThread().getContextClassLoader().loadClass(dbDriver); logger.info("Connecting to DB: {}", url); connection = DriverManager.getConnection(url); } catch (final ClassNotFoundException e) { throw new AproxLifecycleException("Failed to load database driver: " + dbDriver, e); } catch (final SQLException e) { logger.debug(e.getMessage(), e); } finally { close(null, null, connection, url); // try // { // final Driver driver = DriverManager.getDriver( url ); // DriverManager.deregisterDriver( driver ); // } // catch ( final SQLException e ) // { // logger.debug( "Failed to deregister database driver for: " + url, e ); // } } } }
From source file:org.apache.marmotta.platform.core.webservices.CoreApplication.java
@Override public synchronized Set<Class<?>> getClasses() { if (classes == null) { classes = new HashSet<Class<?>>(); try {//from w ww . ja v a2 s. com Enumeration<URL> modulePropertiesEnum = this.getClass().getClassLoader() .getResources("kiwi-module.properties"); while (modulePropertiesEnum.hasMoreElements()) { URL moduleUrl = modulePropertiesEnum.nextElement(); Configuration moduleProperties = null; try { moduleProperties = new PropertiesConfiguration(moduleUrl); for (Object clsName : moduleProperties.getList("webservices")) { if (!"".equals(clsName)) { try { Class<?> cls = Class.forName(clsName.toString()); classes.add(cls); log.debug("module {}: registered webservice {}", moduleProperties.getString("name"), cls.getCanonicalName()); } catch (ClassNotFoundException e) { log.error("could not load class {}, it was not found", clsName.toString()); } } } } catch (ConfigurationException e) { log.error("configuration exception: {}", e.getMessage()); } } } catch (IOException e) { log.error("I/O error while trying to load kiwi-module.properties file: {}", e.getMessage()); } } return classes; }