List of usage examples for java.lang Throwable toString
public String toString()
From source file:com.polyvi.xface.exceptionReporter.XCrashInfo.java
/** * ?//from ww w. j a v a 2 s . c o m * @param ex * @return ? */ private JSONObject getExceptionInfo(Throwable ex) { JSONObject exceptionInfo = new JSONObject(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(baos); ex.printStackTrace(printStream); byte[] data = baos.toByteArray(); String info = new String(data); Throwable cause = ex.getCause(); try { exceptionInfo.put(TAG_EXCEPTION_NAME, ex.getClass().getSimpleName()); exceptionInfo.put(TAG_EXCEPTION_REASON, null == cause ? "unknown cause" : cause.toString()); exceptionInfo.put(TAG_STACK_TRACE, info); } catch (JSONException e) { XLog.e(CLASS_NAME, "JSONException:", e.getMessage()); return null; } return exceptionInfo; }
From source file:com.kakao.http.KakaoAsyncHandler.java
public void onThrowable(final Throwable t) { httpResponseHandler.sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.ERROR, 0, 0, new APIErrorResult(request.getUrl(), "error occurred during http request. t= " + t.toString()))); }
From source file:com.teletalk.jserver.tcp.http.xmlrpc.XmlRpcProxyClient.java
/** * Called to handle an exception that was thrown when executing the request (in {@link #handleRequest(HttpRequest)}). * This implementation will return an XmlRpcException with a code specified through the property <code>defaultErrorCode</code>. The message * will be generated though a call to <code>exception.toString()</code>.<br> * <br>//w w w . ja va 2s . c o m * Subclasses may override this method to provide a customized exception processsing implementation. * * @param exception the exception that was thrown. */ public XmlRpcException processException(Throwable exception) { return new XmlRpcException(this.defaultErrorCode.intValue(), exception.toString()); }
From source file:com.vmware.photon.controller.api.client.resource.DisksApiTest.java
@Test public void testGetTasksForDisksAsyncForPagination() throws IOException, InterruptedException { Task task1 = new Task(); task1.setId("task1"); Task task2 = new Task(); task2.setId("task2"); Task task3 = new Task(); task3.setId("task3"); Task task4 = new Task(); task4.setId("task4"); String nextPageLink = "nextPageLink"; final ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2), nextPageLink, null);/*from www. java2 s .co m*/ final ResourceList<Task> taskResourceListNextPage = new ResourceList<>(Arrays.asList(task3, task4)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(taskResourceList); String serializedTaskNextPage = mapper.writeValueAsString(taskResourceListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); DisksApi disksApi = new DisksApi(restClient); final CountDownLatch latch = new CountDownLatch(1); disksApi.getTasksForDiskAsync("persistentDisk", new FutureCallback<ResourceList<Task>>() { @Override public void onSuccess(@Nullable ResourceList<Task> result) { assertEquals(result.getItems().size(), taskResourceList.getItems().size() + taskResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(taskResourceList.getItems())); assertTrue(result.getItems().containsAll(taskResourceListNextPage.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 testGetTasksForDisksAsyncForPagination() throws IOException, InterruptedException { Task task1 = new Task(); task1.setId("task1"); Task task2 = new Task(); task2.setId("task2"); Task task3 = new Task(); task3.setId("task3"); Task task4 = new Task(); task4.setId("task4"); String nextPageLink = "nextPageLink"; final ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2), nextPageLink, null);/* w w w . j a v a 2 s . c o m*/ final ResourceList<Task> taskResourceListNextPage = new ResourceList<>(Arrays.asList(task3, task4)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(taskResourceList); String serializedTaskNextPage = mapper.writeValueAsString(taskResourceListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); DisksApi disksApi = new DisksRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); disksApi.getTasksForDiskAsync("persistentDisk", new FutureCallback<ResourceList<Task>>() { @Override public void onSuccess(@Nullable ResourceList<Task> result) { assertEquals(result.getItems().size(), taskResourceList.getItems().size() + taskResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(taskResourceList.getItems())); assertTrue(result.getItems().containsAll(taskResourceListNextPage.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.ImagesApiTest.java
@Test public void testGetAllImagesAsync() throws IOException, InterruptedException { Image image1 = new Image(); image1.setId("image1"); Image image2 = new Image(); image2.setId("image2"); final ResourceList<Image> imageResourceList = new ResourceList<>(Arrays.asList(image1, image2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(imageResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); ImagesApi imagesApi = new ImagesApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.getImagesAsync(new FutureCallback<ResourceList<Image>>() { @Override//from w w w . java 2 s . c o m public void onSuccess(@Nullable ResourceList<Image> result) { assertEquals(result.getItems(), imageResourceList.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.ImagesRestApiTest.java
@Test public void testGetAllImagesAsync() throws IOException, InterruptedException { Image image1 = new Image(); image1.setId("image1"); Image image2 = new Image(); image2.setId("image2"); final ResourceList<Image> imageResourceList = new ResourceList<>(Arrays.asList(image1, image2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(imageResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); ImagesApi imagesApi = new ImagesRestApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.getImagesAsync(new FutureCallback<ResourceList<Image>>() { @Override// w w w . j a va 2 s . com public void onSuccess(@Nullable ResourceList<Image> result) { assertEquals(result.getItems(), imageResourceList.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.stallion.asyncTasks.AsyncTaskDbPersister.java
@Override public boolean markFailed(AsyncTask task, Throwable e) { Log.info("Mark task failed: id={0} handler={1} customKey={2}", task.getId(), task.getHandlerName(), task.getCustomKey());/*from w w w. ja v a2 s . c om*/ task.setTryCount(task.getTryCount() + 1); task.setErrorMessage(e.toString() + ExceptionUtils.getStackTrace(e)); if (task.getTryCount() >= 5) { task.setFailedAt(DateUtils.mils()); Log.info("Mark task failed permanently: id={0} handler={1} customKey={2}", task.getId(), task.getHandlerName(), task.getCustomKey()); } else { task.setExecuteAt(DateUtils.mils() + ((2 ^ task.getTryCount()) * 1000)); task.setLockedAt(0); task.setLockUuid(""); } persist(task); return true; }
From source file:com.vmware.photon.controller.api.client.resource.ImagesApiTest.java
@Test public void testGetAllImagesAsyncForPagination() throws IOException, InterruptedException { Image image1 = new Image(); image1.setId("image1"); Image image2 = new Image(); image2.setId("image2"); Image image3 = new Image(); image3.setId("image3"); String nextPageLink = "nextPageLink"; final ResourceList<Image> imageResourceList = new ResourceList<>(Arrays.asList(image1, image2), nextPageLink, null);/* w w w.ja va 2s . c om*/ final ResourceList<Image> imageResourceListNextPage = new ResourceList<>(Arrays.asList(image3)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(imageResourceList); String serializedTaskNextPage = mapper.writeValueAsString(imageResourceListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); ImagesApi imagesApi = new ImagesApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.getImagesAsync(new FutureCallback<ResourceList<Image>>() { @Override public void onSuccess(@Nullable ResourceList<Image> result) { assertEquals(result.getItems().size(), imageResourceList.getItems().size() + imageResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(imageResourceList.getItems())); assertTrue(result.getItems().containsAll(imageResourceListNextPage.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.ImagesRestApiTest.java
@Test public void testGetAllImagesAsyncForPagination() throws IOException, InterruptedException { Image image1 = new Image(); image1.setId("image1"); Image image2 = new Image(); image2.setId("image2"); Image image3 = new Image(); image3.setId("image3"); String nextPageLink = "nextPageLink"; final ResourceList<Image> imageResourceList = new ResourceList<>(Arrays.asList(image1, image2), nextPageLink, null);//from ww w.j ava 2s .com final ResourceList<Image> imageResourceListNextPage = new ResourceList<>(Arrays.asList(image3)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(imageResourceList); String serializedTaskNextPage = mapper.writeValueAsString(imageResourceListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); ImagesApi imagesApi = new ImagesRestApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.getImagesAsync(new FutureCallback<ResourceList<Image>>() { @Override public void onSuccess(@Nullable ResourceList<Image> result) { assertEquals(result.getItems().size(), imageResourceList.getItems().size() + imageResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(imageResourceList.getItems())); assertTrue(result.getItems().containsAll(imageResourceListNextPage.getItems())); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }