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:com.ixora.rms.ui.RMSFrame.java

/**
 * Display the main window of the application to the user.
 * @throws FailedToSaveConfiguration//from w  w w . j av  a 2s  .c  o m
 * @throws SocketException
 * @throws RMSException
 */
private static void initApplication() throws SocketException, FailedToSaveConfiguration, RMSException {
    // first thing to do:
    // initialize the message repository, set the default
    // repository to the repository for the main application component
    MessageRepository.initialize(RMSComponent.NAME);

    // assign a public IP address for the console to use
    String currentConsoleIpAddress = ConfigurationMgr.getString(RMSComponent.NAME,
            RMSConfigurationConstants.NETWORK_ADDRESS);
    if (Utils.isEmptyString(currentConsoleIpAddress)) {
        // tell RMI to use the fully qualified name for this host
        // for object references
        System.setProperty("java.rmi.server.useLocalHostname", "true");
    } else {
        System.setProperty("java.rmi.server.hostname", currentConsoleIpAddress);
    }

    // register deployment modules with the update manager
    UpdateMgr.registerModule(new IxoraCommonModule());
    UpdateMgr.registerModule(new RMSModule());
    UpdateMgr.registerNodeModule(new IxoraCommonModule());
    UpdateMgr.registerNodeModule(new RMSModule());

    // ConfigurationMgr.makeConfigurationEditable(PreferencesConfigurationConstants.PREFERENCES);
    ConfigurationMgr.makeConfigurationEditable(RMSComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(DataViewBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(ChartsBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(TablesBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(PropertiesBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(LogBoardComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(LogComponent.NAME);
    //      ConfigurationMgr.makeConfigurationEditable(LogComponentDB.NAME);
    // ConfigurationMgr.makeConfigurationEditable(LogComponentXML.NAME);
    ConfigurationMgr.makeConfigurationEditable(MonitoringSessionRepositoryComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(JobsComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(ReactionsComponent.NAME);
    ConfigurationMgr.makeConfigurationEditable(ReactionsEmailComponent.NAME);
    // ConfigurationMgr.makeConfigurationEditable(UpdateComponent.NAME);

    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new java.rmi.RMISecurityManager());
    }

    try {
        // initialize RMS
        RMS.initialize();
    } catch (Exception e) {
        // this could happen if a special IP address has been assigned to
        // the console has changed since last time the app was started
        if (e.getCause() instanceof ExportException || Utils.getTrace(e).toString().contains("Port")) {
            logger.error("Ignoring the ip address assigned to the console " + currentConsoleIpAddress
                    + " as it seems to be invalid.");
            resetConsoleIpAddress();
            // try again
            RMS.initialize();
        } else {
            throw new AppRuntimeException(e);
        }
    }

    // do a quick ping to website to check for updates
    UpdateMgr.checkForUpdates();

    // build the GUI on the event dispatch thread
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                // install UI factory in the commons library
                UIFactoryMgr.installUIFactory(new RMSUIFactory());
                // JDialog.setDefaultLookAndFeelDecorated(true);
                // JFrame.setDefaultLookAndFeelDecorated(true);
                // Toolkit.getDefaultToolkit().setDynamicLayout(true);
                Toolkit.getDefaultToolkit().setDynamicLayout(false);
                AppFrameParameters params = new AppFrameParameters();
                params.setString(AppFrameParameters.LOOK_AND_FEEL_CLASS,
                        "javax.swing.plaf.metal.MetalLookAndFeel");
                //"com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
                params.setString(AppFrameParameters.FEEDBACK_URL,
                        "http://spreadsheets.google.com/formResponse");
                JFrame frame = new RMSFrame(params);
                UIUtils.maximizeFrameAndShow(frame);
            } catch (Throwable e) {
                logger.error(e);
                System.exit(1);
            }
        }
    });
}

From source file:hu.bme.mit.sette.common.model.snippet.SnippetContainer.java

/**
 * Validates the constructor of the class.
 *
 * @param validator/* w w  w.  j a  va2 s .co m*/
 *            a validator
 */
private void validateConstructor(final AbstractValidator<?> validator) {
    if (javaClass.getDeclaredConstructors().length != 1) {
        // constructor count is validated with the class
        return;
    }

    Constructor<?> constructor = javaClass.getDeclaredConstructors()[0];
    ConstructorValidator v = new ConstructorValidator(constructor);
    v.withModifiers(Modifier.PRIVATE).parameterCount(0);
    v.synthetic(false);

    // check: constructor throws new
    // UnsupportedOperationException("Static class")

    Throwable exception = null;
    try {
        // call the private ctor
        constructor.setAccessible(true);
        constructor.newInstance();
    } catch (Exception e) {
        exception = e.getCause();
    } finally {
        // restore visibility
        constructor.setAccessible(false);
    }

    if (exception == null || !exception.getClass().equals(UnsupportedOperationException.class)
            || !exception.getMessage().equals("Static class")) {
        v.addException("The constructor must throw an " + "UnsupportedOperationException with "
                + "the message \"Static class\"");
    }

    validator.addChildIfInvalid(v);
}

From source file:com.flipkart.phantom.runtime.impl.spring.web.HandlerConfigController.java

@RequestMapping(value = { "/reInit/**" }, method = RequestMethod.GET)
public String reInitHandler(ModelMap model, HttpServletRequest request,
        @ModelAttribute("handlerName") String handlerName) {
    String message;/*from  w  w w  .j a  va2s  .co m*/
    try {
        this.configService.reinitHandler(handlerName);
        message = "Successfully reinitialized handler " + handlerName;
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        message = "Error while reinitializing handler: \n";
        message += sw.toString() + "\n";
        if (e.getCause() != null) {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            e.getCause().printStackTrace(pw);
            message += "Caused by: ";
            message += sw.toString() + "\n";
        }
        LOGGER.error("Error reinitializing handler " + handlerName, e);
    }
    model.addAttribute("message", message);
    return "message";
}

From source file:com.krawler.notify.email.SimpleEmailSender.java

private String captureMessage(Exception e) {
    String msg = e.getMessage();//w  w w  . j a v  a  2s .  c o  m
    if (msg == null && e instanceof MessagingException) {
        Exception ne = ((MessagingException) e).getNextException();
        if (ne != null)
            msg = ne.getMessage();
    }
    if (msg == null && e.getCause() != null) {
        msg = e.getCause().getMessage();
    }
    if (msg == null) {
        msg = "Could not connect to mail server because of inappropriate information.";
    }
    return msg;
}

From source file:com.github.tomakehurst.wiremock.StubbingAcceptanceTest.java

private void getAndAssertUnderlyingExceptionInstanceClass(String url, Class<?> expectedClass) {
    boolean thrown = false;
    try {/*from   w  w w  .  j  ava  2  s . co  m*/
        WireMockResponse response = testClient.get(url);
        response.content();
    } catch (Exception e) {
        assertThat(e.getCause(), instanceOf(expectedClass));
        thrown = true;
    }

    assertTrue("No exception was thrown", thrown);
}

From source file:com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImplTest.java

/**
 * Test method for//from  w w w  .  ja v a 2s  . c  om
 * {@link com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl#getQueryResponse(java.lang.String)}
 * .
 */
@Ignore
@Test
public void testGetQueryResponse() {
    logger.debug("RUNNING TEST FOR BASIC QUERY RESPONSE");
    jiraDataFactory = new JiraDataFactoryImpl(properties.getProperty("jira.credentials"),
            properties.getProperty("jira.base.url"), properties.getProperty("jira.query.endpoint"));
    jiraDataFactory.buildBasicQuery(query);
    try {
        JSONArray rs = jiraDataFactory.getQueryResponse();

        /*
         * Testing actual JSON for values
         */
        JSONArray dataMainArry = new JSONArray();
        JSONObject dataMainObj = new JSONObject();
        dataMainArry = (JSONArray) rs.get(0);
        dataMainObj = (JSONObject) dataMainArry.get(0);

        logger.info("Basic query response: " + dataMainObj.get("fields").toString());
        // fields
        assertTrue("No valid Number was found", dataMainObj.get("fields").toString().length() >= 1);
    } catch (NullPointerException npe) {
        fail("There was a problem with an object used to connect to Jira during the test\n" + npe.getMessage()
                + " caused by: " + npe.getCause());
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        fail("The object returned from Jira had no JSONObjects in it during the test; try increasing the scope of your test case query and try again\n"
                + aioobe.getMessage() + " caused by: " + aioobe.getCause());
    } catch (IndexOutOfBoundsException ioobe) {
        logger.info("JSON artifact may be empty - re-running test to prove this out...");
        JSONArray rs = jiraDataFactory.getQueryResponse();

        /*
         * Testing actual JSON for values
         */
        String strRs = new String();
        strRs = rs.toString();

        logger.info("Basic query response: " + strRs);
        assertEquals("There was nothing returned from Jira that is consistent with a valid response.", "[[]]",
                strRs);
    } catch (Exception e) {
        fail("There was an unexpected problem while connecting to Jira during the test\n" + e.getMessage()
                + " caused by: " + e.getCause());
    }
}

From source file:com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImplTest.java

/**
 * Test method for/* w w  w.  j  ava2s  .c om*/
 * {@link com.capitalone.dashboard.datafactory.jira.JiraDataFactoryImpl#getPagingQueryResponse()}
 * .
 */
@Ignore
@Test
public void testGetPagingQueryResponse() {
    logger.debug("RUNNING TEST FOR PAGING QUERY RESPONSE");
    jiraDataFactory = new JiraDataFactoryImpl(1, properties.getProperty("jira.credentials"),
            properties.getProperty("jira.base.url"), properties.getProperty("jira.query.endpoint"));
    jiraDataFactory.buildBasicQuery(query);
    jiraDataFactory.buildPagingQuery(0);
    try {
        JSONArray rs = jiraDataFactory.getPagingQueryResponse();

        /*
         * Testing actual JSON for values
         */
        JSONArray dataMainArry = new JSONArray();
        JSONObject dataMainObj = new JSONObject();
        dataMainArry = (JSONArray) rs.get(0);
        dataMainObj = (JSONObject) dataMainArry.get(0);

        logger.info("Paging query response: " + dataMainObj.get("fields").toString());
        // fields
        assertTrue("No valid Number was found", dataMainObj.get("fields").toString().length() >= 1);
    } catch (NullPointerException npe) {
        fail("There was a problem with an object used to connect to Jira during the test:\n" + npe.getMessage()
                + " caused by: " + npe.getCause());
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        fail("The object returned from Jira had no JSONObjects in it during the test; try increasing the scope of your test case query and try again.\n"
                + aioobe.getMessage() + " caused by: " + aioobe.getCause());
    } catch (IndexOutOfBoundsException ioobe) {
        logger.info("JSON artifact may be empty - re-running test to prove this out...");

        JSONArray rs = jiraDataFactory.getPagingQueryResponse();

        /*
         * Testing actual JSON for values
         */
        String strRs = new String();
        strRs = rs.toString();

        logger.info("Paging query response: " + strRs);
        assertEquals("There was nothing returned from Jira that is consistent with a valid response.", "[[]]",
                strRs);
    } catch (Exception e) {
        fail("There was an unexpected problem while connecting to Jira during the test:\n" + e.getMessage()
                + " caused by: " + e.getCause());
    }
}

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

@Test
public void shouldPropagateConfigHasChangedException() throws Exception {
    String originalMd5 = dataSource.forceLoad(dataSource.fileLocation()).configForEdit.getMd5();
    goConfigFileDao.updateConfig(configHelper.addPipelineCommand(originalMd5, "p1", "s1", "b1"));
    GoConfigHolder goConfigHolder = dataSource.forceLoad(dataSource.fileLocation());

    try {//from w  ww .ja v a2  s . c o m
        dataSource.writeWithLock(configHelper.addPipelineCommand(originalMd5, "p2", "s", "b"), goConfigHolder);
        fail("Should throw ConfigFileHasChanged exception");
    } catch (Exception e) {
        assertThat(e.getCause().getClass().getName(), e.getCause() instanceof ConfigMergeException, is(true));
    }
}

From source file:org.malaguna.cmdit.bbeans.AbstractBean.java

/**
 * It runs a command safely and catching all error info. If commands fail, 
 * it will show error info standard way.
 * //  ww w .  j av  a2 s. c o m
 * @param cmd
 * @return
 */
@Override
protected Command runCommand(Command cmd) {
    cmd.setLocale(getLocale());
    cmd.setUser(getAuthUserFromSession());

    try {
        cmd = super.runCommand(cmd);
        if ((cmd != null) && (cmd.getUserComment() != null)) {
            setInfoMessage("Command Info:", cmd.getUserComment());
        }
    } catch (Exception e) {
        Throwable ce = (e.getCause() != null) ? e.getCause() : e;

        String aux = getMessage(ce.getClass().getName(), getLocale());
        String errMsg = null;

        if (aux != null)
            errMsg = String.format("%s: %s", aux, ce.getLocalizedMessage());
        else
            errMsg = ce.getLocalizedMessage();

        setErrorMessage("Command Error:", errMsg);
        cmd = null;
    }

    return cmd;
}

From source file:es.uah.cc.ie.utils.DrushUpdater.java

/**
 * DRY method that converts an AGRISAP / DC object to a serialized Base64
 * JSON//from  w w w .j  a va  2  s . com
 *
 * @param object
 */
private void packObjectHelper(Object object, int objectType) {

    final GsonBuilder builder = new GsonBuilder();
    final Gson gson = builder.create();
    /*
     * test.setWidth(10); test.setHeight(20); test.setDepth(30);
     */
    String json = null;

    try {
        json = gson.toJson(object);
        this.test_passed++;
    } catch (Exception e) {
        test_errors++;
        System.out.println("oops!" + e.getCause());
        // log4j
        // log.error("oops!", e.getCause());
    }

    // final String json = gson.toJson(test);
    // System.out.printf("Serialised: %s%n", json);

    if (this.RUN_TESTS) {
        try {
            assertNotNull("Failed creating serialized JSON", json);
            this.test_passed++;
        } catch (Exception e) {
            test_errors++;
            System.out.println("oops!" + e.getCause());
            // log4j
            // log.error("oops!", e.getCause());
        }
    }

    /*
     * final Test otherBox = gson.fromJson(json, Test.class);
     * System.out.printf("Same test: %s%n", test.equals(otherBox));
     */
    String encoded = null;
    try {
        encoded = encode(json);
        this.test_passed++;
    } catch (Exception e) {
        test_errors++;
        System.out.println("oops!" + e.getCause());
        // log4j
        // log.error("oops!", e.getCause());
    }

    if (this.RUN_TESTS) {
        try {
            assertNotNull("Failed Base64 encoding", encoded);
            this.test_passed++;
        } catch (Exception e) {
            test_errors++;
            System.out.println("oops!" + e.getCause());
            // log4j
            // log.error("oops!", e.getCause());
        }
    }
    String decoded = null;
    if (this.RUN_TESTS) {
        try {
            decoded = decode(encoded);
            this.test_passed++;
        } catch (Exception e) {
            test_errors++;
            System.out.println("oops!" + e.getCause());
            // log4j
            // log.error("oops!", e.getCause());
        }
    }
    if (this.RUN_TESTS) {
        try {
            assertNotNull("Failed Base64 decoding", decoded);
            this.test_passed++;
        } catch (Exception e) {
            test_errors++;
            System.out.println("oops!" + e.getCause());
            // log4j
            // log.error("oops!", e.getCause());
        }
    }
    if (this.RUN_TESTS) {
        try {
            assertEquals("Failed Base64 encoding<->decoding", json, decoded);
            this.test_passed++;
        } catch (Exception e) {
            test_errors++;
            System.out.println("oops!" + e.getCause());
            // log4j
            // log.error("oops!", e.getCause());

        }
    }

    // System.out.println("encoded: " + encoded);
    // System.out.println("decoded: " + decoded);

    boolean execution_error = false;
    try {
        // .exec() for GUN/Linux
        // TODO: get --root param from opts.xml
        Process p = null;
        if (objectType == AGRISAP) {
            p = Runtime.getRuntime().exec("drush agup --root=" + DRUPAL_ROOT_DIR + " --data=" + encoded);
        } else {
            p = Runtime.getRuntime().exec("drush dcup --root=" + DRUPAL_ROOT_DIR + " --data=" + encoded);
        }
        // comment out for greater performance
        // get stream
        InputStream is = p.getInputStream();

        // comment out for greater performance
        // prepare bufferedReader to parse result
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        // comment out for greater performance
        // get line
        String aux = br.readLine();

        // comment out for greater performance
        while (aux != null) {
            // printf

            // FIELD VALUE ************
            // System.out.println(aux);

            // loop
            aux = br.readLine();
        }
    } catch (Exception e) {
        // catch exceptions
        // replace for System.out.print/logging for greater performance
        // e.printStackTrace();
        // TODO: do some logging
        execution_error = true;
        System.out.println("oops!" + e.getCause());
        // log4j
        // log.error("oops!", e.getCause());

    }
    if (this.RUN_TESTS) {
        try {
            assertFalse("Failed execution", execution_error);
            this.test_passed++;
        } catch (Exception e) {
            test_errors++;
            System.out.println("oops!" + e.getCause());
            // log4j
            // log.error("oops!", e.getCause());
        }
    }
    testReport();
}