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.DisksApiTest.java

@Test
public void testGetTasksForDisksAsync() throws IOException, InterruptedException {
    Task task1 = new Task();
    task1.setId("task1");

    Task task2 = new Task();
    task2.setId("task2");

    final ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2));

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

    setupMocks(serializedTask, HttpStatus.SC_OK);

    DisksApi disksApi = new DisksApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    disksApi.getTasksForDiskAsync("persistentDisk", new FutureCallback<ResourceList<Task>>() {
        @Override//from w w w.ja va2s  . c  o  m
        public void onSuccess(@Nullable ResourceList<Task> result) {
            assertEquals(result.getItems(), taskResourceList.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.DisksRestApiTest.java

@Test
public void testGetTasksForDisksAsync() throws IOException, InterruptedException {
    Task task1 = new Task();
    task1.setId("task1");

    Task task2 = new Task();
    task2.setId("task2");

    final ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2));

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

    setupMocks(serializedTask, HttpStatus.SC_OK);

    DisksApi disksApi = new DisksRestApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    disksApi.getTasksForDiskAsync("persistentDisk", new FutureCallback<ResourceList<Task>>() {
        @Override/*from  ww w .  ja va 2 s .  co  m*/
        public void onSuccess(@Nullable ResourceList<Task> result) {
            assertEquals(result.getItems(), taskResourceList.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.analog.lyric.dimple.test.model.TestJunctionTreeTransform.java

private void testGraph(FactorGraph model, @Nullable Boolean expectIdentity) {
    try {//from   w w w  .  j a  va 2 s. c  o m
        testGraphImpl(model, expectIdentity);
    } catch (Throwable ex) {
        String msg = String.format("%s. TestJunctionTreeTransform._seed==%dL", ex.toString(),
                testRand.getSeed());
        ex.printStackTrace(System.err);
        System.err.format(">>> TestJunctionTreeTransform._seed==%dL;<<<\n", testRand.getSeed());
        throw new RuntimeException(msg, ex);
    }
}

From source file:com.commonsware.android.strict.WeatherDemo.java

private void updateForecast(Location loc) {
    String url = String.format(format, loc.getLatitude(), loc.getLongitude());
    HttpGet getMethod = new HttpGet(url);

    try {// w ww  . ja v  a 2 s . c o  m
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = client.execute(getMethod, responseHandler);
        buildForecasts(responseBody);

        String page = generatePage();

        browser.loadDataWithBaseURL(null, page, "text/html", "UTF-8", null);
    } catch (Throwable t) {
        android.util.Log.e("WeatherDemo", "Exception fetching data", t);
        Toast.makeText(this, "Request failed: " + t.toString(), Toast.LENGTH_LONG).show();
    }
}

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

@Test
public void testGetImageAsync() throws IOException, InterruptedException {
    final Image image = new Image();
    image.setId("image1");

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

    setupMocks(serializedTask, HttpStatus.SC_OK);

    ImagesApi imagesApi = new ImagesApi(this.restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    imagesApi.getImageAsync(image.getId(), new FutureCallback<Image>() {
        @Override// ww  w.j  a va  2  s. c o m
        public void onSuccess(@Nullable Image result) {
            assertEquals(result, image);
            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.ImagesRestApiTest.java

@Test
public void testGetImageAsync() throws IOException, InterruptedException {
    final Image image = new Image();
    image.setId("image1");

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

    setupMocks(serializedTask, HttpStatus.SC_OK);

    ImagesApi imagesApi = new ImagesRestApi(this.restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    imagesApi.getImageAsync(image.getId(), new FutureCallback<Image>() {
        @Override/*from   w w  w .j  a  v  a 2 s.  co m*/
        public void onSuccess(@Nullable Image result) {
            assertEquals(result, image);
            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:org.bpmscript.integration.spring.proxy.SpringBpmScriptFacade.java

/**
 * Call a definition using it's name and methodName and send it an array of args. 
 * Wait for timeout milliseconds for the response.
 * //from   ww w.java 2 s.  com
 * @see org.bpmscript.integration.internal.proxy.IBpmScriptFacade#call(java.lang.String, java.lang.String, java.lang.Object[])
 */
public Object call(String definitionName, String methodName, long timeout, Object... args) throws Exception {
    String id = UUID.randomUUID().toString();
    try {
        GenericMessage<Object[]> in = new GenericMessage<Object[]>(args);
        in.getHeader().setAttribute("operation", methodName);
        in.getHeader().setAttribute("definitionName", definitionName);
        in.getHeader().setReturnAddress(returnAddress);
        in.getHeader().setCorrelationId(id);
        syncChannel.expect(id);
        sender.send(address, in);

        Message<?> result = (Message<?>) syncChannel.get(id, timeout);
        if (result == null) {
            log.debug("sync service timed out for " + in);
            return null;
        }
        // TODO: this is where the code is copied... see spring conversation correlator
        Object payload = result.getPayload();
        if (payload instanceof Throwable) {
            Throwable error = (Throwable) payload;
            if (error instanceof Exception) {
                throw (Exception) error;
            } else {
                throw new RuntimeException(error.toString());
            }
        } else {
            return payload;
        }
    } finally {
        syncChannel.close(id);
    }
}

From source file:com.esri.gpt.agp.client.AgpClient.java

/**
 * Executes a request expecting a JSON response.
 * @param url the URL/*w  ww .  j  a  v  a  2s . c  om*/
 * @param requestHeader optional request header properties
 * @param contentProvider the request body content provider
 * @return the JSON response object
 * @throws Exception is an exception occurs
 */
public JSONObject executeJsonRequest(String url, AgpProperties requestHeader, ContentProvider contentProvider)
        throws Exception {
    LOGGER.finest("Sending URL: " + url);
    StringHandler handler = new StringHandler();
    this.executeRequest(url, requestHeader, contentProvider, handler);
    String sResponse = handler.getContent();
    LOGGER.finest("Response for URL: " + url + "\n" + sResponse);

    JSONObject jsoResponse = null;
    try {
        if (sResponse == null) {
            LOGGER.finest("Response for URL: " + url + "\nnull response");
        } else if (sResponse.length() == 0) {
            LOGGER.finest("Response for URL: " + url + "\nempty response");
        } else {
            jsoResponse = new JSONObject(sResponse);
            if (jsoResponse.has("error") && (!jsoResponse.isNull("error"))) {
                AgpError agpError = new AgpError();
                agpError.parse(jsoResponse);
                throw new AgpException(agpError);
            }
        }
    } catch (AgpException e) {
        LOGGER.log(Level.FINEST, "Request failed.", e);
        throw e;
    } catch (Throwable t) {
        LOGGER.log(Level.FINEST, "Request failed.", t);
        AgpError agpError = new AgpError();
        agpError.setMessage(t.toString());
        throw new AgpException(agpError);
    }
    return jsoResponse;
}

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

@Test
public void testDeleteImageAsync() 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);

    ImagesApi imagesApi = new ImagesApi(this.restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    imagesApi.deleteAsync("foo", new FutureCallback<Task>() {
        @Override//from   w ww  .j  a  v  a  2 s  .  c  o  m
        public void onSuccess(@Nullable 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.ImagesRestApiTest.java

@Test
public void testDeleteImageAsync() 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);

    ImagesApi imagesApi = new ImagesRestApi(this.restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    imagesApi.deleteAsync("foo", new FutureCallback<Task>() {
        @Override//www .j a  va  2  s  .co m
        public void onSuccess(@Nullable 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));
}