Example usage for java.lang ClassNotFoundException getCause

List of usage examples for java.lang ClassNotFoundException getCause

Introduction

In this page you can find the example usage for java.lang ClassNotFoundException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.rifidi.emulator.reader.commandhandler.CommandHandlerInvoker.java

/**
 * This method takes in a CommandObject as the parameter and then calls the
 * handler method stored in it via reflection. <br />
 * <br />/*from   w  w w  .  j  a  va 2 s. c o m*/
 * The handler method has several assumptions: - It takes a CommandObject as
 * a parameter <br /> - It returns a CommandObject <br />
 * 
 * 
 * If any of the preceding are not met, an exception will be thrown and the
 * parameter will be returned unmodified.
 * 
 * @param newObject
 *            CommandObject that specifies the method and arguments
 * @return Returns CommandObject with the operation's result
 */
@SuppressWarnings("unchecked")
public static CommandObject invokeHandler(CommandObject newObject, AbstractReaderSharedResources asr,
        GenericExceptionHandler geh) {
    String className = newObject.getHandlerClass();
    String methodName = newObject.getHandlerMethod();
    Class c = null;
    try {
        c = Class.forName(className);
    } catch (ClassNotFoundException e) {
        logger.error(e.getLocalizedMessage());
    }

    // Force the single parameter to be a CommandObject. If you
    // want different arguments, this class must be rewritten.
    Class[] parameter = new Class[] { CommandObject.class, AbstractReaderSharedResources.class };
    Method commandMethod;
    Object[] arguments = new Object[] { newObject, asr };

    try {
        commandMethod = c.getMethod(methodName, parameter);
        // You must invoke reflection on an instance of this object
        Object instance = null;
        instance = c.newInstance();
        // Force the return type to be a CommandObject. ;
        newObject = (CommandObject) commandMethod.invoke(instance, arguments);
    } catch (NoSuchMethodException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("error caused by: " + methodName);
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    } catch (IllegalAccessException e) {
        logger.error(e.getLocalizedMessage());
        logger.debug("error caused by: " + methodName);
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        logger.error(e.getCause());
        logger.debug("error caused by: " + methodName);
        logger.error(e.getTargetException());
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    } catch (InstantiationException e) {
        logger.debug("error caused by: " + methodName);
        logger.error(e.getLocalizedMessage());
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    } catch (Exception e) {
        e.printStackTrace();
        logger.debug("error caused by: " + methodName);
        logger.error("Something is defined in the XML that is not" + " defined by a handler method: "
                + newObject.getHandlerMethod());
        newObject = geh.methodInvocationError(new ArrayList<Object>(), newObject);
    }

    return newObject;
}

From source file:br.com.caelum.vraptor.ioc.spring.ComponentScanner.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*w  ww  .  j  av a 2 s. c  o m*/
protected void postProcessBeanDefinition(AbstractBeanDefinition beanDefinition, String beanName) {
    super.postProcessBeanDefinition(beanDefinition, beanName);
    beanDefinition.setPrimary(true);
    beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
    try {
        Class<?> componentType = Class.forName(beanDefinition.getBeanClassName());
        if (ComponentFactory.class.isAssignableFrom(componentType)
                && checkCandidate(beanName, beanDefinition)) {
            registry.registerSingleton(beanDefinition.getBeanClassName(),
                    new ComponentFactoryBean(container, componentType));
        }
    } catch (ClassNotFoundException e) {
        logger.warn("Class " + beanDefinition.getBeanClassName()
                + " was not found during bean definition proccess");
    } catch (ExceptionInInitializerError e) {
        // log and rethrow antipattern is needed, this is rally important
        logger.warn("Class " + beanDefinition.getBeanClassName() + " has problems during initialization",
                e.getCause());
        throw e;
    }
}

From source file:org.wso2.imwrapper.yahoo.YahooWrapperImpl.java

/**
 * Used to make a login call to the relevant IM server.
 * The method does not return untill the login process is completed. In case the login fails it
 * throws an IMException with the details for the failure.
 *
 * @param userID   - The username of the person wishng to send an IM
 * @param password - The password of the person wishng to send an IM
 * @throws org.wso2.imwrapper.core.IMException
 *          - Thrown in case login fails.
 *//*from  w  w  w. j ava2 s . c o  m*/
public void login(String userID, String password) throws IMException {
    try {
        sessionClass = Class.forName("ymsg.network.Session");
        session = sessionClass.newInstance();
        Method method = sessionClass.getMethod("login", new Class[] { String.class, String.class });
        method.invoke(session, new Object[] { userID, password });
        loggedIn = true;
        loginProcessed = true;
    } catch (ClassNotFoundException e) {
        throw new IMException(EXCEPTION);
    } catch (IllegalAccessException e) {
        throw new IMException(EXCEPTION);
    } catch (InstantiationException e) {
        throw new IMException(EXCEPTION);
    } catch (NoSuchMethodException e) {
        throw new IMException(EXCEPTION);
    } catch (Exception e) {
        Throwable throwable = e.getCause();
        if (throwable != null && "ymsg.network.LoginRefusedException".equals(throwable.getClass().getName())) {
            loggedIn = false;
            loginProcessed = true;
            throw new IMException(throwable.getMessage());
        }
    }
}

From source file:org.marketcetera.util.misc.ReflectUtilsTest.java

@Test
public void instance() throws Exception {
    assertEquals(1, ((IntObject) (ReflectUtils.getInstance(IntObject.class.getName(),
            new Class[] { Integer.TYPE }, new Object[] { new Integer(1) }))).getValue());
    try {//from w ww.j a  v a  2  s . c o m
        ReflectUtils.getInstance("NonExistent", null, null);
        fail();
    } catch (ClassNotFoundException ex) {
        assertFalse(Thread.interrupted());
    }
    try {
        ReflectUtils.getInstance(IntObject.class.getName(), new Class[] { Integer.TYPE },
                new Object[] { new Integer(0) });
        fail();
    } catch (InvocationTargetException ex) {
        assertTrue(Thread.interrupted());
        assertEquals(I18NInterruptedRuntimeException.class, ex.getCause().getClass());
    }
}

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

private String getResultType(Class<?> aClass, String name, String[] types) throws MojoExecutionException {
    Class<?>[] argTypes = new Class<?>[types.length];
    final ClassLoader classLoader = getProjectClassLoader();
    for (int i = 0; i < types.length; i++) {
        try {//from   w w w .j a  va 2  s  . co  m
            try {
                argTypes[i] = ApiMethodParser.forName(types[i], classLoader);
            } catch (ClassNotFoundException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        } catch (IllegalArgumentException e) {
            throw new MojoExecutionException(e.getCause().getMessage(), e.getCause());
        }
    }

    // return null for non-public methods, and for non-static methods if includeStaticMethods is null or false
    String result = null;
    try {
        final Method method = aClass.getMethod(name, argTypes);
        int modifiers = method.getModifiers();
        if (!Modifier.isStatic(modifiers) || Boolean.TRUE.equals(includeStaticMethods)) {
            result = method.getReturnType().getCanonicalName();
        }
    } catch (NoSuchMethodException e) {
        // could be a non-public method
        try {
            aClass.getDeclaredMethod(name, argTypes);
        } catch (NoSuchMethodException e1) {
            throw new MojoExecutionException(e1.getMessage(), e1);
        }
    }

    return result;
}

From source file:org.springframework.batch.item.data.RepositoryItemReader.java

private Object doInvoke(MethodInvoker invoker) throws Exception {
    try {//  w w  w. j  a va2s.  co  m
        invoker.prepare();
    } catch (ClassNotFoundException e) {
        throw new DynamicMethodInvocationException(e);
    } catch (NoSuchMethodException e) {
        throw new DynamicMethodInvocationException(e);
    }

    try {
        return invoker.invoke();
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof Exception) {
            throw (Exception) e.getCause();
        } else {
            throw new InvocationTargetThrowableWrapper(e.getCause());
        }
    } catch (IllegalAccessException e) {
        throw new DynamicMethodInvocationException(e);
    }
}

From source file:com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.java

/**
 * Double check the master secret of an SSL session must not be null, or
 * else a {@link SecurityException} will be thrown.
 * @param sock connected socket/* www.  j ava  2s. c om*/
 */
private void verifyMasterSecret(final Socket sock) {
    if (sock instanceof SSLSocket) {
        SSLSocket ssl = (SSLSocket) sock;
        SSLSession session = ssl.getSession();
        if (session != null) {
            String className = session.getClass().getName();
            if ("sun.security.ssl.SSLSessionImpl".equals(className)) {
                try {
                    Class<?> clazz = Class.forName(className);
                    Method method = clazz.getDeclaredMethod("getMasterSecret");
                    method.setAccessible(true);
                    Object masterSecret = method.invoke(session);
                    if (masterSecret == null) {
                        session.invalidate();
                        if (log.isDebugEnabled()) {
                            log.debug("Invalidated session " + session);
                        }
                        throw log(new SecurityException("Invalid SSL master secret"));
                    }
                } catch (ClassNotFoundException e) {
                    failedToVerifyMasterSecret(e);
                } catch (NoSuchMethodException e) {
                    failedToVerifyMasterSecret(e);
                } catch (IllegalAccessException e) {
                    failedToVerifyMasterSecret(e);
                } catch (InvocationTargetException e) {
                    failedToVerifyMasterSecret(e.getCause());
                }
            }
        }
    }
    return;
}

From source file:ome.services.query.ClassQuerySource.java

@Override
public Query lookup(String queryID, Parameters parameters) {
    Query q = null;/*from ww  w.j  a v a  2  s. c om*/
    Class klass = null;
    try {
        klass = Class.forName(queryID);
    } catch (ClassNotFoundException e) {
        // Not an issue.
    }

    // return null immediately
    if (klass == null) {
        return null;
    }

    // it's a query
    else if (Query.class.isAssignableFrom(klass)) {
        try {
            Constructor c = klass.getConstructor(Parameters.class);
            q = (Query) c.newInstance(parameters);
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Query could not be instanced.", e.getCause());
            }
            throw new RuntimeException("Error while trying to instantiate:" + queryID, e);
        }
        return q;
    }

    // it's an IObject
    else if (IObject.class.isAssignableFrom(klass)) {
        Parameters p = new Parameters(parameters);
        p.addClass(klass);
        return new IObjectClassQuery(p);
    }

    else {
        return null;
    }
}

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;/*from  w  w w.j a va2  s  .co  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;
        }
    }
}