Example usage for java.lang Throwable toString

List of usage examples for java.lang Throwable toString

Introduction

In this page you can find the example usage for java.lang Throwable toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.ctrip.infosec.rule.executor.ModelRulesExecutorService.java

/**
 * /*from www .j a v a  2 s .  c  om*/
 */
public void execute(RiskFact fact) {

    // matchRules      
    List<ModelRule> matchedRules = Configs.matchModelRules(fact);
    List<String> scriptRulePackageNames = Collections3.extractToList(matchedRules, "ruleNo");
    logger.debug(
            Contexts.getLogPrefix() + "matched model rules: " + StringUtils.join(scriptRulePackageNames, ", "));
    TraceLogger.traceLog("? " + matchedRules.size() + " ? ...");

    StatelessModelRuleEngine statelessModelRuleEngine = SpringContextHolder
            .getBean(StatelessModelRuleEngine.class);
    for (ModelRule rule : matchedRules) {
        RuleMonitorHelper.newTrans(fact, RuleMonitorType.MODEL_RULE, rule.getRuleNo());
        TraceLogger.beginNestedTrans(fact.eventId);
        TraceLogger.setNestedLogPrefix("[" + rule.getRuleNo() + "]");
        Contexts.setPolicyOrRuleNo(rule.getRuleNo());
        try {
            long start = System.currentTimeMillis();

            // add current execute ruleNo and logPrefix before execution
            fact.ext.put(Constants.key_ruleNo, rule.getRuleNo());
            fact.ext.put(Constants.key_isAsync, true);

            statelessModelRuleEngine.execute(rule.getRuleNo(), fact);

            // remove current execute ruleNo when finished execution.
            fact.ext.remove(Constants.key_ruleNo);
            fact.ext.remove(Constants.key_isAsync);

            long handlingTime = System.currentTimeMillis() - start;
            if (handlingTime > 100) {
                logger.info(Contexts.getLogPrefix() + "modelRule: " + rule.getRuleNo() + ", usage: "
                        + handlingTime + "ms");
            }

            Map<String, Object> result = fact.modelResults.get(rule.getRuleNo());
            if (result != null) {
                int riskLevel = MapUtils.getIntValue(result, Constants.riskLevel, 0);
                if (riskLevel > 0) {
                    TraceLogger.traceLog(">>>> [" + rule.getRuleNo() + "] : [] riskLevel = "
                            + result.get(Constants.riskLevel) + ", riskMessage = "
                            + result.get(Constants.riskMessage) + ", usage = " + result.get(Constants.timeUsage)
                            + "ms");
                }
            }

        } catch (Throwable ex) {
            logger.warn(Contexts.getLogPrefix() + ". modelRule: " + rule.getRuleNo(),
                    ex);
            TraceLogger.traceLog("[" + rule.getRuleNo() + "] EXCEPTION: " + ex.toString());
        } finally {
            TraceLogger.commitNestedTrans();
            RuleMonitorHelper.commitTrans(fact);
            Contexts.clearLogPrefix();
        }
    }

}

From source file:de.jackwhite20.japs.server.network.Connection.java

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {

    ChannelUtil.closeOnFlush(channel);/*from w w w  .  j  ava2  s  .  c o m*/

    if (!(cause instanceof IOException)) {
        cause.printStackTrace();

        LOGGER.log(Level.SEVERE, "Error: " + cause.toString());
    }
}

From source file:com.haulmont.cuba.security.app.LoginServiceBean.java

@Override
public UserSession getSystemSession(String trustedClientPassword) throws LoginException {
    try {/*from w  w w. jav  a  2  s . c  o  m*/
        return trustedClientService.getSystemSession(trustedClientPassword);
    } catch (LoginException e) {
        log.info("Login failed: {}", e.toString());
        throw e;
    } catch (Throwable e) {
        log.error("Login error", e);
        //noinspection ThrowableResultOfMethodCallIgnored
        Throwable rootCause = ExceptionUtils.getRootCause(e);
        if (rootCause == null)
            rootCause = e;
        // send text only to avoid ClassNotFoundException when the client has no dependency to some library
        throw new LoginException(rootCause.toString());
    }
}

From source file:com.vmware.photon.controller.api.client.resource.FlavorApiTest.java

@Test
public void testListAllAsync() throws Exception {
    Flavor flavor1 = new Flavor();
    flavor1.setId("flavor1");
    flavor1.setKind("vm");

    Flavor flavor2 = new Flavor();
    flavor2.setId("flavor2");
    flavor2.setKind("vm");

    final ResourceList<Flavor> flavorResourceList = new ResourceList<>(Arrays.asList(flavor1, flavor2));

    ObjectMapper mapper = new ObjectMapper();
    String serializedResponse = mapper.writeValueAsString(flavorResourceList);

    setupMocks(serializedResponse, HttpStatus.SC_OK);

    FlavorApi flavorApi = new FlavorApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    flavorApi.listAllAsync(new FutureCallback<ResourceList<Flavor>>() {
        @Override/*from   w  w w .j av  a2  s.c om*/
        public void onSuccess(@Nullable ResourceList<Flavor> result) {
            assertEquals(result.getItems(), flavorResourceList.getItems());
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.api.client.resource.FlavorRestApiTest.java

@Test
public void testListAllAsync() throws Exception {
    Flavor flavor1 = new Flavor();
    flavor1.setId("flavor1");
    flavor1.setKind("vm");

    Flavor flavor2 = new Flavor();
    flavor2.setId("flavor2");
    flavor2.setKind("vm");

    final ResourceList<Flavor> flavorResourceList = new ResourceList<>(Arrays.asList(flavor1, flavor2));

    ObjectMapper mapper = new ObjectMapper();
    String serializedResponse = mapper.writeValueAsString(flavorResourceList);

    setupMocks(serializedResponse, HttpStatus.SC_OK);

    FlavorApi flavorApi = new FlavorRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    flavorApi.listAllAsync(new FutureCallback<ResourceList<Flavor>>() {
        @Override//from   w  ww  . j a  va  2 s  . co  m
        public void onSuccess(@Nullable ResourceList<Flavor> result) {
            assertEquals(result.getItems(), flavorResourceList.getItems());
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.googlecode.flyway.ant.AbstractFlywayTask.java

@Override
public void execute() throws BuildException {
    AntLogAppender.startTaskLog(getProject());

    prepareClassPath();/*w ww  .j  a  va 2  s .c  om*/

    try {
        Flyway flyway = new Flyway();

        flyway.setDataSource(createDataSource());
        String schemasValue = useValueIfPropertyNotSet(schemas, "schemas");
        if (schemasValue != null) {
            flyway.setSchemas(StringUtils.tokenizeToStringArray(schemasValue, ","));
        }
        String tableValue = useValueIfPropertyNotSet(table, "table");
        if (tableValue != null) {
            flyway.setTable(tableValue);
        }

        doExecute(flyway);
    } catch (Exception e) {
        LOG.error(e.toString());

        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
        Throwable rootCause = ExceptionUtils.getRootCause(e);
        if (rootCause != null) {
            LOG.error("Caused by " + rootCause.toString());
        }
        throw new BuildException("Flyway Error: " + e.toString(), e);
    } finally {
        AntLogAppender.endTaskLog();
    }
}

From source file:com.microsoft.alm.plugin.external.commands.Command.java

/**
 * This method starts the command after hooking up the listener. It returns immediately and calls the listener
 * when the command process finishes./*  w  w w.  ja  va 2  s  .  c om*/
 *
 * @param listener
 */
public void run(final Listener<T> listener) {
    final StringBuilder stdout = new StringBuilder();
    final StringBuilder stderr = new StringBuilder();
    ArgumentHelper.checkNotNull(listener, "listener");
    final ToolRunner runner = ToolRunnerCache.getRunningToolRunner(TfTool.getValidLocation(),
            getArgumentBuilder(), new ToolRunner.Listener() {
                @Override
                public void processStandardOutput(final String line) {
                    logger.info("CMD: " + line);
                    stdout.append(line + "\n");
                    listener.progress(line, OUTPUT_TYPE_INFO, 50);
                }

                @Override
                public void processStandardError(final String line) {
                    logger.info("ERROR: " + line);
                    stderr.append(line + "\n");
                    listener.progress(line, OUTPUT_TYPE_ERROR, 50);
                }

                @Override
                public void processException(final Throwable throwable) {
                    logger.info("ERROR: " + throwable.toString());
                    listener.progress("", OUTPUT_TYPE_INFO, 100);
                    listener.completed(null, throwable);
                }

                @Override
                public void completed(final int returnCode) {
                    listener.progress("Parsing command output", OUTPUT_TYPE_INFO, 99);

                    Throwable error = null;
                    T result = null;
                    try {
                        //TODO there are some commands that write errors to stdout and simply return a non-zero exit code (i.e. when a workspace is not found by name)
                        //TODO we may want to pass in the return code to the parse method or something like that to allow the command to inspect this info as well.
                        result = parseOutput(stdout.toString(), stderr.toString());
                        TfTool.throwBadExitCode(interpretReturnCode(returnCode));
                    } catch (Throwable throwable) {
                        logger.warn("CMD: parsing output failed", throwable);
                        error = throwable;
                    }
                    listener.progress("", OUTPUT_TYPE_INFO, 100);
                    listener.completed(result, error);
                }
            });
}

From source file:com.vmware.photon.controller.api.client.resource.FlavorApiTest.java

@Test
public void testListAllAsyncForPagination() throws Exception {
    Flavor flavor1 = new Flavor();
    flavor1.setId("flavor1");
    flavor1.setKind("vm");

    Flavor flavor2 = new Flavor();
    flavor2.setId("flavor2");
    flavor2.setKind("vm");

    Flavor flavor3 = new Flavor();
    flavor3.setId("flavor3");
    flavor3.setKind("vm");

    String nextPageLink = "nextPageLink";

    final ResourceList<Flavor> flavorResourceList = new ResourceList<>(Arrays.asList(flavor1, flavor2),
            nextPageLink, null);/* w  w  w . ja  v a 2 s .  c  o m*/
    final ResourceList<Flavor> flavorResourceListNextPage = new ResourceList<>(Arrays.asList(flavor3));
    final ResourceList<Flavor> expectedFlavorResourceList = new ResourceList<>(
            Arrays.asList(flavor1, flavor2, flavor3));

    ObjectMapper mapper = new ObjectMapper();
    String serializedResponse = mapper.writeValueAsString(flavorResourceList);
    String serializedResponseNextPage = mapper.writeValueAsString(flavorResourceListNextPage);

    setupMocksForPagination(serializedResponse, serializedResponseNextPage, nextPageLink, HttpStatus.SC_OK);

    FlavorApi flavorApi = new FlavorApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    flavorApi.listAllAsync(new FutureCallback<ResourceList<Flavor>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Flavor> result) {
            assertTrue(result.getItems().containsAll(expectedFlavorResourceList.getItems()));
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.api.client.resource.FlavorRestApiTest.java

@Test
public void testListAllAsyncForPagination() throws Exception {
    Flavor flavor1 = new Flavor();
    flavor1.setId("flavor1");
    flavor1.setKind("vm");

    Flavor flavor2 = new Flavor();
    flavor2.setId("flavor2");
    flavor2.setKind("vm");

    Flavor flavor3 = new Flavor();
    flavor3.setId("flavor3");
    flavor3.setKind("vm");

    String nextPageLink = "nextPageLink";

    final ResourceList<Flavor> flavorResourceList = new ResourceList<>(Arrays.asList(flavor1, flavor2),
            nextPageLink, null);// www . j av  a2s .  c o  m
    final ResourceList<Flavor> flavorResourceListNextPage = new ResourceList<>(Arrays.asList(flavor3));
    final ResourceList<Flavor> expectedFlavorResourceList = new ResourceList<>(
            Arrays.asList(flavor1, flavor2, flavor3));

    ObjectMapper mapper = new ObjectMapper();
    String serializedResponse = mapper.writeValueAsString(flavorResourceList);
    String serializedResponseNextPage = mapper.writeValueAsString(flavorResourceListNextPage);

    setupMocksForPagination(serializedResponse, serializedResponseNextPage, nextPageLink, HttpStatus.SC_OK);

    FlavorApi flavorApi = new FlavorRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    flavorApi.listAllAsync(new FutureCallback<ResourceList<Flavor>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Flavor> result) {
            assertTrue(result.getItems().containsAll(expectedFlavorResourceList.getItems()));
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}