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.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java

@Test
public void testGetProjectsAsyncForPagination() throws IOException, InterruptedException {
    Project project1 = new Project();
    project1.setId("project1");

    Project project2 = new Project();
    project2.setId("project2");

    Project project3 = new Project();
    project3.setId("project3");

    String nextPageLink = "nextPageLink";

    ResourceList<Project> projectResourceList = new ResourceList<>(Arrays.asList(project1, project2),
            nextPageLink, null);// w  w  w . j a va  2 s .  c  o m
    ResourceList<Project> projectResourceListNextPage = new ResourceList<>(Arrays.asList(project3));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(projectResourceList);
    String serializedTaskNextPage = mapper.writeValueAsString(projectResourceListNextPage);

    setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK);

    TenantsApi tenantsApi = new TenantsRestApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    tenantsApi.getProjectsAsync("foo", new FutureCallback<ResourceList<Project>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Project> result) {
            assertEquals(result.getItems().size(),
                    projectResourceList.getItems().size() + projectResourceListNextPage.getItems().size());
            assertTrue(result.getItems().containsAll(projectResourceList.getItems()));
            assertTrue(result.getItems().containsAll(projectResourceListNextPage.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.TenantsApiTest.java

@Test
public void testGetResourceTicketsAsyncForPagination() throws IOException, InterruptedException {
    ResourceTicket resourceTicket1 = new ResourceTicket();
    resourceTicket1.setId("resourceTicket1");

    ResourceTicket resourceTicket2 = new ResourceTicket();
    resourceTicket2.setId("resourceTicket2");

    ResourceTicket resourceTicket3 = new ResourceTicket();
    resourceTicket3.setId("resourceTicket3");

    String nextPageLink = "nextPageLink";

    ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>(
            Arrays.asList(resourceTicket1, resourceTicket2), nextPageLink, null);

    ResourceList<ResourceTicket> resourceTicketResourceListNextPage = new ResourceList<>(
            Arrays.asList(resourceTicket3));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(resourceTicketResourceList);
    String serializedTaskNextPage = mapper.writeValueAsString(resourceTicketResourceListNextPage);

    setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK);

    TenantsApi tenantsApi = new TenantsApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    tenantsApi.getResourceTicketsAsync("foo", new FutureCallback<ResourceList<ResourceTicket>>() {
        @Override/*from ww  w.  j a v a 2 s  . com*/
        public void onSuccess(@Nullable ResourceList<ResourceTicket> result) {
            assertEquals(result.getItems().size(), resourceTicketResourceList.getItems().size()
                    + resourceTicketResourceListNextPage.getItems().size());
            assertTrue(result.getItems().containsAll(resourceTicketResourceList.getItems()));
            assertTrue(result.getItems().containsAll(resourceTicketResourceListNextPage.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.TenantsRestApiTest.java

@Test
public void testGetResourceTicketsAsyncForPagination() throws IOException, InterruptedException {
    ResourceTicket resourceTicket1 = new ResourceTicket();
    resourceTicket1.setId("resourceTicket1");

    ResourceTicket resourceTicket2 = new ResourceTicket();
    resourceTicket2.setId("resourceTicket2");

    ResourceTicket resourceTicket3 = new ResourceTicket();
    resourceTicket3.setId("resourceTicket3");

    String nextPageLink = "nextPageLink";

    ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>(
            Arrays.asList(resourceTicket1, resourceTicket2), nextPageLink, null);

    ResourceList<ResourceTicket> resourceTicketResourceListNextPage = new ResourceList<>(
            Arrays.asList(resourceTicket3));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(resourceTicketResourceList);
    String serializedTaskNextPage = mapper.writeValueAsString(resourceTicketResourceListNextPage);

    setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK);

    TenantsApi tenantsApi = new TenantsRestApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    tenantsApi.getResourceTicketsAsync("foo", new FutureCallback<ResourceList<ResourceTicket>>() {
        @Override//from  w  w  w  .j av  a2s  . c  om
        public void onSuccess(@Nullable ResourceList<ResourceTicket> result) {
            assertEquals(result.getItems().size(), resourceTicketResourceList.getItems().size()
                    + resourceTicketResourceListNextPage.getItems().size());
            assertTrue(result.getItems().containsAll(resourceTicketResourceList.getItems()));
            assertTrue(result.getItems().containsAll(resourceTicketResourceListNextPage.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:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.ConsoleLicenseGenerator.java

public void run(String[] arguments) {
    this.processCommandLineOptions(arguments);

    try {//from   w  w  w  .ja  v a  2 s. c om
        this.initializeLicenseCreator();

        this.generateLicense();
    } catch (KeyNotFoundException e) {
        this.device.printErrLn(e.getLocalizedMessage() + " Correct the error and try again.");
        this.device.exit(51);
        return;
    } catch (ObjectSerializationException e) {
        this.device.printErrLn(e.getLocalizedMessage() + " Correct the error and try again.");
        this.device.exit(52);
        return;
    } catch (AlgorithmNotSupportedException e) {
        this.device.printErrLn(e.getLocalizedMessage() + " Contact your system administrator for assistance.");
        this.device.exit(41);
        return;
    } catch (InappropriateKeyException e) {
        this.device.printErrLn(e.getLocalizedMessage() + " Contact your system administrator for assistance.");
        this.device.exit(42);
        return;
    } catch (InappropriateKeySpecificationException e) {
        this.device.printErrLn(e.getLocalizedMessage() + " Contact your system administrator for assistance.");
        this.device.exit(43);
        return;
    } catch (InterruptedException e) {
        // in theory, this error wouldn't actually get reached in this circumstance,
        // but we'll catch it just in case
        this.device.printErrLn("The system was interrupted while waiting for events to complete.");
        this.device.exit(44);
        return;
    } catch (IOException e) {
        this.device.printErrLn("An error occurred writing or reading files from the system. Analyze the error "
                + "below to determine what went wrong and fix it!");
        this.device.printErrLn(e.toString());
        e.printStackTrace();
        this.device.exit(21);
        return;
    } catch (Throwable t) {
        this.device.printErrLn(t.toString());
        t.printStackTrace();
        this.device.exit(-1);
        return;
    }

    this.device.exit(0);
}

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

@Test
public void testListAsyncForPagination() throws IOException, InterruptedException {
    Tenant tenant1 = new Tenant();
    tenant1.setId("tenant1");
    tenant1.setName("tenant1");

    Tenant tenant2 = new Tenant();
    tenant2.setId("tenant2");
    tenant2.setName("tenant2");

    Tenant tenant3 = new Tenant();
    tenant3.setId("tenant3");
    tenant3.setName("tenant3");

    String nextPageLink = "nextPageLink";

    ResourceList<Tenant> tenantResourceList = new ResourceList<>(Arrays.asList(tenant1, tenant2), nextPageLink,
            null);/* w  w  w . jav  a 2s . c om*/
    ResourceList<Tenant> tenantResourceListNextPage = new ResourceList<>(Arrays.asList(tenant3));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(tenantResourceList);
    String serializedTaskNextPage = mapper.writeValueAsString(tenantResourceListNextPage);

    setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK);

    TenantsApi tenantsApi = new TenantsApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    tenantsApi.listByNameAsync("foo", new FutureCallback<ResourceList<Tenant>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Tenant> result) {
            assertEquals(result.getItems().size(),
                    tenantResourceList.getItems().size() + tenantResourceListNextPage.getItems().size());
            assertTrue(result.getItems().containsAll(tenantResourceList.getItems()));
            assertTrue(result.getItems().containsAll(tenantResourceListNextPage.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.TenantsRestApiTest.java

@Test
public void testListAsyncForPagination() throws IOException, InterruptedException {
    Tenant tenant1 = new Tenant();
    tenant1.setId("tenant1");
    tenant1.setName("tenant1");

    Tenant tenant2 = new Tenant();
    tenant2.setId("tenant2");
    tenant2.setName("tenant2");

    Tenant tenant3 = new Tenant();
    tenant3.setId("tenant3");
    tenant3.setName("tenant3");

    String nextPageLink = "nextPageLink";

    ResourceList<Tenant> tenantResourceList = new ResourceList<>(Arrays.asList(tenant1, tenant2), nextPageLink,
            null);//from w  w  w  .  j  a  v a 2 s . co m
    ResourceList<Tenant> tenantResourceListNextPage = new ResourceList<>(Arrays.asList(tenant3));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(tenantResourceList);
    String serializedTaskNextPage = mapper.writeValueAsString(tenantResourceListNextPage);

    setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK);

    TenantsApi tenantsApi = new TenantsRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    tenantsApi.listByNameAsync("foo", new FutureCallback<ResourceList<Tenant>>() {
        @Override
        public void onSuccess(@Nullable ResourceList<Tenant> result) {
            assertEquals(result.getItems().size(),
                    tenantResourceList.getItems().size() + tenantResourceListNextPage.getItems().size());
            assertTrue(result.getItems().containsAll(tenantResourceList.getItems()));
            assertTrue(result.getItems().containsAll(tenantResourceListNextPage.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:io.bitsquare.gui.util.BSFormatter.java

/**
 * Converts to a coin with max. 4 decimal places. Last place gets rounded.
 * 0.01234 -> 0.0123//from   w  w  w  .  j  av a  2s  .c  o  m
 * 0.01235 -> 0.0124
 *
 * @param input
 * @return
 */
public Coin parseToCoinWith4Decimals(String input) {
    try {
        return Coin.valueOf(new BigDecimal(parseToCoin(cleanInput(input)).value)
                .setScale(-scale - 1, BigDecimal.ROUND_HALF_UP).setScale(scale + 1).toBigInteger().longValue());
    } catch (Throwable t) {
        if (input != null && input.length() > 0)
            log.warn("Exception at parseToCoinWith4Decimals: " + t.toString());
        return Coin.ZERO;
    }
}

From source file:be.wegenenverkeer.common.resteasy.exception.ExceptionUtil.java

/**
 * Extract a "sensible", reasonably compact message.
 *
 * @param exc exception to get message for
 * @return error message//  w ww .  j ava2  s  . com
 */
private String getMessage(Throwable exc) {
    String msg;

    // see if there is a "getShortMessage" method
    Class clazz = exc.getClass();
    try {
        Method method = clazz.getMethod("getShortMessage");
        msg = (String) method.invoke(exc);
    } catch (Exception ex) {
        msg = null; /*ignore*/
    }

    // fallback to normal message or else class name
    if (msg == null || "null".equals(msg)) {
        msg = exc.getMessage();
    }
    if (msg == null || "null".equals(msg)) {
        msg = exc.toString();
    }

    return msg;
}

From source file:com.intuit.tank.util.ExceptionHandler.java

public void handle(Throwable t) {
    Throwable root = getRoot(t);
    if (root instanceof ConstraintViolationException) {
        ConstraintViolationException c = (ConstraintViolationException) root;
        for (@SuppressWarnings("rawtypes")
        ConstraintViolation v : c.getConstraintViolations()) {
            StringBuilder sb = new StringBuilder();
            sb.append(WordUtils.capitalize(v.getPropertyPath().iterator().next().getName()));
            sb.append(' ').append(v.getMessage()).append('.');
            messages.error(sb.toString());
        }//from   ww  w .j a  v  a2 s  .co  m
    } else if (!StringUtils.isEmpty(root.getMessage())) {
        messages.error(root.getMessage());
    } else {
        messages.error(root.toString());
    }
}

From source file:com.jkoolcloud.tnt4j.format.JSONFormatter.java

@Override
public String format(long ttl, Source source, OpLevel level, String msg, Object... args) {
    StringBuilder jsonString = new StringBuilder(1024);
    jsonString.append(START_JSON);/*from  w w  w . j  av a  2 s . c  o m*/
    jsonString.append(JSON_SEVERITY_LABEL).append(ATTR_SEP).append(Utils.quote(level)).append(ATTR_JSON);
    jsonString.append(JSON_SEVERITY_NO_LABEL).append(ATTR_SEP).append(level.ordinal()).append(ATTR_JSON);
    jsonString.append(JSON_TYPE_LABEL).append(ATTR_SEP).append(Utils.quote(OpType.DATAGRAM)).append(ATTR_JSON);
    jsonString.append(JSON_TYPE_NO_LABEL).append(ATTR_SEP).append(OpType.DATAGRAM.ordinal()).append(ATTR_JSON);

    jsonString.append(JSON_PID_LABEL).append(ATTR_SEP).append(Utils.getVMPID()).append(ATTR_JSON);
    jsonString.append(JSON_TID_LABEL).append(ATTR_SEP).append(Thread.currentThread().getId()).append(ATTR_JSON);

    String usrName = StringEscapeUtils.escapeJson(
            source == null ? DefaultSourceFactory.getInstance().getRootSource().getUser() : source.getUser());
    jsonString.append(JSON_USER_LABEL).append(ATTR_SEP).append(Utils.quote(usrName)).append(ATTR_JSON);
    jsonString.append(JSON_TTL_SEC_LABEL).append(ATTR_SEP).append(ttl).append(ATTR_JSON);
    jsonString.append(JSON_TIME_USEC_LABEL).append(ATTR_SEP).append(Useconds.CURRENT.get()).append(ATTR_JSON);
    jsonString.append(JSON_OPERATION_LABEL).append(ATTR_SEP).append(Utils.quote(defOpName)).append(ATTR_JSON);

    if (source != null) {
        jsonString.append(JSON_SOURCE_LABEL).append(ATTR_SEP)
                .append(Utils.quote(StringEscapeUtils.escapeJson(source.getName()))).append(ATTR_JSON);
        String ssn = source.getSourceFactory().getSSN();
        if (!Utils.isEmpty(ssn)) {
            String escaped = StringEscapeUtils.escapeJson(ssn); // escape double quote chars
            jsonString.append(JSON_SOURCE_SSN_LABEL).append(ATTR_SEP).append(Utils.quote(escaped))
                    .append(ATTR_JSON);
        }
        jsonString.append(JSON_SOURCE_FQN_LABEL).append(ATTR_SEP)
                .append(Utils.quote(StringEscapeUtils.escapeJson(source.getFQName())));
        if (!Utils.isEmpty(source.getUrl())) {
            jsonString.append(ATTR_JSON);
            String escaped = StringEscapeUtils.escapeJson(source.getUrl()); // escape double quote chars
            jsonString.append(JSON_SOURCE_URL_LABEL).append(ATTR_SEP).append(Utils.quote(escaped));
        }
        Source geoloc = source.getSource(SourceType.GEOADDR);
        if (geoloc != null) {
            jsonString.append(ATTR_JSON);
            jsonString.append(JSON_LOCATION_LABEL).append(ATTR_SEP).append(Utils.quote(geoloc.getName()));
        }
    }
    if (!Utils.isEmpty(msg)) {
        String msgText = Utils.format(msg, args);
        msgText = StringEscapeUtils.escapeJson(msgText); // escape double quote chars
        jsonString.append(ATTR_JSON);
        jsonString.append(JSON_MSG_TEXT_LABEL).append(ATTR_SEP).append(Utils.quote(msgText));
    }
    Throwable ex = Utils.getThrowable(args);
    if (ex != null) {
        jsonString.append(ATTR_JSON);
        String excText = StringEscapeUtils.escapeJson(ex.toString()); // escape double quote chars
        jsonString.append(JSON_EXCEPTION_LABEL).append(ATTR_SEP).append(Utils.quote(excText));
    }
    jsonString.append(END_JSON);
    return jsonString.toString();
}