List of usage examples for java.lang RuntimeException getMessage
public String getMessage()
From source file:com.github.carlomicieli.rest.resources.BrandsResource.java
/** * /*from w w w . j ava 2s . com*/ * @param brandId */ @DELETE @Path("/{brandId}") public void delete(@PathParam("brandId") long brandId) { log.info("DELETE /brands/{}", brandId); try { brandService.remove(new Brand(brandId)); } catch (RuntimeException ex) { log.error(ex.getMessage()); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } }
From source file:com.github.carlomicieli.rest.resources.RailwaysResource.java
/** * /*from w w w. jav a2 s . co m*/ * @param railwayId */ @DELETE @Path("/{railwayId}") public void delete(@PathParam("railwayId") long railwayId) { log.info("DELETE /railways/{}", railwayId); try { railwayService.remove(new Railway(railwayId)); } catch (RuntimeException ex) { log.error(ex.getMessage()); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } }
From source file:org.snaker.engine.access.spring.SpringJdbcAccess.java
@Override public <T> List<T> queryList(Page<T> page, Class<T> T, String sql, Object... args) { String countSQL = "select count(1) from (" + sql + ") c "; String querySQL = sql;/* w ww .jav a2 s. co m*/ if (page.isOrderBySetted()) { querySQL = sql + StringHelper.buildPageOrder(page.getOrder(), page.getOrderBy()); } //???pageSize if (page.getPageSize() != Page.NON_PAGE) { querySQL = getDialect().getPageSql(querySQL, page.getPageNo(), page.getPageSize()); } if (log.isDebugEnabled()) { log.debug("countSQL=\n" + countSQL); log.debug("querySQL=\n" + querySQL); } List<T> tasks = null; long count = 0L; try { count = template.queryForLong(countSQL, args); tasks = template.query(querySQL, args, new BeanPropertyRowMapper<T>(T)); if (tasks == null) tasks = Collections.emptyList(); page.setResult(tasks); page.setTotalCount(ClassHelper.castLong(count)); return page.getResult(); } catch (RuntimeException e) { log.error("" + e.getMessage()); return Collections.emptyList(); } }
From source file:com.opera.core.systems.SelftestTest.java
@Test public void respectsTimeout() { driver.manage().timeouts().selftestTimeout(10, TimeUnit.MILLISECONDS); try {/* w w w .j a v a 2 s .c o m*/ driver.selftest(ImmutableSet.of("about")); fail("Expected selftest to time out"); } catch (RuntimeException e) { assertThat(e, is(instanceOf(ResponseNotReceivedException.class))); assertThat(e.getMessage(), containsString("No response in a timely fashion")); } }
From source file:edu.duke.cabig.c3pr.domain.scheduler.runtime.job.ScheduledJob.java
/** * @author Vinay Gangoli/* w ww .j a va2s .c o m*/ * All jobs must extend this class. this handles the hibernate session scope for the jobs. */ public void execute(JobExecutionContext context) throws JobExecutionException { logger.debug("Executing Scheduled Job"); WebRequest webRequest = new ServletWebRequest(new MockHttpServletRequest()); OpenSessionInViewInterceptor interceptor = null; try { // init the member variables scheduler = context.getScheduler(); jobDetail = context.getJobDetail(); applicationContext = (ApplicationContext) scheduler.getContext().get("applicationContext"); plannedNotificationDao = (PlannedNotificationDao) applicationContext.getBean("plannedNotificationDao"); recipientScheduledNotificationDao = (RecipientScheduledNotificationDao) applicationContext .getBean("recipientScheduledNotificationDao"); interceptor = (OpenSessionInViewInterceptor) applicationContext.getBean("openSessionInViewInterceptor"); interceptor.preHandle(webRequest); JobDataMap jobDataMap = jobDetail.getJobDataMap(); Integer plannedNotificationId = jobDataMap.getInt("plannedNotificationId"); //PlannedNotification plannedNotification = plannedNotificationDao.getInitializedPlannedNotificationById(plannedNotificationId); PlannedNotification plannedNotification = plannedNotificationDao.getById(plannedNotificationId); setAuditInfo(); RecipientScheduledNotification recipientScheduledNotification = null; if (jobDataMap.containsKey("recipientScheduledNotificationId")) { Integer recipientScheduledNotificationId = jobDataMap.getInt("recipientScheduledNotificationId"); //recipientScheduledNotification = recipientScheduledNotificationDao.getInitializedRecipientScheduledNotificationById(recipientScheduledNotificationId); recipientScheduledNotification = recipientScheduledNotificationDao .getById(recipientScheduledNotificationId); } if (plannedNotification.getEventName() != null) { try { processJob(jobDataMap, recipientScheduledNotification, plannedNotification); } catch (JobExecutionException jee) { logger.error(jee.getMessage()); } } //try commenting out the postHandle ...might not be necessary! interceptor.postHandle(webRequest, null); } catch (RuntimeException exception) { logger.error(exception.getMessage()); // Get cause if present Throwable t = ((HibernateJdbcException) exception).getRootCause(); while (t != null) { //t = t.getCause(); } catch (Exception e) { logger.error("execution of job failed", e); } finally { interceptor.afterCompletion(webRequest, null); } }
From source file:com.thoughtworks.go.server.database.H2DatabaseTest.java
@Test void shouldThrowUpWhenBackupFails() throws Exception { File destDir = new File("."); SystemEnvironment systemEnvironment = mock(SystemEnvironment.class); Database database = new H2Database(systemEnvironment); Database spy = spy(database);/*from ww w . j av a 2 s. c om*/ BasicDataSource dataSource = mock(BasicDataSource.class); Connection connection = mock(Connection.class); Statement statement = mock(Statement.class); doReturn(dataSource).when(spy).createDataSource(); when(dataSource.getConnection()).thenReturn(connection); when(connection.createStatement()).thenReturn(statement); when(statement.execute(anyString())).thenThrow(new SQLException("i failed")); try { spy.backup(destDir); } catch (RuntimeException e) { assertThat(e.getMessage(), is("i failed")); } verify(statement).execute(anyString()); }
From source file:org.elasticsearch.client.SyncResponseListenerTests.java
public void testExceptionIsWrapped() throws Exception { RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000); //we just need any checked exception URISyntaxException exception = new URISyntaxException("test", "test"); syncResponseListener.onFailure(exception); try {/*from w w w . j av a2 s . c o m*/ syncResponseListener.get(); fail("get should have failed"); } catch (RuntimeException e) { assertEquals("error while performing request", e.getMessage()); assertSame(exception, e.getCause()); } }
From source file:de.michaeltamm.W3cMarkupValidator.java
/** * Validates the given <code>html</code>. * * @param html a complete HTML document//from w w w . j av a 2 s .c o m */ public W3cMarkupValidationResult validate(String html) { if (_httpClient == null) { final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); _httpClient = new HttpClient(connectionManager); } final PostMethod postMethod = new PostMethod(_checkUrl); final Part[] data = { // The HTML to validate ... new StringPart("fragment", html, "UTF-8"), new StringPart("prefill", "0", "UTF-8"), new StringPart("doctype", "Inline", "UTF-8"), new StringPart("prefill_doctype", "html401", "UTF-8"), // List Messages Sequentially | Group Error Messages by Type ... new StringPart("group", "0", "UTF-8"), // Show source ... new StringPart("ss", "1", "UTF-8"), // Verbose Output ... new StringPart("verbose", "1", "UTF-8"), }; postMethod.setRequestEntity(new MultipartRequestEntity(data, postMethod.getParams())); try { final int status = _httpClient.executeMethod(postMethod); if (status != 200) { throw new RuntimeException(_checkUrl + " responded with " + status); } final String pathPrefix = _checkUrl.substring(0, _checkUrl.lastIndexOf('/') + 1); final String resultPage = getResponseBody(postMethod).replace("\"./", "\"" + pathPrefix) .replace("src=\"images/", "src=\"" + pathPrefix + "images/") .replace("<script type=\"text/javascript\" src=\"loadexplanation.js\">", "<script type=\"text/javascript\" src=\"" + pathPrefix + "loadexplanation.js\">"); return new W3cMarkupValidationResult(resultPage); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } finally { postMethod.releaseConnection(); } }
From source file:cz.fi.muni.pa165.dao.PrintedBookDAOImpl.java
@Override public List<PrintedBook> findPrintedBooksByState(Book book, Boolean state) { if (book == null) { throw new IllegalArgumentException("Book null"); }/*from w ww . j a v a 2s . c om*/ if (state == null) { throw new IllegalArgumentException("State null"); } try { final Query query = em .createQuery("SELECT m FROM PrintedBook as m WHERE m.book.idBook = :i AND m.state = :s"); query.setParameter("i", book.getIdBook()); query.setParameter("s", state); return query.getResultList(); } catch (RuntimeException E) { throw new DAException(E.getMessage()); } }
From source file:cz.fi.muni.pa165.dao.PrintedBookDAOImpl.java
@Override public List<PrintedBook> findPrintedBooksByLoan(Book book, Loan loan) { if (book == null) { throw new IllegalArgumentException("Book null"); }/*from w w w . j a va2 s. c o m*/ if (loan == null) { throw new IllegalArgumentException("Loan null"); } try { final Query query = em .createQuery("SELECT m FROM PrintedBook as m WHERE m.book.idBook = :i AND m.loan.idLoan = :l"); query.setParameter("i", book.getIdBook()); query.setParameter("l", loan.getIdLoan()); return query.getResultList(); } catch (RuntimeException E) { throw new DAException(E.getMessage()); } }