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.connectsdk.cordova.JSCommandDispatcher.java

public void dispatchCommand(String interfaceName, String methodName, JSCommand command, JSONObject args,
        boolean subscribe) {
    Method method = getMethod(interfaceName, methodName);

    if (method != null) {
        try {/*from  w w  w  .  j a  va  2s .c o m*/
            Object returnValue = method.invoke(this, command, args);

            if (returnValue != null && returnValue instanceof ServiceSubscription) {
                command.serviceSubscription = (ServiceSubscription<?>) returnValue;
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            Exception wrappedException = new DispatcherException(
                    "Exception calling " + methodName + ": " + cause.toString());
            wrappedException.initCause(cause);

            wrappedException.printStackTrace();
            command.error(wrappedException);
        } catch (Exception e) {
            e.printStackTrace();
            command.error(e);
        }
    } else {
        Log.d("ConnectSDKCordova", "Method not implemented: " + interfaceName + "." + methodName);
        command.error("method not implemented");
    }
}

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

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

    VmApi vmApi = new VmApi(restClient);

    VmOperation vmOperation = new VmOperation();
    vmOperation.setOperation(Operation.START_VM.name());

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.performOperationAsync("foo", vmOperation, new FutureCallback<Task>() {
        @Override/*from   w w  w.ja  v  a  2s . 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.esri.gpt.catalog.gxe.GxeServlet.java

/**
 * Handles a request to return a posted XML document as
 * a content disposition attachment./*w w  w . j  av  a2s  .c  o  m*/
 * <br/>The posted mime-type should be: application/x-www-form-urlencoded
 * <br/>The posted URL parameter name should be: xml
 * @param request the HTTP servlet request
 * @param response the HTTP servlet response
 * @param context the request context
 * @throws Exception if a processing exception occurs
 */
private void executeEchoAttachment(HttpServletRequest request, HttpServletResponse response,
        RequestContext context) throws Exception {

    String sResponse = "";
    String sFilename = "";
    try {

        // read the posted xml
        String sXml = this.readPostedXml(request, response, context);
        if ((sXml != null) && (sXml.length() > 0)) {
            sResponse = sXml;
            sFilename = Val.chkStr(request.getParameter("filename"));
            if (sFilename.length() == 0)
                sFilename = "metadata.xml";
        } else {
            sFilename = "error.txt";
            sResponse = "Error: The posted XML was empty.";
        }
    } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Error processing request.", t);
        String sMsg = Val.chkStr(t.getMessage());
        if (sMsg.length() == 0)
            sMsg = t.toString();
        sFilename = "error.xml";
        sResponse = "Error: " + sMsg;
    }

    // write the response
    //LOGGER.finest("gxeResponse:\n"+sResponse);
    response.setContentType("APPLICATION/OCTET-STREAM; charset=UTF-8");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + sFilename + "\"");
    writeCharacterResponse(response, sResponse, "UTF-8", "APPLICATION/OCTET-STREAM; charset=UTF-8");
}

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

@Test
public void testGetVmAsync() throws IOException, InterruptedException {
    final Vm vm = new Vm();
    vm.setId("vm");

    ObjectMapper mapper = new ObjectMapper();
    String serialized = mapper.writeValueAsString(vm);

    setupMocks(serialized, HttpStatus.SC_OK);

    VmApi vmApi = new VmApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.getVmAsync("foo", new FutureCallback<Vm>() {
        @Override/*from   w  ww  .jav  a  2  s .c om*/
        public void onSuccess(@Nullable Vm result) {
            assertEquals(result, vm);
            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.VmRestApiTest.java

@Test
public void testGetVmAsync() throws IOException, InterruptedException {
    final Vm vm = new Vm();
    vm.setId("vm");

    ObjectMapper mapper = new ObjectMapper();
    String serialized = mapper.writeValueAsString(vm);

    setupMocks(serialized, HttpStatus.SC_OK);

    VmApi vmApi = new VmRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.getVmAsync("foo", new FutureCallback<Vm>() {
        @Override//from www  .  j a v  a2  s .  co  m
        public void onSuccess(@Nullable Vm result) {
            assertEquals(result, vm);
            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.VmApiTest.java

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

    VmApi vmApi = new VmApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.attachDiskAsync("foo", new VmDiskOperation(), new FutureCallback<Task>() {
        @Override//from  w ww  .j a  v  a 2s  .c  om
        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.VmRestApiTest.java

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

    VmApi vmApi = new VmRestApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.attachDiskAsync("foo", new VmDiskOperation(), new FutureCallback<Task>() {
        @Override/*from ww  w  . j ava 2 s.com*/
        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.VmApiTest.java

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

    VmApi vmApi = new VmApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.performStartOperationAsync("foo", new FutureCallback<Task>() {
        @Override/*from  w ww  .j  a  va2 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));
}