Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

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

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:freeipa.client.JSONRequestServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    String jsonRequest = req.getParameter("json");
    URL ipaUrl = new URL("https://vm-144.idm.lab.eng.brq.redhat.com/ipa/json");
    PrintWriter writer = resp.getWriter();

    writer.println("<html>");
    writer.println("  <head>");
    writer.println("    <title>Json request servlet</title>");
    writer.println("  </head>");
    writer.println("  <body>");
    writer.println("    <h1>JSON POST Test:</h1>");

    displayForm(writer);/*  w  w w. ja  va  2 s.c  o m*/
    if (jsonRequest == null) {
        try {
            LoginContext context = new LoginContext(SECURITY_DOMAIN);
            log.debug("Obtained LoginContext for '" + SECURITY_DOMAIN + "' security-domain.");

            context.login();
            writer.println("<h4>Authenticated</h4>");

            Subject subject = context.getSubject();
            KerberosHttpClient.makeCallWithKerberosAuthn(ipaUrl, subject, httpClient);
        } catch (Exception e) {
            // TODO - Output full exception detail.
            writer.println("<h5>Failed!</h5>");
            writer.print("<p>");
            writer.print(e.getClass().getName());
            writer.print(" - ");
            writer.print(e.getMessage());
            writer.println("</p>");

            log.error("testDomain Failed", e);
        }
    } else {
        testRequest(jsonRequest, writer);
    }

    writer.println("  </body>");
    writer.println("</html>");
    writer.flush();
}

From source file:org.nubomedia.marketplace.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ NotFoundException.class })
@ResponseStatus(value = HttpStatus.NOT_FOUND)
protected ResponseEntity<Object> handleNotFoundException(HttpServletRequest req, Exception e) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    Map body = new HashMap<>();
    body.put("error", "Not Found");
    body.put("exception", e.getClass().toString());
    body.put("message", e.getMessage());
    body.put("path", req.getRequestURI());
    body.put("status", HttpStatus.NOT_FOUND.value());
    body.put("timestamp", new Date().getTime());
    ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.NOT_FOUND);
    return responseEntity;
}

From source file:de.tu_dortmund.ub.data.dswarm.Export.java

@Override
public String call() {

    final String serviceName = config.getProperty(TPUStatics.SERVICE_NAME_IDENTIFIER);

    LOG.info(String.format("[%s] Starting 'XML-Export (Task)' ...", serviceName));

    try {//from ww  w .  j  a  v  a 2 s .c om

        TPUUtil.initSchemaIndices(serviceName, config);

        // export and save to results folder
        exportDataModel(exportDataModelID, optionalExportMimeType, optionalExportFileExtension, serviceName);

        return null;
    } catch (final Exception e) {

        final String message = String.format("[%s] Exporting and saving datamodel '%s' failed with a %s",
                serviceName, exportDataModelID, e.getClass().getSimpleName());
        LOG.error(message, e);

        throw new RuntimeException(message, e);
    }
}

From source file:com.github.tomakehurst.wiremock.HttpsAcceptanceTest.java

@Test
public void rejectsWithoutClientCertificate() {
    startServerEnforcingClientCert(KEY_STORE_PATH, TRUST_STORE_PATH, TRUST_STORE_PASSWORD);
    wireMockServer.stubFor(//from  ww w .  java 2 s  .c  o m
            get(urlEqualTo("/https-test")).willReturn(aResponse().withStatus(200).withBody("HTTPS content")));

    try {
        contentFor(url("/https-test")); // this lacks the required client certificate
        fail("Expected a SocketException or SSLHandshakeException to be thrown");
    } catch (Exception e) {
        assertThat(e.getClass().getName(),
                Matchers.anyOf(is(SocketException.class.getName()), is(SSLHandshakeException.class.getName())));
    }
}

From source file:ca.uhn.hl7v2.model.primitive.tests.CommonISTest.java

/**
 * Test for void set/getValue(String)//from w  w w .java  2s.com
 * table set
 */
@Test
public void testSetGetValueString() throws DataTypeException {
    class TestSpec {
        String value;
        Object outcome;
        IS commonIS;
        Exception exception = null;

        TestSpec(String value, Object outcome) throws DataTypeException {
            this.value = value;
            this.outcome = outcome;
            Message message = new GenericMessage.V25(new DefaultModelClassFactory());
            message.setValidationContext(new DefaultValidation());
            this.commonIS = new ca.uhn.hl7v2.model.v25.datatype.IS(message, 1);
            this.commonIS.setValue("IS");
        }

        public String toString() {
            return "[ " + value + " : " + (outcome != null ? outcome : "null")
                    + (exception != null ? " [ " + exception.toString() + " ]" : " ]");
        }

        public boolean executeTest() {
            try {
                commonIS.setValue(value);
                String retval = commonIS.getValue();
                if (retval != null) {
                    return retval.equals(outcome);
                } else {
                    return outcome == null;
                }
            } catch (Exception e) {
                if (e.getClass().equals(outcome)) {
                    return true;
                } else {
                    this.exception = e;
                    return (e.getClass().equals(outcome));
                }
            }
        }
    } //inner class

    TestSpec[] tests = { new TestSpec(null, null), new TestSpec("", ""), new TestSpec("\"\"", "\"\""),
            new TestSpec("ISString", "ISString"), new TestSpec(getString(200, 'a'), getString(200, 'a')),
            new TestSpec(getString(201, 'a'), DataTypeException.class), };

    ArrayList failedTests = new ArrayList();

    for (int i = 0; i < tests.length; i++) {
        if (!tests[i].executeTest())
            failedTests.add(tests[i]);
    }

    assertEquals("Failures: " + failedTests, 0, failedTests.size());
}

From source file:ca.uhn.hl7v2.model.primitive.tests.CommonIDTest.java

/**
 * Test for void set/getValue(String)/*  ww w .  j a  va2 s  .  c  om*/
 * table set
 */
@Test
public void testSetGetValueString() throws DataTypeException {
    class TestSpec {
        String value;
        Object outcome;
        ID commonID;
        Exception exception = null;

        TestSpec(String value, Object outcome) throws DataTypeException {
            this.value = value;
            this.outcome = outcome;
            Message message = new GenericMessage.V25(new DefaultModelClassFactory());
            message.setValidationContext(new DefaultValidation());
            this.commonID = new ca.uhn.hl7v2.model.v25.datatype.ID(message, 1);
            this.commonID.setValue("ID");
        }

        public String toString() {
            return "[ " + value + " : " + (outcome != null ? outcome : "null")
                    + (exception != null ? " [ " + exception.toString() + " ]" : " ]");
        }

        public boolean executeTest() {
            try {
                commonID.setValue(value);
                String retval = commonID.getValue();
                if (retval != null) {
                    return retval.equals(outcome);
                } else {
                    return outcome == null;
                }
            } catch (Exception e) {
                if (e.getClass().equals(outcome)) {
                    return true;
                } else {
                    this.exception = e;
                    return (e.getClass().equals(outcome));
                }
            }
        }
    } //inner class

    TestSpec[] tests = { new TestSpec(null, null), new TestSpec("", ""), new TestSpec("\"\"", "\"\""),
            new TestSpec("IDString", "IDString"), new TestSpec(getString(200, 'a'), getString(200, 'a')),
            new TestSpec(getString(201, 'a'), DataTypeException.class), };

    ArrayList failedTests = new ArrayList();

    for (int i = 0; i < tests.length; i++) {
        if (!tests[i].executeTest())
            failedTests.add(tests[i]);
    }

    assertEquals("Failures: " + failedTests, 0, failedTests.size());
}

From source file:crossspectrumapp.CrossSpectrumApp.java

private void plotData(double[] frequency, double[] power, double[] phase, String title, String subTitleText1,
        String subTitleText2) throws WebUtilException {
    XYSeries asdSeries = new XYSeries("asd");
    XYSeries phiSeries = new XYSeries("phase");

    for (int i = 1; i < frequency.length; i++) {
        double f = frequency[i];
        double pwr = power[i];
        double phi = phase[i];
        asdSeries.add(f, pwr);//from   w  w  w  .j  a  v  a2  s  .c  om
        phiSeries.add(f, phi);
    }

    XYSeriesCollection asdCollection = new XYSeriesCollection();
    asdCollection.addSeries(asdSeries);
    XYSeriesCollection phiCollection = new XYSeriesCollection();
    phiCollection.addSeries(phiSeries);

    // create the chart
    XYItemRenderer asdRenderer = new StandardXYItemRenderer();
    LogAxis asdAxis = new LogAxis("ASD counts/ \u221AHz");
    XYPlot asdSubplot = new XYPlot(asdCollection, null, asdAxis, asdRenderer);
    asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    XYItemRenderer phiRenderer = new StandardXYItemRenderer();
    NumberAxis phiAxis = new NumberAxis("Phase degrees");
    XYPlot phiSubplot = new XYPlot(phiCollection, null, phiAxis, phiRenderer);
    asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new LogAxis("Frequency (Hz)"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(asdSubplot, 2);
    plot.add(phiSubplot, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    Title subTitle = new TextTitle(subTitleText1);
    chart.addSubtitle(subTitle);
    subTitle = new TextTitle(subTitleText2);
    chart.addSubtitle(subTitle);
    ChartPanel panel = new ChartPanel(chart, true, true, true, false, true);
    panel.setPreferredSize(new java.awt.Dimension(cscl.getOutX(), cscl.getOutY()));

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(cscl.getOfileName());
        ChartUtilities.writeChartAsPNG(fos, chart, cscl.getOutX(), cscl.getOutY());
        fos.close();
        fos = null;
    } catch (Exception ex) {
        throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage());
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
        } catch (Exception ex) {
            throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage());
        }
    }

}

From source file:ca.uhn.hl7v2.model.primitive.tests.CommonIDTest.java

/**
 * Test for void set/getValue(int, String)
 */// w w  w.j av  a  2 s  .c om
@Test
public void testSetGetValueStringAndTable() throws DataTypeException {
    class TestSpec {
        String value;
        int table;
        Object outcome;
        Exception exception = null;

        TestSpec(int table, String value, Object outcome) {
            this.value = value;
            this.table = table;
            this.outcome = outcome;
        }

        public String toString() {
            return "[ " + table + " " + value + " : " + (outcome != null ? outcome : "null")
                    + (exception != null ? " [ " + exception.toString() + " ]" : " ]");
        }

        public boolean executeTest() {
            Message message = new GenericMessage.V25(new DefaultModelClassFactory());
            message.setValidationContext(new DefaultValidation());
            ID id = new ca.uhn.hl7v2.model.v25.datatype.ID(message, table);
            try {
                id.setTable(table);
                id.setValue(value);
                String retval = id.getValue();
                if (retval != null) {
                    return retval.equals(outcome);
                } else {
                    return outcome == null;
                }
            } catch (Exception e) {
                if (e.getClass().equals(outcome)) {
                    return true;
                } else {
                    this.exception = e;
                    return (e.getClass().equals(outcome));
                }
            }
        }
    } //inner class

    TestSpec[] tests = { new TestSpec(2, null, null), new TestSpec(2, "", ""), new TestSpec(-1, "\"\"", "\"\""),
            new TestSpec(0, "\"\"", "\"\""), new TestSpec(2, "IDString", "IDString"),
            new TestSpec(2, getString(200, 'a'), getString(200, 'a')),
            new TestSpec(2, getString(201, 'a'), DataTypeException.class), };

    ArrayList failedTests = new ArrayList();

    for (int i = 0; i < tests.length; i++) {
        if (!tests[i].executeTest())
            failedTests.add(tests[i]);
    }

    assertEquals("Failures: " + failedTests, 0, failedTests.size());
}

From source file:ca.uhn.hl7v2.model.primitive.tests.CommonISTest.java

/**
 * Test for void set/getValue(int, String)
 *///from w  ww  .j a  va2s . c  om
@Test
public void testSetGetValueStringAndTable() throws DataTypeException {
    class TestSpec {
        String value;
        int table;
        Object outcome;
        Exception exception = null;

        TestSpec(int table, String value, Object outcome) {
            this.value = value;
            this.table = table;
            this.outcome = outcome;
        }

        public String toString() {
            return "[ " + table + " " + value + " : " + (outcome != null ? outcome : "null")
                    + (exception != null ? " [ " + exception.toString() + " ]" : " ]");
        }

        public boolean executeTest() {
            Message message = new GenericMessage.V25(new DefaultModelClassFactory());
            message.setValidationContext(new DefaultValidation());
            IS is = new ca.uhn.hl7v2.model.v25.datatype.IS(message, 0);
            try {
                is.setTable(table);
                is.setValue(value);
                String retval = is.getValue();
                if (retval != null) {
                    return retval.equals(outcome);
                } else {
                    return outcome == null;
                }
            } catch (Exception e) {
                if (e.getClass().equals(outcome)) {
                    return true;
                } else {
                    this.exception = e;
                    return (e.getClass().equals(outcome));
                }
            }
        }
    } //inner class

    TestSpec[] tests = { new TestSpec(2, null, null), new TestSpec(2, "", ""), new TestSpec(-1, "\"\"", "\"\""),
            new TestSpec(0, "\"\"", "\"\""), new TestSpec(2, "ISString", "ISString"),
            //new TestSpec(-1, "ISString", DataTypeException.class),
            new TestSpec(2, getString(200, 'a'), getString(200, 'a')),
            new TestSpec(2, getString(201, 'a'), DataTypeException.class), };

    ArrayList failedTests = new ArrayList();

    for (int i = 0; i < tests.length; i++) {
        if (!tests[i].executeTest())
            failedTests.add(tests[i]);
    }

    assertEquals("Failures: " + failedTests, 0, failedTests.size());
}

From source file:com.clustercontrol.logfile.session.MonitorLogfileControllerBean.java

/**
 * /*from   w w  w.java  2 s .com*/
 * <??> ???Agent????????
 * <??> ???Agent?????????
 * 
 * facilityID??????
 * withCalendartrue???MonitorInfo?calendarDTO????
 * 
 * 
 * @return Object?2?
 * @throws HinemosUnknown
 * @throws MonitorNotFound
 * 
 */
public ArrayList<MonitorInfo> getLogfileListForFacilityId(String facilityId, boolean withCalendar)
        throws MonitorNotFound, HinemosUnknown {
    ArrayList<MonitorInfo> ret = new ArrayList<MonitorInfo>();
    JpaTransactionManager jtm = null;
    try {
        jtm = new JpaTransactionManager();
        jtm.begin();

        // ?????????????????????????
        // (?????????????????????????)
        ArrayList<MonitorInfo> monitorList = getCache();

        for (MonitorInfo monitorInfo : monitorList) {
            String scope = monitorInfo.getFacilityId();
            ArrayList<String> facilityIdList = new RepositoryControllerBean().getExecTargetFacilityIdList(scope,
                    monitorInfo.getOwnerRoleId());
            if (facilityIdList != null && facilityIdList.contains(facilityId)) {
                if (withCalendar) {
                    String calendarId = monitorInfo.getCalendarId();
                    try {
                        CalendarInfo calendar = new CalendarControllerBean().getCalendarFull(calendarId);
                        monitorInfo.setCalendar(calendar);
                    } catch (Exception e) {
                        m_log.warn("getLogfileList() : " + e.getClass().getSimpleName() + ", " + e.getMessage(),
                                e);
                        throw new HinemosUnknown(e.getMessage(), e);
                    }
                }
                ret.add(monitorInfo);
            }
        }

        jtm.commit();
    } catch (HinemosUnknown e) {
        jtm.rollback();
        throw e;
    } catch (Exception e) {
        m_log.warn("getLogfileListForFacilityId() : " + e.getClass().getSimpleName() + ", " + e.getMessage(),
                e);
        if (jtm != null)
            jtm.rollback();
        throw new HinemosUnknown(e.getMessage(), e);
    } finally {
        if (jtm != null)
            jtm.close();
    }

    return ret;
}