Example usage for java.lang Exception getCause

List of usage examples for java.lang Exception getCause

Introduction

In this page you can find the example usage for java.lang Exception 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:fr.mobilit.neo4j.server.service.nantes.CycleRentTest.java

@BeforeClass
public void setUp() throws Exception {
    super.setUp(true);
    HttpClient client = new HttpClient();
    GetMethod get = null;/*from ww w  .j a  v a 2s .  c o  m*/
    try {
        // we do the http call and parse the xml response
        get = new GetMethod(CycleRentImpl.IMPORT_URL);
        client.executeMethod(get);
        javax.xml.stream.XMLInputFactory factory = javax.xml.stream.XMLInputFactory.newInstance();
        javax.xml.stream.XMLStreamReader parser = factory.createXMLStreamReader(get.getResponseBodyAsStream());
        ArrayList<String> currentXMLTags = new ArrayList<String>();
        int depth = 0;
        while (true) {
            int event = parser.next();
            if (event == javax.xml.stream.XMLStreamConstants.END_DOCUMENT) {
                break;
            }
            switch (event) {
            case javax.xml.stream.XMLStreamConstants.START_ELEMENT:
                currentXMLTags.add(depth, parser.getLocalName());
                String tagPath = currentXMLTags.toString();
                // here we have a match, so we construct the POI
                if (tagPath.equals("[carto, markers, marker]")) {
                    numberOfStations++;
                }
                depth++;
                break;
            case javax.xml.stream.XMLStreamConstants.END_ELEMENT:
                depth--;
                currentXMLTags.remove(depth);
                break;
            default:
                break;
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e.getCause());
    } finally {
        get.releaseConnection();
    }
}

From source file:ca.simplegames.micro.controllers.ControllerManager.java

public void execute(String controllerName, MicroContext context, Map configuration)
        throws ControllerException, ControllerNotFoundException {
    if (StringUtils.isBlank(controllerName)) {
        throw new ControllerNotFoundException("Invalid controller name: " + controllerName);
    }/*from   www. j  a  v  a  2s . c  o  m*/

    final String controllerNotFoundMessage = String.format("%s, not found!", controllerName);
    Controller controller = findController(controllerName);

    if (controller != null) {
        if (controller instanceof ScriptController) {
            controller.execute(context, configuration);
        } else {
            try {
                Class[] paramTypes = { MicroContext.class, Map.class };
                Object[] params = { context, configuration };
                Method method = controller.getClass().getDeclaredMethod(EXECUTE_METHOD, paramTypes);
                // ... Object result =
                method.invoke(controller, params);
            } catch (Exception e) {
                if (e.getCause() instanceof RedirectException) {
                    throw new RedirectException(); // must be a better way :'(
                } else {
                    log.error(String.format("%s, error: %s", controllerName, e.getMessage()));
                    e.printStackTrace();
                    throw new ControllerException(String.format("%s, error: %s", controllerName, e.getCause()));
                }
            }
        }
    } else {
        throw new ControllerException(controllerNotFoundMessage);
    }
}

From source file:com.bradmcevoy.property.BeanPropertySource.java

@Override
public void setProperty(QName name, Object value, Resource r)
        throws NotAuthorizedException, PropertySetException {
    log.debug("setProperty: " + name + " = " + value);
    PropertyDescriptor pd = getPropertyDescriptor(r, name.getLocalPart());
    try {//from   w w w .j  a v  a  2s.c o  m
        pd.getWriteMethod().invoke(r, value);
    } catch (PropertySetException e) {
        throw e;
    } catch (Exception ex) {
        if (ex.getCause() instanceof NotAuthorizedException) {
            NotAuthorizedException na = (NotAuthorizedException) ex.getCause();
            throw na;
        } else if (ex.getCause() instanceof PropertySetException) {
            PropertySetException na = (PropertySetException) ex.getCause();
            throw na;
        } else {
            if (value == null) {
                log.error("Exception setting property: " + name.toString() + " to null");
            } else {
                log.error("Exception setting property: " + name.toString() + " to value: " + value + " class:"
                        + value.getClass());
            }
            throw new RuntimeException(name.toString(), ex);
        }
    }
}

From source file:org.mybatis.spring.config.MapperScannerBeanDefinitionParser.java

/**
 * {@inheritDoc}/*from w w w .j  a  va2s  .  c om*/
 */
@Override
public synchronized BeanDefinition parse(Element element, ParserContext parserContext) {
    ClassPathMapperScanner scanner = new ClassPathMapperScanner(parserContext.getRegistry());
    ClassLoader classLoader = scanner.getResourceLoader().getClassLoader();
    XmlReaderContext readerContext = parserContext.getReaderContext();
    scanner.setResourceLoader(readerContext.getResourceLoader());
    try {
        String annotationClassName = element.getAttribute(ATTRIBUTE_ANNOTATION);
        if (StringUtils.hasText(annotationClassName)) {
            @SuppressWarnings("unchecked")
            Class<? extends Annotation> markerInterface = (Class<? extends Annotation>) classLoader
                    .loadClass(annotationClassName);
            scanner.setAnnotationClass(markerInterface);
        }
        String markerInterfaceClassName = element.getAttribute(ATTRIBUTE_MARKER_INTERFACE);
        if (StringUtils.hasText(markerInterfaceClassName)) {
            Class<?> markerInterface = classLoader.loadClass(markerInterfaceClassName);
            scanner.setMarkerInterface(markerInterface);
        }
        String nameGeneratorClassName = element.getAttribute(ATTRIBUTE_NAME_GENERATOR);
        if (StringUtils.hasText(nameGeneratorClassName)) {
            Class<?> nameGeneratorClass = classLoader.loadClass(nameGeneratorClassName);
            BeanNameGenerator nameGenerator = BeanUtils.instantiateClass(nameGeneratorClass,
                    BeanNameGenerator.class);
            scanner.setBeanNameGenerator(nameGenerator);
        }
    } catch (Exception ex) {
        readerContext.error(ex.getMessage(), readerContext.extractSource(element), ex.getCause());
    }
    String sqlSessionTemplateBeanName = element.getAttribute(ATTRIBUTE_TEMPLATE_REF);
    scanner.setSqlSessionTemplateBeanName(sqlSessionTemplateBeanName);
    String sqlSessionFactoryBeanName = element.getAttribute(ATTRIBUTE_FACTORY_REF);
    scanner.setSqlSessionFactoryBeanName(sqlSessionFactoryBeanName);
    scanner.registerFilters();
    String basePackage = element.getAttribute(ATTRIBUTE_BASE_PACKAGE);
    scanner.scan(StringUtils.tokenizeToStringArray(basePackage,
            ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
    return null;
}

From source file:eu.europa.esig.dss.token.Pkcs12SignatureToken.java

@Override
public List<DSSPrivateKeyEntry> getKeys() throws DSSException {

    List<DSSPrivateKeyEntry> list = new ArrayList<DSSPrivateKeyEntry>();

    InputStream input = null;/* w w w  . j  a  va  2s  .c  o m*/
    try {
        KeyStore keyStore = KeyStore.getInstance("PKCS12");

        if (pkcs12Data != null) {
            input = new ByteArrayInputStream(pkcs12Data);
        } else {
            input = new FileInputStream(pkcs12File);
        }

        keyStore.load(input, password);
        PasswordProtection pp = new KeyStore.PasswordProtection(password);
        Enumeration<String> aliases = keyStore.aliases();
        while (aliases.hasMoreElements()) {

            String alias = aliases.nextElement();
            if (keyStore.isKeyEntry(alias)) {

                PrivateKeyEntry entry = (PrivateKeyEntry) keyStore.getEntry(alias, pp);
                final KSPrivateKeyEntry privateKeyEntry = new KSPrivateKeyEntry(entry);
                list.add(privateKeyEntry);
            }
        }
    } catch (Exception e) {
        if (e.getCause() instanceof BadPaddingException) {
            throw new DSSBadPasswordException(MSG.PKCS12_BAD_PASSWORD);
        }
        throw new DSSException("Can't initialize Sun PKCS#12 security provider. Reason: " + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(input);
    }
    return list;
}

From source file:com.proofpoint.event.client.EventFieldMetadata.java

private Object getValue(Object event) throws InvalidEventException {
    try {//from  w w w  . ja  v  a  2  s . c o  m
        return method.invoke(event);
    } catch (Exception e) {
        throw new InvalidEventException(firstNonNull(e.getCause(), e),
                "Unable to get value of event field %s: Exception occurred while invoking [%s]", name,
                method.toGenericString());
    }
}

From source file:com.nandhootoo.services.DepartmentServiceImpl.java

public void persist(Department department) {
    EntityTransaction tx = null;/*  w w w .ja  v a2 s.c o  m*/
    try {
        entityManager.persist(department);
    } catch (Exception ex) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw (RuntimeException) ex.getCause();
    }
}

From source file:com.nandhootoo.services.DepartmentServiceImpl.java

public void merge(Department department) {
    EntityTransaction tx = null;/* w w w  . j  a  v  a 2 s. c  om*/
    try {
        entityManager.merge(department);
    } catch (Exception ex) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw (RuntimeException) ex.getCause();
    }
}

From source file:com.nandhootoo.services.IssueServiceImpl.java

public void persist(Issue issue) {
    EntityTransaction tx = null;/* w w  w. ja v  a 2 s  .com*/
    try {
        entityManager.persist(issue);
    } catch (Exception ex) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw (RuntimeException) ex.getCause();
    }
}

From source file:com.nandhootoo.services.IssueServiceImpl.java

public void merge(Issue issue) {
    EntityTransaction tx = null;/*from  w  ww  .ja v a 2  s  .  c  om*/
    try {
        entityManager.merge(issue);
    } catch (Exception ex) {
        if (tx != null && tx.isActive())
            tx.rollback();
        throw (RuntimeException) ex.getCause();
    }
}