List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:org.neo4j.ogm.persistence.authentication.AuthenticatingDriverTest.java
@Test public void testUnauthorizedDriver() { session = new SessionFactory(getBaseConfiguration().credentials("", "").build(), "dummy").openSession(); try (Transaction tx = session.beginTransaction()) { tx.commit();//w w w .j a va 2 s .co m fail("Driver should not have authenticated"); } catch (Exception rpe) { Throwable cause = rpe.getCause(); while (!(cause instanceof HttpResponseException)) { cause = cause.getCause(); } assertThat(cause.getMessage().startsWith("Invalid username or password")).isTrue(); } }
From source file:org.neo4j.ogm.persistence.authentication.AuthenticatingDriverTest.java
/** * @see issue #35// w ww. j a va2s . c o m */ @Test public void testInvalidCredentials() { session = new SessionFactory(getBaseConfiguration().credentials("neo4j", "invalid_password").build(), "dummy").openSession(); try (Transaction tx = session.beginTransaction()) { fail("Driver should not have authenticated"); } catch (Exception rpe) { Throwable cause = rpe.getCause(); while (!(cause instanceof HttpResponseException)) { cause = cause.getCause(); } assertThat(cause.getMessage()).isEqualTo("Invalid username or password."); } }
From source file:com.iisigroup.cap.report.AbstractReportHtmlService.java
@Override public ByteArrayOutputStream generateReport(Request request) throws CapException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer writer = null;/*from w ww. java 2 s .c o m*/ OutputStreamWriter wr = null; try { Template t = getFmConfg().getConfiguration().getTemplate(getReportDefinition() + REPORT_SUFFIX); Map<String, Object> reportData = execute(request); wr = new OutputStreamWriter(out, getSysConfig().getProperty(ReportParamEnum.defaultEncoding.toString(), DEFAULT_ENCORDING)); writer = new BufferedWriter(wr); t.process(reportData, writer); } catch (Exception e) { if (e.getCause() != null) { throw new CapException(e.getCause(), e.getClass()); } else { throw new CapException(e, e.getClass()); } } finally { IOUtils.closeQuietly(wr); IOUtils.closeQuietly(writer); IOUtils.closeQuietly(out); } return out; }
From source file:org.esigate.HttpErrorPage.java
public static CloseableHttpResponse generateHttpResponse(Exception exception) { if (exception instanceof HttpHostConnectException) { return generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, "Connection refused"); } else if (exception instanceof ConnectionPoolTimeoutException) { return generateHttpResponse(HttpStatus.SC_GATEWAY_TIMEOUT, "Connection pool timeout"); } else if (exception instanceof ConnectTimeoutException) { return generateHttpResponse(HttpStatus.SC_GATEWAY_TIMEOUT, "Connect timeout"); } else if (exception instanceof SocketTimeoutException) { return generateHttpResponse(HttpStatus.SC_GATEWAY_TIMEOUT, "Socket timeout"); } else if (exception instanceof SocketException) { return generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, "Socket Exception"); } else if (exception instanceof ClientProtocolException) { String message = exception.getMessage(); if (message == null && exception.getCause() != null) { message = exception.getCause().getMessage(); }/*from w w w . j a va2s .com*/ return generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, "Protocol error: " + message); } else { LOG.error("Error retrieving URL", exception); return generateHttpResponse(HttpStatus.SC_BAD_GATEWAY, "Error retrieving URL"); } }
From source file:rascal.AssertThrowsWithCause.java
@Override protected void checkExceptionExpectations(Exception actualException) { super.checkExceptionExpectations(actualException); if (actualException.getCause() == null || !getExpectedCauseException().isAssignableFrom(actualException.getCause().getClass())) { throw new AssertionFailedError(String.format("Should have thrown exception with cause [%s]", getExpectedCauseException().getName())); }// w w w . j a v a2s.c o m }
From source file:com.nandhootoo.services.DepartmentServiceImpl.java
public void deleteKey(Integer id) { try {/*from w w w. j a va2s . co m*/ String hqlDelete = "delete Department where id = :idString "; int deletedEntries = entityManager.createQuery(hqlDelete).setParameter("idString", id).executeUpdate(); } catch (Exception ex) { throw (RuntimeException) ex.getCause(); } }
From source file:com.nandhootoo.services.IssueServiceImpl.java
public void deleteKey(Integer id) { try {/*from www .j av a2 s . co m*/ String hqlDelete = "delete Issue where id = :idString "; int deletedEntries = entityManager.createQuery(hqlDelete).setParameter("idString", id).executeUpdate(); } catch (Exception ex) { throw (RuntimeException) ex.getCause(); } }
From source file:com.nandhootoo.services.NoteServiceImpl.java
public void deleteKey(Integer id) { try {/* w w w .j a va 2s. c o m*/ String hqlDelete = "delete Note where id = :idString "; int deletedEntries = entityManager.createQuery(hqlDelete).setParameter("idString", id).executeUpdate(); } catch (Exception ex) { throw (RuntimeException) ex.getCause(); } }
From source file:com.nandhootoo.services.ProductServiceImpl.java
public void deleteKey(Integer id) { try {/* ww w . j a v a2 s . c o m*/ String hqlDelete = "delete Product where id = :idString "; int deletedEntries = entityManager.createQuery(hqlDelete).setParameter("idString", id).executeUpdate(); } catch (Exception ex) { throw (RuntimeException) ex.getCause(); } }
From source file:com.nandhootoo.services.StatusServiceImpl.java
public void deleteKey(Integer id) { try {//from w w w.j a va 2 s. c om String hqlDelete = "delete Status where id = :idString "; int deletedEntries = entityManager.createQuery(hqlDelete).setParameter("idString", id).executeUpdate(); } catch (Exception ex) { throw (RuntimeException) ex.getCause(); } }