Example usage for java.lang RuntimeException getCause

List of usage examples for java.lang RuntimeException getCause

Introduction

In this page you can find the example usage for java.lang RuntimeException 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.jbosson.plugins.amq.ArtemisServerDiscoveryComponent.java

protected DiscoveredResourceDetails discoverResourceDetails(ResourceDiscoveryContext context,
        ProcessInfo process) {/*ww w  .  ja  v  a  2  s .  c o m*/

    Configuration pluginConfig;

    // Start up a JMX agent within the JVM via the Sun Attach API, and return a URL that can be used to connect
    // to that agent.
    // Note, this will only work if the remote JVM is Java 6 or later, and maybe some 64 bit Java 5 - see
    // JBNADM-3332. Also, the RHQ Agent will have to be running on a JDK, not a JRE, so that we can access
    // the JDK's tools.jar, which contains the Sun JVM Attach API classes.
    JMXServiceURL jmxServiceURL;
    try {
        jmxServiceURL = JvmUtility.extractJMXServiceURL(process);
    } catch (RuntimeException e) {
        // avoid loading AttachNotSupportedException class, since its optional
        if (e.getCause() != null
                && e.getCause().getClass().getName().equals(ATTACH_NOT_SUPPORTED_EXCEPTION_CLASS_NAME)) {
            // try connecting using jvmstat
            jmxServiceURL = JvmStatUtility.extractJMXServiceURL(process);
        } else {
            // re-throw
            throw e;
        }
    }
    if (jmxServiceURL != null) {
        pluginConfig = context.getDefaultPluginConfiguration();
        // do not use the default connector address, principal or credentials
        pluginConfig.setSimpleValue(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY, null);
        pluginConfig.setSimpleValue(JMXComponent.PRINCIPAL_CONFIG_PROP, null);
        pluginConfig.setSimpleValue(JMXComponent.CREDENTIALS_CONFIG_PROP, null);
    } else {
        // create plugin config with JMX connection properties
        pluginConfig = getConfigWithJmxServiceUrl(context, process);
    }

    // log the JMX URL being used
    if (log.isDebugEnabled()) {
        log.debug("JMX service URL for java process [" + process + "] is ["
                + (jmxServiceURL != null ? jmxServiceURL
                        : pluginConfig.getSimpleValue(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY))
                + "].");
    }

    return buildResourceDetails(pluginConfig, context, process,
            pluginConfig.getSimpleValue(JMXDiscoveryComponent.CONNECTOR_ADDRESS_CONFIG_PROPERTY));
}

From source file:com.thoughtworks.go.config.GoFileConfigDataSourceIntegrationTest.java

@Test
public void shouldThrowConfigMergeExceptionWhenConfigMergeFeatureIsTurnedOff() throws Exception {
    String firstMd5 = dataSource.forceLoad(dataSource.fileLocation()).configForEdit.getMd5();
    goConfigDao.updateConfig(configHelper.addPipelineCommand(firstMd5, "p0", "s0", "b0"));
    String originalMd5 = dataSource.forceLoad(dataSource.fileLocation()).configForEdit.getMd5();
    goConfigDao.updateConfig(configHelper.addPipelineCommand(originalMd5, "p1", "s1", "j1"));
    GoConfigHolder goConfigHolder = dataSource.forceLoad(dataSource.fileLocation());

    systemEnvironment.set(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE, Boolean.FALSE);

    try {/*from w ww  . ja  v  a 2  s.com*/
        dataSource.writeWithLock(configHelper.changeJobNameCommand(originalMd5, "p0", "s0", "b0", "j0"),
                goConfigHolder);
        fail("Should throw ConfigMergeException");
    } catch (RuntimeException e) {
        ConfigMergeException cme = (ConfigMergeException) e.getCause();
        assertThat(cme.getMessage(), is(ConfigFileHasChangedException.CONFIG_CHANGED_PLEASE_REFRESH));
    }
}

From source file:org.wso2.carbon.governance.registry.extensions.handlers.utils.SchemaUriProcessor.java

public String importSchemaToRegistry(RequestContext requestContext, String resourcePath, String commonLocation,
        String sourceURL) throws RegistryException {
    resourceName = resourcePath.substring(resourcePath.lastIndexOf(RegistryConstants.PATH_SEPARATOR) + 1);

    XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
    xmlSchemaCollection.setBaseUri(sourceURL);
    baseURI = sourceURL;/* ww  w .ja v  a2s .  com*/
    InputSource inputSource = new InputSource(sourceURL);

    try {
        // Here we assue schema is correct. Schema validation is beyond our scope, so we don't
        // bother with a ValidationEventHandler.
        XmlSchema xmlSchema = xmlSchemaCollection.read(inputSource, null);
        evaluateSchemasRecursively(xmlSchema, null, false, true);
    } catch (RuntimeException re) {
        String msg = "Could not read the XML Schema Definition file. ";
        if (re.getCause() instanceof org.apache.ws.commons.schema.XmlSchemaException) {
            msg += re.getCause().getMessage();
            log.error(msg, re);
            throw new RegistryException(msg);
        }
        throw new RegistryException(msg, re);
    }
    updateSchemaPaths(commonLocation);

    updateSchemaInternalsAndAssociations();

    Resource metaResource = requestContext.getResource();
    String path = saveSchemaToRegistry(resourcePath, metaResource); // should depend on the central location / relative location flag
    persistAssociations(path);
    return path;
}

From source file:org.apache.tinkerpop.gremlin.server.GremlinServerIntegrateTest.java

@Test
public void shouldFailOnDeadHost() throws Exception {
    final Cluster cluster = Cluster.build("localhost").create();
    final Client client = cluster.connect();

    // ensure that connection to server is good
    assertEquals(2, client.submit("1+1").all().join().get(0).getInt());

    // kill the server which will make the client mark the host as unavailable
    this.stopServer();

    try {/*www. j  a v a 2 s.  c  o m*/
        // try to re-issue a request now that the server is down
        client.submit("1+1").all().join();
        fail();
    } catch (RuntimeException re) {
        assertTrue(re.getCause().getCause() instanceof ClosedChannelException);

        //
        // should recover when the server comes back
        //

        // restart server
        this.startServer();
        // the retry interval is 1 second, wait a bit longer
        TimeUnit.SECONDS.sleep(5);

        List<Result> results = client.submit("1+1").all().join();
        assertEquals(1, results.size());
        assertEquals(2, results.get(0).getInt());

    } finally {
        cluster.close();
    }
}

From source file:com.fujitsu.dc.core.model.impl.es.CellEsImpl.java

@Override
public Box getBoxForName(String boxName) {
    if (Box.DEFAULT_BOX_NAME.equals(boxName)) {
        return new Box(this, null);
    }/* ww w.j  a va 2 s .co  m*/

    // URl???Box????????Box??????null??
    if (!validatePropertyRegEx(boxName, Common.PATTERN_NAME)) {
        return null;
    }
    // ??Box???
    Box cachedBox = BoxCache.get(boxName, this);
    if (cachedBox != null) {
        return cachedBox;
    }

    Box loadedBox = null;
    try {
        ODataProducer op = ModelFactory.ODataCtl.cellCtl(this);
        EntityResponse er = op.getEntity("Box", OEntityKey.create(boxName), null);
        loadedBox = new Box(this, er.getEntity());
        BoxCache.cache(loadedBox);
        return loadedBox;
    } catch (RuntimeException e) {
        if (e.getCause() instanceof CheckedOperationTimeoutException) {
            return loadedBox;
        } else {
            return null;
        }
    }
}

From source file:org.linqs.psl.parser.ModelLoaderTest.java

@Test
public void testArithmeticDivideByZero() {
    String[] input = new String[] { "Single(A) / 0 + Single(B) = 0.0 .",
            "2 / 0 * Single(A) + Single(B) = 0.0 .", "2 / (2 - 2) * Single(A) + Single(B) = 0.0 .",
            "Single(A) / (-1 + 1) + Single(B) = 0.0 .", "Single(A) / @Min[0, 1] + Single(B) = 0.0 ." };

    for (String rule : input) {
        try {//from   www. j  a  va 2 s .  c  o  m
            PSLTest.assertRule(dataStore, rule, "");
            fail("Divide by zero did not throw exception.");
        } catch (RuntimeException ex) {
            if (!(ex.getCause() instanceof ArithmeticException)) {
                fail("Divide by zero threw a non-Arithmetic exception: " + ex.getCause() + ".");
            }
        }
    }
}

From source file:ome.services.RawPixelsBean.java

@RolesAllowed("user")
@Transactional(readOnly = false)//from w ww.j a  v a2s .co m
public synchronized Pixels save() {
    if (isModified()) {
        Long id = (pixelsInstance == null) ? null : pixelsInstance.getId();
        if (id == null) {
            return null;
        }

        try {
            byte[] hash = buffer.calculateMessageDigest();
            pixelsInstance.setSha1(Utils.bytesToHex(hash));

        } catch (RuntimeException re) {
            // ticket:3140
            if (re.getCause() instanceof FileNotFoundException) {
                String msg = "Cannot find path. Deleted? " + buffer;
                log.warn(msg);
                clean(); // Prevent a second exception on close.
                throw new ResourceError(msg);
            }
            throw re;
        } catch (IOException e) {
            log.warn("calculateMessageDigest failed on " + buffer, e);
            throw new ResourceError(e.getMessage());
        }

        iUpdate.flush();
        modified = false;
        return new ShallowCopy().copy(pixelsInstance);
    }
    return null;
}

From source file:org.jahia.services.content.files.FileServlet.java

protected JCRNodeWrapper getNode(FileKey fileKey) {
    JCRNodeWrapper n = null;//from   w  w w .  java  2 s.co  m
    JCRSessionWrapper session = null;
    try {
        session = JCRSessionFactory.getInstance().getCurrentUserSession(fileKey.getWorkspace());

        if (fileKey.getVersionDate() != null) {
            session.setVersionDate(new Date(Long.valueOf(fileKey.getVersionDate())));
        }
        if (fileKey.getVersionLabel() != null) {
            session.setVersionLabel(fileKey.getVersionLabel());
        }

        n = session.getNode(fileKey.getPath());

        if (!isValid(n)) {
            n = null;
        }
    } catch (RuntimeException e) {
        // throw by the session.setVersionLabel()
        logger.debug(e.getMessage(), e);
    } catch (PathNotFoundException e) {
        logger.debug(e.getMessage(), e);
    } catch (RepositoryException e) {
        if (e.getCause() != null && e.getCause() instanceof MalformedPathException) {
            logger.debug(e.getMessage(), e);
        } else {
            logger.error("Error accesing path: " + fileKey.getPath() + " for user "
                    + (session != null ? session.getUserID() : null), e);
        }
    }
    return n;
}

From source file:org.alfresco.web.app.servlet.ajax.AjaxServlet.java

/**
 * Handles any error that occurs during the execution of the servlet
 * //from  www .  j ava  2  s .c  om
 * @param response The response
 * @param cause The cause of the error
 */
protected void handleError(HttpServletResponse response, RuntimeException cause)
        throws ServletException, IOException {
    // if we can send back the 500 error with the error from the top of the 
    // stack as the error status message.

    // NOTE: if we use the built in support for generating error pages for
    //       500 errors we can tailor the output for AJAX calls so that the
    //       body of the response can be used to show the error details.

    if (!response.isCommitted()) {
        // dump the error if debugging is enabled
        if (logger.isDebugEnabled()) {
            logger.error(cause);
            Throwable theCause = cause.getCause();
            if (theCause != null) {
                logger.error("caused by: ", theCause);
            }
        }

        // extract a message from the exception
        String msg = cause.getMessage();
        if (msg == null) {
            msg = cause.toString();
        }
        // ALF-9036. We need to trap incomplete sessions
        if (cause instanceof IllegalStateException) {
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, cause.getMessage());
        } else {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
        }
    } else {
        // the response has already been comitted, not much we can do but
        // let the error through and let the container deal with it
        throw cause;
    }
}

From source file:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java

@Override
public VerifyResult verify(final SOAPMessage message) {
    try {/*  www .  j  a v a2 s.c  o  m*/
        return verifyMessage(message);
    } catch (final RuntimeException e) {
        throw e;
    } catch (final Exception e) {
        final Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        }
        throw new RuntimeException(e);
    }
}