@Override public void handleException(Throwable t, Record record) { if (t instanceof Error) { throw (Error) t; } throw new MorphlineRuntimeException(t); }
@Test public void testJavaRuntimeException() throws Exception { morphline = createMorphline("test-morphlines/javaRuntimeException"); Record record = new Record(); startSession(); assertEquals(1, collector.getNumStartEvents()); try { morphline.process(record); fail(); } catch (MorphlineRuntimeException e) { assertTrue(e.getMessage().startsWith("Cannot execute script")); } assertEquals(Lists.newArrayList(), collector.getRecords()); }
@Test public void testTryRulesFailTwice() throws Exception { morphline = createMorphline("test-morphlines/tryRulesFailTwice"); Record record = new Record(); record.put("first_name", "Nadja"); List<Record> expectedList = Lists.newArrayList(); startSession(); assertEquals(1, collector.getNumStartEvents()); try { morphline.process(record); fail(); } catch (MorphlineRuntimeException e) { assertTrue(e.getMessage().startsWith("tryRules command found no successful rule for record")); } assertEquals(expectedList, collector.getRecords()); }
@Override public void handleException(Throwable t, Record record) { if (t instanceof Error) { throw (Error) t; } throw new MorphlineRuntimeException(t); }
@Override protected boolean doProcess(Record inputRecord, InputStream stream) throws IOException { try { return doProcess2(inputRecord, stream); } catch (SAXNotRecognizedException e) { throw new MorphlineRuntimeException(e); } catch (SAXNotSupportedException e) { throw new MorphlineRuntimeException(e); } catch (SAXException e) { throw new MorphlineRuntimeException(e); } }
@Override protected final boolean doProcess(Record inputRecord, InputStream stream) throws IOException { try { return doProcess2(inputRecord, stream); } catch (SaxonApiException e) { throw new MorphlineRuntimeException(e); } catch (XMLStreamException e) { throw new MorphlineRuntimeException(e); } }
protected Charset detectCharset(Record record, Charset charset) { if (charset != null) { return charset; } List charsets = record.get(Fields.ATTACHMENT_CHARSET); if (charsets.size() == 0) { // TODO try autodetection (AutoDetectReader) throw new MorphlineRuntimeException("Missing charset for record: " + record); } String charsetName = (String) charsets.get(0); return Charset.forName(charsetName); }
private Schema getSchema(GenericContainer datum, Schema lastSchema) { Schema schema = datum.getSchema(); if (lastSchema != null && lastSchema != schema) { throw new MorphlineRuntimeException("Schemas must be identical: " + schema + ", lastSchema: " + lastSchema); } return schema; }
protected Charset detectCharset(Record record, Charset charset) { if (charset != null) { return charset; } List charsets = record.get(Fields.ATTACHMENT_CHARSET); if (charsets.size() == 0) { // TODO try autodetection (AutoDetectReader) throw new MorphlineRuntimeException("Missing charset for record: " + record); } String charsetName = (String) charsets.get(0); return Charset.forName(charsetName); }
private Schema getSchema(GenericContainer datum, Schema lastSchema) { Schema schema = datum.getSchema(); if (lastSchema != null && lastSchema != schema) { throw new MorphlineRuntimeException("Schemas must be identical: " + schema + ", lastSchema: " + lastSchema); } return schema; }
loader.beginTransaction(); } catch (SolrServerException e) { throw new MorphlineRuntimeException(e); } catch (IOException e) { throw new MorphlineRuntimeException(e); loader.commitTransaction(); } catch (SolrServerException e) { throw new MorphlineRuntimeException(e); } catch (IOException e) { throw new MorphlineRuntimeException(e); loader.rollbackTransaction(); } catch (SolrServerException e) { throw new MorphlineRuntimeException(e); } catch (IOException e) { throw new MorphlineRuntimeException(e); loader.shutdown(); } catch (SolrServerException e) { throw new MorphlineRuntimeException(e); } catch (IOException e) { throw new MorphlineRuntimeException(e);
loader.beginTransaction(); } catch (SolrServerException e) { throw new MorphlineRuntimeException(e); } catch (IOException e) { throw new MorphlineRuntimeException(e); loader.commitTransaction(); } catch (SolrServerException e) { throw new MorphlineRuntimeException(e); } catch (IOException e) { throw new MorphlineRuntimeException(e); loader.rollbackTransaction(); } catch (SolrServerException e) { throw new MorphlineRuntimeException(e); } catch (IOException e) { throw new MorphlineRuntimeException(e); loader.shutdown(); } catch (SolrServerException e) { throw new MorphlineRuntimeException(e); } catch (IOException e) { throw new MorphlineRuntimeException(e);
public void importCommandBuilders(Collection<String> importSpecs) { if (commandBuilders == Collections.EMPTY_MAP) { // intentionally effective no more than once commandBuilders = Maps.newHashMap(); if (LOG.isDebugEnabled()) { LOG.debug("Importing commands from Java classpath: {}", System.getProperty("java.class.path")); } else { LOG.info("Importing commands"); } Collection<Class<CommandBuilder>> builderClasses = getTopLevelClasses(importSpecs, CommandBuilder.class); for (Class<CommandBuilder> builderClass : builderClasses) { try { CommandBuilder builder = builderClass.newInstance(); for (String builderName : builder.getNames()) { LOG.debug("Importing command: {} from class: {}", builderName, builderClass.getName()); if (builderName.contains(".")) { LOG.warn("Command name should not contain a period character: " + builderName); } commandBuilders.put(builderName, builderClass); } } catch (Exception e) { throw new MorphlineRuntimeException(e); } } LOG.info("Done importing commands"); } }
getters.put(propertyName, clazz.getMethod(getterName.toString())); } catch (Exception e1) { throw new MorphlineRuntimeException("Property '" + propertyName + "' does not exist in class '" + clazz.getName() + "'.");
@Override protected void doNotify(Record notification) { for (Object event : Notifications.getLifecycleEvents(notification)) { if (event == Notifications.LifecycleEvent.SHUTDOWN) { synchronized (SERVERS) { Server server = SERVERS.remove(port); if (server != null) { try { server.stop(); server.join(); } catch (Exception e) { throw new MorphlineRuntimeException(e); } } } } } super.doNotify(notification); }
@Override protected void doNotify(Record notification) { for (Object event : Notifications.getLifecycleEvents(notification)) { if (event == Notifications.LifecycleEvent.SHUTDOWN) { synchronized (SERVERS) { Server server = SERVERS.remove(port); if (server != null) { try { server.stop(); server.join(); } catch (Exception e) { throw new MorphlineRuntimeException(e); } } } } } super.doNotify(notification); }
public void importCommandBuilders(Collection<String> importSpecs) { if (commandBuilders == Collections.EMPTY_MAP) { // intentionally effective no more than once commandBuilders = Maps.newHashMap(); if (LOG.isDebugEnabled()) { LOG.debug("Importing commands from Java classpath: {}", System.getProperty("java.class.path")); } else { LOG.info("Importing commands"); } Collection<Class<CommandBuilder>> builderClasses = getTopLevelClasses(importSpecs, CommandBuilder.class); for (Class<CommandBuilder> builderClass : builderClasses) { try { CommandBuilder builder = builderClass.newInstance(); for (String builderName : builder.getNames()) { LOG.debug("Importing command: {} from class: {}", builderName, builderClass.getName()); if (builderName.contains(".")) { LOG.warn("Command name should not contain a period character: " + builderName); } commandBuilders.put(builderName, builderClass); } } catch (Exception e) { throw new MorphlineRuntimeException(e); } } LOG.info("Done importing commands"); } }
@Override protected boolean doProcess(Record record) { Timer.Context timerContext = elapsedTime.time(); SolrInputDocument doc = convert(record); try { loader.load(doc); } catch (IOException | SolrServerException e) { throw new MorphlineRuntimeException(e); } finally { timerContext.stop(); } // pass record to next command in chain: return super.doProcess(record); }
@Override public void handleException(Throwable t, Record record) { if (t instanceof Error) { throw (Error) t; // never ignore errors } if (isProductionMode()) { if (!isRecoverableException(t)) { LOG.warn("Ignoring unrecoverable exception in production mode for record: " + record, t); return; } else if (isIgnoringRecoverableExceptions()) { LOG.warn("Ignoring recoverable exception in production mode for record: " + record, t); return; } } throw new MorphlineRuntimeException(t); }
@Override public void handleException(Throwable t, Record record) { if (t instanceof Error) { throw (Error) t; // never ignore errors } if (isProductionMode()) { if (!isRecoverableException(t)) { LOG.warn("Ignoring unrecoverable exception in production mode for record: " + record, t); return; } else if (isIgnoringRecoverableExceptions()) { LOG.warn("Ignoring recoverable exception in production mode for record: " + record, t); return; } } throw new MorphlineRuntimeException(t); }