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:org.apache.carbondata.core.util.ObjectSerializationUtil.java

/**
 * Converts Base64 string to object./* www  .  j av a 2  s .c  om*/
 *
 * @param objectString serialized object in string format
 * @return Object after convert string to object
 * @throws IOException
 */
public static Object convertStringToObject(String objectString) throws IOException {
    if (objectString == null) {
        return null;
    }

    byte[] bytes = CarbonUtil.decodeStringToBytes(objectString);

    ByteArrayInputStream bais = null;
    GZIPInputStream gis = null;
    ObjectInputStream ois = null;

    try {
        bais = new ByteArrayInputStream(bytes);
        gis = new GZIPInputStream(bais);
        ois = new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), gis);
        return ois.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException("Could not read object", e);
    } finally {
        try {
            if (ois != null) {
                ois.close();
            }
            if (gis != null) {
                gis.close();
            }
            if (bais != null) {
                bais.close();
            }
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
    }
}

From source file:com.he5ed.lib.cloudprovider.utils.AuthHelper.java

/**
 * Extract user information from the JSONObject
 *
 * @param cloudApi type of cloud account
 * @param jsonObject JSONObject that contain user information
 * @return User/*w w w  .  ja  va  2s  .co m*/
 * @throws JSONException
 */
public static User extractUser(String cloudApi, JSONObject jsonObject) throws JSONException {
    // use reflection for flexibility
    try {
        Class<?> clazz = Class.forName(cloudApi);
        Method extractUser = clazz.getMethod("extractUser", JSONObject.class);
        return (User) extractUser.invoke(null, jsonObject);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        // catch exception throw by class method
        if (e.getCause() instanceof JSONException) {
            throw new JSONException(e.getMessage());
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.he5ed.lib.cloudprovider.utils.AuthHelper.java

/**
 * Extract access token from the JSONObject
 *
 * @param cloudApi type of cloud account
 * @param jsonObject JSONObject that contain access token
 * @return Map/*from  w  w  w.j a v a 2s.  c  o  m*/
 * @throws JSONException
 */
public static Map<String, String> extractAccessToken(String cloudApi, JSONObject jsonObject)
        throws JSONException {
    // use reflection for flexibility
    try {
        Class<?> clazz = Class.forName(cloudApi);
        Method extractAccessToken = clazz.getMethod("extractAccessToken", JSONObject.class);
        return (Map) extractAccessToken.invoke(null, jsonObject);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        // catch exception throw by class method
        if (e.getCause() instanceof JSONException) {
            throw new JSONException(e.getMessage());
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

/**
 * Returns a {@code Class} object which represents the class with
 * the given name. The name should be the name of a non-primitive
 * class, as described in the {@link Class class definition}.
 * Primitive types can not be found using this method; use {@code
 * int.class} or {@code Integer.TYPE} instead.
 *
 * @param packages  class package/*from  w  ww .  j  a v a2  s.  c o  m*/
 * @param className given class name
 * @return
 */
public static Class<?> forName(String[] packages, String className) {
    if (packages != null && packages.length > 0 && !className.contains(".")
            && !CLASS_CACHE.containsKey(className)) {
        for (String pkg : packages) {
            try {
                return _forName(pkg + "." + className);
            } catch (ClassNotFoundException e2) {
            }
        }
        try {
            return _forName("java.lang." + className);
        } catch (ClassNotFoundException e2) {
        }
    }
    try {
        return _forName(className);
    } catch (ClassNotFoundException e) {
        int index = className.lastIndexOf('.');
        if (index > 0 && index < className.length() - 1) {
            try {
                return _forName(className.substring(0, index) + "$" + className.substring(index + 1));
            } catch (ClassNotFoundException e2) {
            }
        }
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:com.aurel.track.admin.customize.category.report.execute.ReportExecuteBL.java

/**
 * Get the FieldType by class name//w w  w.  j  ava2s . c om
 *
 * @param fieldTypeClassName
 * @return
 */
public static IPluggableDatasource pluggableDatasouceFactory(String pluggableDatasouceClassName) {
    Class pluggableDatasouceClass = null;
    if (pluggableDatasouceClassName == null) {
        LOGGER.warn("No PluggableDatasource specified ");
        return null;
    }
    try {
        pluggableDatasouceClass = Class.forName(pluggableDatasouceClassName);
    } catch (final ClassNotFoundException e) {
        LOGGER.error("The PluggableDatasouce class " + pluggableDatasouceClassName
                + "  not found found in the classpath " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (pluggableDatasouceClass != null) {
        try {
            return (IPluggableDatasource) pluggableDatasouceClass.newInstance();
        } catch (final Exception e) {
            LOGGER.error("Instantiating the PluggableDatasouce class " + pluggableDatasouceClassName
                    + "  failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    return null;
}

From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java

private static Principal parsePrincipal(AuthorizationTokenStream ats)
        throws AuthorizationSyntaxParseException, IOException {
    String principal = ats.nextUsefulToken();
    String className = ats.nextUsefulToken();
    String roleName = ats.nextUsefulToken();
    if (principal == null || !principal.toLowerCase().equals("principal")) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", principal syntax error");
    }//w  w w.  java2  s  . c o m
    if (className == null) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", className is null");
    }
    if (roleName == null) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", roleName is null");
    } else {
        roleName = StringUtils.strip(roleName, "\"");
        roleName = roleName.replace("*", "All");
    }

    try {
        Class<?> clazz = Class.forName(className);
        return ((Principal) clazz.getDeclaredConstructor(String.class).newInstance(roleName));
    } catch (ClassNotFoundException e) {
        throw new AuthorizationSyntaxParseException(
                "Line " + ats.getLineNum() + ", ClassNotFoundException, " + e.getMessage());
    } catch (Exception e) {
        throw new AuthorizationSyntaxParseException(
                "Line " + ats.getLineNum() + ", Exception happens, " + e.getMessage());
    }

}

From source file:org.apache.jackrabbit.oak.plugins.document.rdb.RDBExport.java

private static void dumpJDBC(String url, String user, String pw, String table, String query, Format format,
        PrintStream out, List<String> fieldNames, RDBDocumentSerializer ser) throws SQLException {
    String driver = RDBJDBCTools.driverForDBType(RDBJDBCTools.jdbctype(url));
    try {//from w  w w.  j a v a2s  .c  o  m
        Class.forName(driver);
    } catch (ClassNotFoundException ex) {
        System.err.println(
                RDBExport.class.getName() + ":attempt to load class " + driver + " failed:" + ex.getMessage());
    }
    Connection c = DriverManager.getConnection(url, user, pw);
    c.setReadOnly(true);
    Statement stmt = c.createStatement();
    String sql = "select ID, MODIFIED, MODCOUNT, CMODCOUNT, HASBINARY, DELETEDONCE, DATA, BDATA from " + table;
    if (query != null) {
        sql += " where " + query;
    }
    sql += " order by id";
    ResultSet rs = stmt.executeQuery(sql);

    if (format == Format.JSONARRAY) {
        out.println("[");
    } else if (format == Format.CSV) {
        out.println(dumpFieldNames(fieldNames));
    }
    boolean needComma = format == Format.JSONARRAY;
    ResultSetMetaData rsm = null;
    boolean idIsAscii = true;
    while (rs.next()) {
        if (rsm == null) {
            rsm = rs.getMetaData();
            idIsAscii = !isBinaryType(rsm.getColumnType(1));
        }
        String id = idIsAscii ? rs.getString("ID") : new String(rs.getBytes("ID"), UTF8);
        long modified = rs.getLong("MODIFIED");
        long modcount = rs.getLong("MODCOUNT");
        long cmodcount = rs.getLong("CMODCOUNT");
        long hasBinary = rs.getLong("HASBINARY");
        long deletedOnce = rs.getLong("DELETEDONCE");
        String data = rs.getString("DATA");
        byte[] bdata = rs.getBytes("BDATA");

        RDBRow row = new RDBRow(id, hasBinary == 1, deletedOnce == 1, modified, modcount, cmodcount, data,
                bdata);
        StringBuilder fulljson = dumpRow(ser, id, row);
        if (format == Format.CSV) {
            out.println(asCSV(fieldNames, fulljson));
        } else {
            fulljson = asJSON(fieldNames, fulljson);
            if (format == Format.JSONARRAY && needComma && !rs.isLast()) {
                fulljson.append(",");
            }
            out.println(fulljson);
            needComma = true;
        }
    }
    if (format == Format.JSONARRAY) {
        out.println("]");
    }
    out.close();
    rs.close();
    stmt.close();
    c.close();
}

From source file:org.apache.tiles.ComponentDefinition.java

/**
 * Create a controller from specified classname
 * @param classname Controller classname.
 * @return org.apache.tiles.Controller//  w  w w .j  a va2 s . c o m
 * @throws InstantiationException if an error occur while instanciating Controller :
 * (classname can't be instanciated, Illegal access with instanciated class,
 * Error while instanciating class, classname can't be instanciated.
 */
public static Controller createControllerFromClassname(String classname) throws InstantiationException {

    try {
        Class requestedClass = TilesUtil.applicationClass(classname);
        Object instance = requestedClass.newInstance();

        if (log.isDebugEnabled()) {
            log.debug("Controller created : " + instance);
        }
        return (Controller) instance;

    } catch (java.lang.ClassNotFoundException ex) {
        throw new InstantiationException("Error - Class not found :" + ex.getMessage());

    } catch (java.lang.IllegalAccessException ex) {
        throw new InstantiationException("Error - Illegal class access :" + ex.getMessage());

    } catch (java.lang.InstantiationException ex) {
        throw ex;

    } catch (java.lang.ClassCastException ex) {
        throw new InstantiationException(
                "Controller of class '" + classname + "' should implements 'Controller' or extends 'Action'");
    }
}

From source file:org.apache.struts.tiles.ComponentDefinition.java

/**
 * Create a controller from specified classname
 * @param classname Controller classname.
 * @return org.apache.struts.tiles.Controller
 * @throws InstantiationException if an error occur while instanciating Controller :
 * (classname can't be instanciated, Illegal access with instanciated class,
 * Error while instanciating class, classname can't be instanciated.
 *///from w  w w  . j  av  a 2 s  .  co m
public static Controller createControllerFromClassname(String classname) throws InstantiationException {

    try {
        Class requestedClass = RequestUtils.applicationClass(classname);
        Object instance = requestedClass.newInstance();

        if (log.isDebugEnabled()) {
            log.debug("Controller created : " + instance);
        }
        return (Controller) instance;

    } catch (java.lang.ClassNotFoundException ex) {
        throw new InstantiationException("Error - Class not found :" + ex.getMessage());

    } catch (java.lang.IllegalAccessException ex) {
        throw new InstantiationException("Error - Illegal class access :" + ex.getMessage());

    } catch (java.lang.InstantiationException ex) {
        throw ex;

    } catch (java.lang.ClassCastException ex) {
        throw new InstantiationException(
                "Controller of class '" + classname + "' should implements 'Controller' or extends 'Action'");
    }
}

From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java

private static Permission parsePermission(AuthorizationTokenStream ats)
        throws AuthorizationSyntaxParseException, IOException {
    String perm = ats.nextUsefulToken();
    if (perm == null) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", permission syntax error");
    } else if (!perm.toLowerCase().equals("permission")) {
        String rightBracket = perm;
        if (rightBracket == null || !rightBracket.contains("}")) {
            throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", no right bracket");
        } else if (!rightBracket.contains(";")) {
            throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", no \";\" sign finded");
        }/*from  ww w  .  j  a va 2 s . c  o  m*/
        return null;
    }
    String className = ats.nextUsefulToken();
    String isEnd = ats.nextUsefulToken();
    if (className == null) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", className is null");
    }
    if (isEnd == null) {
        throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", no operate object defined");
    } else {
        try {
            if (!isEnd.contains(";")) {
                String oper = isEnd;
                oper = oper.replace("\"", "");
                oper = oper.replace(",", "");
                isEnd = ats.nextUsefulToken();
                if (isEnd != null && isEnd.contains(";")) {
                    String actions = isEnd.replace(";", "");
                    actions = actions.replace("\"", "");
                    Class<?> clazz = Class.forName(className, false, VWBPermission.class.getClassLoader());
                    return ((Permission) clazz
                            .getDeclaredConstructor(new Class[] { String.class, String.class })
                            .newInstance(oper, actions));
                } else {
                    throw new AuthorizationSyntaxParseException(
                            "Line " + ats.getLineNum() + ", no \";\" sign finded");
                }
            } else {
                String oper = isEnd.replace(";", "");
                oper = oper.replace("\"", "");
                Class<?> clazz = Class.forName(className);
                return ((Permission) clazz.getDeclaredConstructor(String.class).newInstance(oper));
            }
        } catch (ClassNotFoundException e) {
            throw new AuthorizationSyntaxParseException(
                    "Line " + ats.getLineNum() + ", ClassNotFoundException, " + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw new AuthorizationSyntaxParseException(
                    "Line " + ats.getLineNum() + ", Exception happens, " + e.getMessage());
        }
    }
}