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:net.sf.clirr.cli.Clirr.java

private void run(String[] args) {
    Options options = defineOptions();/*from   w ww .  ja v  a 2  s .co  m*/

    CommandLine cmdline = parseCommandLine(args, options);

    String oldPath = cmdline.getOptionValue('o');
    String newPath = cmdline.getOptionValue('n');
    String oldClassPath = cmdline.getOptionValue("ocp");
    String newClassPath = cmdline.getOptionValue("ncp");
    String style = cmdline.getOptionValue('s', "text");
    String outputFileName = cmdline.getOptionValue('f');
    String[] includePkgs = cmdline.getOptionValues('i');
    boolean showAll = cmdline.hasOption('a');
    boolean showPkg = cmdline.hasOption('p');

    if ((oldPath == null) || (newPath == null)) {
        printUsage(options, System.err);
        System.exit(-1);
    }

    Checker checker = new Checker();
    if (showAll) {
        checker.getScopeSelector().setScope(Scope.PRIVATE);
    } else if (showPkg) {
        checker.getScopeSelector().setScope(Scope.PACKAGE);
    }

    ClassSelector classSelector;
    if ((includePkgs != null) && (includePkgs.length > 0)) {
        classSelector = new ClassSelector(ClassSelector.MODE_IF);
        for (int i = 0; i < includePkgs.length; ++i) {
            classSelector.addPackageTree(includePkgs[i]);
        }
    } else {
        // a selector that selects everything
        classSelector = new ClassSelector(ClassSelector.MODE_UNLESS);
    }

    DiffListener diffListener = null;
    if (style.equals("text")) {
        try {
            diffListener = new PlainDiffListener(outputFileName);
        } catch (IOException ex) {
            System.err.println("Invalid output file name.");
        }
    } else if (style.equals("xml")) {
        try {
            diffListener = new XmlDiffListener(outputFileName);
        } catch (IOException ex) {
            System.err.println("Invalid output file name.");
        }
    } else {
        System.err.println("Invalid style option. Must be one of 'text', 'xml'.");
        printUsage(options, System.err);
        System.exit(-1);
    }

    File[] origClassPathEntries = pathToFileArray(oldPath);
    File[] newClassPathEntries = pathToFileArray(newPath);

    checker.addDiffListener(diffListener);

    try {
        ClassLoader loader1 = new URLClassLoader(convertFilesToURLs(pathToFileArray(oldClassPath)));
        ClassLoader loader2 = new URLClassLoader(convertFilesToURLs(pathToFileArray(newClassPath)));

        DefaultTypeArrayBuilderFactory tabFactory = new DefaultTypeArrayBuilderFactory();

        TypeArrayBuilder tab1 = tabFactory.build();
        TypeArrayBuilder tab2 = tabFactory.build();

        final JavaType[] origClasses = tab1.createClassSet(origClassPathEntries, loader1, classSelector);

        final JavaType[] newClasses = tab2.createClassSet(newClassPathEntries, loader2, classSelector);

        checker.reportDiffs(origClasses, newClasses);

        System.exit(0);
    } catch (CheckerException ex) {
        System.err.println("Unable to complete checks: " + ex.getMessage());
        System.exit(1);
    } catch (MalformedURLException ex) {
        System.err.println("Unable to create classloader for 3rd party classes: " + ex.getMessage());
        System.err.println("old classpath: " + oldClassPath);
        System.err.println("new classpath: " + newClassPath);
        System.exit(1);
    } catch (RuntimeException ex) {
        System.err.println("Unable to complete checks: " + ex.toString());
        Throwable cause = ex.getCause();
        if (cause != null) {
            System.err.println("  caused by : " + cause.toString());
        }
        System.exit(2);
    }
}

From source file:com.streamsets.datacollector.el.ELEvaluator.java

@Override
@SuppressWarnings("unchecked")
public <T> T evaluate(final ELVars vars, String expression, Class<T> returnType) throws ELEvalException {
    VariableResolver variableResolver = new VariableResolver() {

        @Override//from   ww  w .j a  v a2  s  .  c o m
        public Object resolveVariable(String name) throws ELException {
            Object value = constants.get(name);
            if (!vars.hasVariable(name)) {
                if (value == null && !constants.containsKey(name)) {
                    throw new ELException(Utils.format("Constants/Variable '{}' cannot be resolved", name));
                }
            } else {
                value = vars.getVariable(name);
            }
            return value;
        }
    };
    try {
        return (T) EVALUATOR.evaluate(expression, returnType, variableResolver, functionMapper);
    } catch (ELException e) {
        LOG.debug("Error valuating EL '{}': {}", expression, e.toString(), e);
        Throwable t = e;
        if (e.getRootCause() != null) {
            t = e.getRootCause();
        }
        throw new ELEvalException(CommonError.CMN_0104, expression, t.toString(), e);
    }
}

From source file:edu.pitt.dbmi.facebase.hd.InstructionQueueManager.java

/** Retrieves new queue items from Hub's DB
 * Calls getNewQueueItems()/* www.  j a  v  a  2  s  .  c om*/
 *
 * @return list of queue items found with status='request'
 */
List<InstructionQueueItem> queryInstructions() {
    log.debug("InstructionQueueManager.queryInstructions() called.");
    Session session = null;
    Transaction transaction = null;
    List<InstructionQueueItem> items = new ArrayList<InstructionQueueItem>();
    try {
        session = conf.openSession();
        items = getNewQueueItems(session);
        session.flush();
        session.close();
    } catch (Throwable t) {
        String errorString = "InstructionQueueManager caught a t in queryInstructions() " + t.toString();
        String logString = t.getMessage();
        edu.pitt.dbmi.facebase.hd.HumanDataController.addError(errorString, logString);
        log.error(errorString, t);
        handleThrowable(t, session, transaction);
    }
    return (items);
}

From source file:org.chtijbug.drools.platform.backend.jms.JMSHistoryEventListener.java

@Transactional
public void onMessage(Message message) {
    HistoryEvent historyEvent = null;/*  w ww .j  a v a2 s  . co m*/
    try {
        if (message instanceof ObjectMessage) {
            ObjectMessage objectMessage = (ObjectMessage) message;
            Object messageContent = objectMessage.getObject();
            historyEvent = (HistoryEvent) messageContent;
            try {
                AbstractEventHandlerStrategy strategy = messageHandlerResolver
                        .resolveMessageHandler(historyEvent);
                strategy.handleMessage(historyEvent);
            } catch (Throwable e) {
                throw Throwables.propagate(e);
            }
            ObjectMessage msg = (ObjectMessage) message;
            LOG.debug("Consumed message: " + msg.toString());
        }
    } catch (Exception e) {
        LOG.error("Consumed message: " + e.toString() + " message content " + message.toString());
        LOG.error("                  message  " + message.toString());
        LOG.error("                  object content " + historyEvent.toString());

    }
}

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

@Test
public void testGetClusterAsync() throws IOException, InterruptedException {
    final Cluster cluster = new Cluster();
    cluster.setName("clusterName");
    cluster.setState(ClusterState.READY);

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(cluster);

    setupMocks(serializedTask, HttpStatus.SC_OK);

    ClusterApi clusterApi = new ClusterApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    clusterApi.getClusterAsync("foo", new FutureCallback<Cluster>() {
        @Override//w  w w. ja  v a2  s  .  c  om
        public void onSuccess(Cluster result) {
            assertEquals(result, cluster);
            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.ClusterRestApiTest.java

@Test
public void testGetClusterAsync() throws IOException, InterruptedException {
    final Cluster cluster = new Cluster();
    cluster.setName("clusterName");
    cluster.setState(ClusterState.READY);

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(cluster);

    setupMocks(serializedTask, HttpStatus.SC_OK);

    ClusterApi clusterApi = new ClusterRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    clusterApi.getClusterAsync("foo", new FutureCallback<Cluster>() {
        @Override/*from   w  w w  . j av a  2  s. com*/
        public void onSuccess(Cluster result) {
            assertEquals(result, cluster);
            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.linkedin.databus2.ggParser.staxparser.validator.XmlFormatTrailValidator.java

public boolean run() throws IOException {
    boolean success = false;
    LOG.info("starting validation ...");
    if (_continuous) {
        Thread runThread = new Thread(_parser, "XmlFormatTrailParser");
        runThread.start();/*from   ww  w  .j  av a  2s .c  o  m*/
        success = true;
    } else {
        _parser.run();
        Throwable error = _parser.getLastError();
        LOG.info("validation complete: " + (null == error ? "SUCCESS" : error.toString()));
        if (null != error) {
            _parser.printErrorContext(System.err);
        } else {
            success = true;
        }
        LOG.info("PARSE ERRORS: " + _parser.getErrorCount());
    }

    return success;
}

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

@Test
public void testDeleteAsync() throws IOException, InterruptedException {
    final Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    ClusterApi clusterApi = new ClusterApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    clusterApi.deleteAsync("foo", new FutureCallback<Task>() {
        @Override/*w w  w  .jav  a2  s .  c om*/
        public void onSuccess(Task result) {
            assertEquals(result, responseTask);
            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.ClusterApiTest.java

@Test
public void testResizeAsync() throws IOException, InterruptedException {
    final Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    ClusterApi clusterApi = new ClusterApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    clusterApi.resizeAsync("dummy-cluster-id", 100, new FutureCallback<Task>() {
        @Override//from  ww  w  .ja  v  a 2  s  .  c  om
        public void onSuccess(Task result) {
            assertEquals(result, responseTask);
            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.ClusterRestApiTest.java

@Test
public void testDeleteAsync() throws IOException, InterruptedException {
    final Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    ClusterApi clusterApi = new ClusterRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    clusterApi.deleteAsync("foo", new FutureCallback<Task>() {
        @Override/*w  w  w. j a  v a  2 s  .c o m*/
        public void onSuccess(Task result) {
            assertEquals(result, responseTask);
            latch.countDown();
        }

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

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