Example usage for java.lang Throwable getClass

List of usage examples for java.lang Throwable getClass

Introduction

In this page you can find the example usage for java.lang Throwable getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StopDeviceTestSteps.java

@DomainStep("the stop device test request is received")
public void whenTheRequestIsReceived() {
    LOGGER.info("WHEN: the stop device test request is received.");

    try {//from   ww  w  .  java 2  s  .  co m
        this.stopDeviceTestAsyncResponse = this.deviceInstallationEndpoint
                .stopDeviceTest(this.organisation.getOrganisationIdentification(), this.request);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        this.throwable = t;
    }
}

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StopDeviceTestSteps.java

@DomainStep("the stop device test response request is received")
public void whenTheStopDeviceTestResponseRequestIsReceived() {
    LOGGER.info("WHEN: \"the stop device test response request is received\".");

    try {//from  w w w .ja  va  2 s  .co  m
        this.response = this.deviceInstallationEndpoint.getStopDeviceTestResponse(
                this.organisation.getOrganisationIdentification(), this.stopDeviceTestAsyncRequest);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        this.throwable = t;
    }
}

From source file:com.comcast.drivethru.client.ClientExecuteTest.java

@Test(dataProvider = "exceptionTests")
public void testExecuteExceptions(Throwable thrown, Class<?> expected, String messagePart) throws Exception {

    RestRequest request = new RestRequest(new URL().setPath("/").addQuery("q", "stuff"), POST);
    request.setContentType("application/json");
    request.setBody("{ \"name\" : \"Clark\" }");
    request.addHeader("x-transaction-id", "0011223344556677");

    Capture<HttpPost> capture = EasyMock.newCapture();
    Capture<HttpPost> capture2 = EasyMock.newCapture();

    HttpClient delegate = createMock(HttpClient.class);
    expect(delegate.execute(capture(capture))).andThrow(thrown);

    SecurityProvider securityProvider = createMock(SecurityProvider.class);
    securityProvider.sign(capture(capture2));
    expectLastCall();/*from  ww w.j av a  2s. c o  m*/

    replay(delegate, securityProvider);

    String base = "http://www.google.com";
    DefaultRestClient client = new DefaultRestClient(base, delegate);
    client.addDefaultHeader("Fintan", "The Salmon of Knowledge");
    client.setSecurityProvider(securityProvider);

    Throwable actual = null;
    try {
        client.execute(request);
    } catch (Throwable t) {
        actual = t;
    } finally {
        client.close();
    }

    /* Verify the thrown exception */
    assertNotNull(actual);
    assertEquals(actual.getClass(), expected);
    assertTrue(actual.getMessage().contains(messagePart));

    /* Verify the constructed request object */
    assertTrue(capture.hasCaptured());
    HttpPost req = capture.getValue();
    assertEquals(req.getLastHeader("Content-Type").getValue(), "application/json");
    assertEquals(req.getLastHeader("x-transaction-id").getValue(), "0011223344556677");
    assertEquals(req.getLastHeader("Fintan").getValue(), "The Salmon of Knowledge");
    assertEquals(req.getURI().toString(), "http://www.google.com/?q=stuff");

    /* Verify the "aborted" status of the request */
    assertEquals(req.isAborted(), true);

    /* Read and verify the contents of the request */
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOUtils.copy(req.getEntity().getContent(), baos);
    assertEquals(baos.toString(), "{ \"name\" : \"Clark\" }");

    /* Verify Security was called with same element */
    assertTrue(capture2.hasCaptured());
    assertSame(capture2.getValue(), req);

    verify(delegate, securityProvider);
}

From source file:fedora.server.storage.DefaultExternalContentManager.java

/**
 * Initializes the Module based on configuration parameters. The
 * implementation of this method is dependent on the schema used to define
 * the parameter names for the role of//  ww  w  .jav a 2 s . c o m
 * <code>fedora.server.storage.DefaultExternalContentManager</code>.
 * 
 * @throws ModuleInitializationException
 *         If initialization values are invalid or initialization fails for
 *         some other reason.
 */
@Override
public void initModule() throws ModuleInitializationException {
    try {
        Server s_server = getServer();
        m_userAgent = getParameter("userAgent");
        if (m_userAgent == null) {
            m_userAgent = "Fedora";
        }

        fedoraServerPort = s_server.getParameter("fedoraServerPort");
        fedoraServerHost = s_server.getParameter("fedoraServerHost");
        fedoraServerRedirectPort = s_server.getParameter("fedoraRedirectPort");

        m_http = new WebClient();
        m_http.USER_AGENT = m_userAgent;

    } catch (Throwable th) {
        throw new ModuleInitializationException("[DefaultExternalContentManager] "
                + "An external content manager " + "could not be instantiated. The underlying error was a "
                + th.getClass().getName() + "The message was \"" + th.getMessage() + "\".", getRole());
    }
}

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StopDeviceTestSteps.java

@DomainStep("the stop device test response")
public boolean thenTheResponseShouldContain() {
    LOGGER.info("THEN: the stop device test response.");

    try {//www  .  ja va  2 s .  co  m
        Assert.assertNotNull("Response should not be null", this.response);
        Assert.assertNull("Throwable should be null", this.throwable);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }

    return true;
}

From source file:com.polyvi.xface.exceptionReporter.XCrashInfo.java

/**
 * ?/*w w w . j a  va  2 s .co  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.alliander.osgp.acceptancetests.adhocmanagement.ResumeScheduleSteps.java

@DomainStep("the resume schedule response request should return a resume schedule response with result (.*) and description (.*)")
public boolean thenTheResumeScheduleResponseRequestShouldReturn(final String result, final String description) {
    LOGGER.info(/*from w  w  w. j a  v  a2s.c om*/
            "THEN: \"the resume schedule response request should return a stop device test response with result {} and description {}\".",
            result, description);

    try {
        if ("NOT_OK".equals(result)) {
            Assert.assertNull("Set Schedule Response should be null", this.response);
            Assert.assertNotNull("Throwable should not be null", this.throwable);
            Assert.assertTrue("Throwable should contain a validation exception",
                    this.throwable.getCause() instanceof ValidationException);
        } else {

            Assert.assertNotNull("Response should not be null", this.response);

            final String expected = result.equals("NULL") ? null : result;
            final String actual = this.response.getResult().toString();

            Assert.assertTrue("Invalid result, found: " + actual + " , expected: " + expected,
                    (actual == null && expected == null) || actual.equals(expected));
        }
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }
    return true;
}

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StartDeviceTestSteps.java

@DomainStep("the start device test request is received")
public void whenTheRequestIsReceived() {
    LOGGER.info("WHEN: the start device test request is received.");

    try {/*w ww.ja va 2  s  .c o m*/
        this.startDeviceTestAsyncResponse = this.deviceInstallationEndpoint
                .startDeviceTest(this.organisation.getOrganisationIdentification(), this.request);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        this.throwable = t;
    }
}

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StartDeviceTestSteps.java

@DomainStep("the start device test response request is received")
public void whenTheStartDeviceTestResponseRequestIsReceived() {
    LOGGER.info("WHEN: \"the start device test response request is received\".");

    try {/*from w  w w.j av a2 s  .  c o  m*/
        this.response = this.deviceInstallationEndpoint.getStartDeviceTestResponse(
                this.organisation.getOrganisationIdentification(), this.startDeviceTestAsyncRequest);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        this.throwable = t;
    }
}

From source file:com.alliander.osgp.acceptancetests.adhocmanagement.SetRebootSteps.java

@DomainStep("the set reboot request is received")
public void whenTheSetRebootRequestIsReceived() {
    LOGGER.info("WHEN: \"the set reboot request is received\".");

    try {// ww  w .  ja  va2s  .c om
        this.setRebootAsyncResponse = this.adHocManagementEndpoint.setReboot(ORGANISATION_ID, this.request);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        this.throwable = t;
    }
}