List of usage examples for java.lang Exception getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.qrmedia.commons.persistence.hibernate.clone.HibernateEntityBeanCloner.java
public boolean visitNode(EntityPreserveIdFlagPair entityPreserveIdFlagPair, GraphTraverser<EntityPreserveIdFlagPair, IdentityHashMap<Object, Object>> graphTraverser, IdentityHashMap<Object, Object> entityClones) { if (!(graphTraverser instanceof HibernateEntityGraphCloner)) { throw new IllegalArgumentException( graphTraverser + " is not an instance of HibernateEntityGraphCloner"); }/*from w ww.j a va 2 s . c o m*/ Object entity = entityPreserveIdFlagPair.getEntity(); Object clone; try { // ensure the "real" class is instantiated if the current instance is a CGLIB class clone = getEntityClass(entity).newInstance(); for (String targetedFieldName : getTargetedFieldNames(entity, entityPreserveIdFlagPair.isPreserveId())) { cloneProperty(entity, clone, targetedFieldName, (HibernateEntityGraphCloner) graphTraverser); } } catch (Exception exception) { throw new AssertionError("Unable to clone entity " + entity + " due to " + exception.getClass().getSimpleName() + ": " + exception.getMessage()); } entityClones.put(entity, clone); return true; }
From source file:com.netcrest.pado.tools.pado.command.show.java
private void show_col(CommandLine commandLine) throws Exception { if (commandLine.getOptionValue("col") == null) { PadoShell.printlnError(this, "Must specify <collection entry print count>. Current count is " + padoShell.getCollectionEntryPrintCount()); return;//w ww.j a va 2s.co m } try { int count = Integer.parseInt(commandLine.getOptionValue("col")); padoShell.setCollectionEntryPrintCount(count); } catch (Exception ex) { PadoShell.printlnError(this, ex.getClass().getSimpleName() + ": " + ex.getMessage()); } }
From source file:net.sourceforge.floggy.persistence.fr2935390.FR2935390Test.java
/** * DOCUMENT ME!/* ww w . jav a2 s . co m*/ * * @throws Exception DOCUMENT ME! */ public void testDoesNotExistIndexName() throws Exception { try { IndexFilter indexFilter = new IndexFilter("color", "green"); manager.find(Bird.class, indexFilter, false); fail("It must throw a FloggyException"); } catch (Exception ex) { assertEquals(FloggyException.class, ex.getClass()); } finally { } }
From source file:at.ac.tuwien.dsg.comot.m.common.event.state.ExceptionMessage.java
public ExceptionMessage(String serviceId, String origin, Long time, String eventCauseId, Exception exception) { super();// ww w. j av a 2 s. com Throwable root = ExceptionUtils.getRootCause(exception); String type; String message; String details; if (root == null) { type = exception.getClass().getName(); message = exception.getMessage(); details = ExceptionUtils.getStackTrace(exception); } else { type = root.getClass().getName(); message = root.getMessage(); details = ExceptionUtils.getStackTrace(root); } this.origin = origin; this.type = type; this.message = message; this.details = details; this.serviceId = serviceId; this.time = time; this.eventCauseId = eventCauseId; }
From source file:com.manning.blogapps.chapter11.PlanetManagerImpl.java
protected Set getNewEntriesRemote(PlanetSubscriptionData sub, FeedFetcher feedFetcher, FeedFetcherCache feedInfoCache) throws Exception { Set newEntries = new TreeSet(); SyndFeed feed = null;/* www. j a v a 2 s .c o m*/ URL feedUrl = null; Date lastUpdated = new Date(); try { feedUrl = new URL(sub.getFeedUrl()); logger.debug("Get feed from cache " + sub.getFeedUrl()); feed = feedFetcher.retrieveFeed(feedUrl); SyndFeedInfo feedInfo = feedInfoCache.getFeedInfo(feedUrl); if (feedInfo.getLastModified() != null) { long lastUpdatedLong = ((Long) feedInfo.getLastModified()).longValue(); if (lastUpdatedLong != 0) { lastUpdated = new Date(lastUpdatedLong); } } Thread.sleep(100); // be nice } catch (Exception e) { logger.warn( "ERROR parsing " + sub.getFeedUrl() + " : " + e.getClass().getName() + " : " + e.getMessage()); logger.debug(e); return newEntries; // bail out } if (lastUpdated != null && sub.getLastUpdated() != null) { Calendar feedCal = Calendar.getInstance(); feedCal.setTime(lastUpdated); Calendar subCal = Calendar.getInstance(); subCal.setTime(sub.getLastUpdated()); if (!feedCal.after(subCal)) { if (logger.isDebugEnabled()) { String msg = MessageFormat.format(" Skipping ({0} / {1})", new Object[] { lastUpdated, sub.getLastUpdated() }); logger.debug(msg); } return newEntries; // bail out } } if (feed.getPublishedDate() != null) { sub.setLastUpdated(feed.getPublishedDate()); saveSubscription(sub); } // Kludge for Feeds without entry dates: most recent entry is given // feed's last publish date (or yesterday if none exists) and earler // entries are placed at once day intervals before that. Calendar cal = Calendar.getInstance(); if (sub.getLastUpdated() != null) { cal.setTime(sub.getLastUpdated()); } else { cal.setTime(new Date()); cal.add(Calendar.DATE, -1); } // Populate subscription object with new entries Iterator entries = feed.getEntries().iterator(); while (entries.hasNext()) { try { SyndEntry romeEntry = (SyndEntry) entries.next(); PlanetEntryData entry = new PlanetEntryData(feed, romeEntry, sub); if (entry.getPublished() == null) { logger.debug("No published date, assigning fake date for " + feedUrl); entry.setPublished(cal.getTime()); } if (entry.getPermalink() == null) { logger.warn("No permalink, rejecting entry from " + feedUrl); } else { saveEntry(entry); newEntries.add(entry); } cal.add(Calendar.DATE, -1); } catch (Exception e) { logger.error("ERROR processing subscription entry", e); } } return newEntries; }
From source file:ca.uhn.hl7v2.llp.tests.MinLLPWriterTest.java
/** * Testing writeMessage with various messages. *//* w w w .j av a 2s . com*/ @Test public void testWriteMessages() { class TestSpec { String writeMessage; String recvMessage; Object outcome; TestSpec(String message, Object outcome) { if (message != null) this.writeMessage = message; else this.writeMessage = null; this.outcome = outcome; } public String toString() { return "[" + (writeMessage != null ? writeMessage.toString() : "null") + ":" + outcome + "]"; } public boolean executeTest() { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); MinLLPWriter minLLPWriter = new MinLLPWriter(outputStream); minLLPWriter.writeMessage(writeMessage); return outputStream.toString().equals(outcome); } catch (Exception e) { return (e.getClass().equals(outcome)); } } }// inner class TestSpec[] tests = { new TestSpec(null, NullPointerException.class), new TestSpec("", START_MESSAGE + "" + END_MESSAGE + LAST_CHARACTER), new TestSpec(message, START_MESSAGE + message + END_MESSAGE + LAST_CHARACTER), }; ArrayList failedTests = new ArrayList(); for (int i = 0; i < tests.length; i++) { if (!tests[i].executeTest()) failedTests.add(tests[i]); } assertEquals("readMessages failures: " + failedTests, 0, failedTests.size()); }
From source file:ca.uhn.hl7v2.llp.tests.MinLLPReaderTest.java
/** * Testing readMessage with well and malformed llp encoded input messages. *///w w w . j a v a 2s . c o m @Test public void testReadMessages() { class TestSpec { byte[] sendMessage; Object outcome; TestSpec(String message, Object outcome) { if (message != null) this.sendMessage = message.getBytes(); else this.sendMessage = null; this.outcome = outcome; } public String toString() { return "[" + (sendMessage != null ? sendMessage.toString() : "null") + ":" + outcome + "]"; } public boolean executeTest() { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(this.sendMessage); MinLLPReader reader = new MinLLPReader(inputStream); String recvMessage = reader.getMessage(); return recvMessage.equals(outcome); } catch (Exception e) { return (e.getClass().equals(outcome)); } } }// inner class TestSpec[] tests = { new TestSpec(null, NullPointerException.class), new TestSpec(START_MESSAGE + message + END_MESSAGE + LAST_CHARACTER, message), new TestSpec(START_MESSAGE + message + END_MESSAGE, LLPException.class), new TestSpec(START_MESSAGE + message, LLPException.class), new TestSpec(Integer.toString(START_MESSAGE), LLPException.class), new TestSpec(message, LLPException.class), new TestSpec(message + END_MESSAGE + LAST_CHARACTER, LLPException.class), new TestSpec(Integer.toString(END_MESSAGE) + Integer.toString(LAST_CHARACTER), LLPException.class), new TestSpec(Integer.toString(LAST_CHARACTER), LLPException.class), new TestSpec(Integer.toString(START_MESSAGE) + Integer.toString(END_MESSAGE) + Integer.toString(LAST_CHARACTER), LLPException.class), }; ArrayList failedTests = new ArrayList(); for (int i = 0; i < tests.length; i++) { if (!tests[i].executeTest()) failedTests.add(tests[i]); } assertEquals("readMessages failures: " + failedTests, 0, failedTests.size()); }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.HubLocationProvider.java
@Periodic(millisBetweenUpdates = 1000 * 60) public void pollActiveSystems() { if (!enabled) return;/*from w ww . j a v a2s.co m*/ try { Gson gson = new Gson(); URL url = new URL(systemsUrl); HubSystemMsg[] msgs = gson.fromJson(new InputStreamReader(url.openStream()), HubSystemMsg[].class); NeptusLog.pub().info(" through HTTP: " + systemsUrl); for (HubSystemMsg m : msgs) { AssetPosition pos = new AssetPosition(m.name, m.coordinates[0], m.coordinates[1]); pos.setType(IMCUtils.getSystemType(m.imcid)); pos.setTimestamp(HubIridiumMessenger.stringToDate(m.updated_at).getTime()); pos.setSource(getName()); if (pos.getAssetName().equals("hermes")) pos.setType("ASV"); if (!m.pos_error_class.isEmpty()) { pos.putExtra("Loc. Class", m.pos_error_class); } parent.addAssetPosition(pos); NeptusLog.pub().info("Received HUB position update for " + m.name + ": " + pos.getLoc() + " @ " + new Date(pos.getTimestamp())); } } catch (Exception e) { e.printStackTrace(); NeptusLog.pub().error(e); parent.postNotification(Notification .error("Situation Awareness", e.getClass().getSimpleName() + " while polling device updates from HUB.") .requireHumanAction(false)); } }
From source file:de.tudarmstadt.lt.lm.web.servlet.LanguageModelProviderServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); resp.setContentType("text/html; charset=utf-8"); PrintWriter w = new PrintWriter(resp.getWriter()); String plaintext = req.getParameter("plaintext"); String crawl_uri = req.getParameter("crawluri"); String lm_key = req.getParameter("lm"); String inputtype = req.getParameter("inputtype"); boolean show_all_ngrams = req.getParameter("showall") != null; try {// w w w .ja va 2 s .co m if (lm_key == null) // no parameter set show_available(w); else show(inputtype, lm_key, plaintext, crawl_uri, show_all_ngrams, w); } catch (Exception e) { w.format("Error %s: %s.", e.getClass().getSimpleName(), e.getMessage()); } w.flush(); w.close(); }
From source file:org.zkybase.kite.circuitbreaker.CircuitBreakerTemplate.java
/** * <p>//from w ww .j av a 2s. co m * Executes the specified action inside the circuit breaker. * </p> * * @param <T> * action return type * @param action * action to execute * @return result of the action * @throws CircuitOpenException * if the breaker is in the open state * @throws Exception * exception thrown by the action, if any */ public <T> T execute(CircuitBreakerCallback<T> action) throws Exception { final State currState = getState(); switch (currState) { case CLOSED: try { T value = action.doInCircuitBreaker(); this.exceptionCount.set(0); return value; } catch (Exception e) { if (isHandledException(e.getClass()) && exceptionCount.incrementAndGet() >= exceptionThreshold) { trip(); } // In any event, throw the exception. throw e; } case OPEN: throw new CircuitOpenException(); case HALF_OPEN: try { T value = action.doInCircuitBreaker(); reset(); return value; } catch (Exception e) { if (isHandledException(e.getClass())) { trip(); } throw e; } default: // This shouldn't happen... throw new IllegalStateException("Unknown state: " + currState); } }