@Override public KeywordValidator getKeywordValidator(JsonNode node) throws ProcessingException { try { return constructor.newInstance(node); } catch (InstantiationException e) { throw new ProcessingException(ERRMSG, e); } catch (IllegalAccessException e) { throw new ProcessingException(ERRMSG, e); } catch (InvocationTargetException e) { throw new ProcessingException(ERRMSG, e); } }
@Override void doIt(final ProcessingReport report) throws ProcessingException { throw new ProcessingException(); } };
@Override void doIt(final ProcessingReport report, final ProcessingMessage message) throws ProcessingException { throw new ProcessingException(); } };
@Override void doIt(final ProcessingReport report) throws ProcessingException { throw new ProcessingException(); } };
throw new ProcessingException(validationLoopMessage(data)); schemaURIs.addLast(schemaURI); return;
@Override public ProcessingException doException(final ProcessingMessage message) { return new ProcessingException(message); } }
@Override public ProcessingException doException(final ProcessingMessage message) { return new ProcessingException(message); } }
@Override public ProcessingException doException(final ProcessingMessage message) { return new ProcessingException(message); } }
@Override public Y process(final ProcessingReport report, final X input) throws ProcessingException { Predicate<X> predicate; Processor<X, Y> processor; for (final Map.Entry<Predicate<X>, Processor<X, Y>> entry: map.entrySet()) { predicate = entry.getKey(); processor = entry.getValue(); if (predicate.apply(input)) return processor.process(report, input); } if (byDefault != null) return byDefault.process(report, input); throw new ProcessingException( BUNDLE.getMessage("processing.noProcessor")); }
@Override public Y process(final ProcessingReport report, final X input) throws ProcessingException { Predicate<X> predicate; Processor<X, Y> processor; for (final Map.Entry<Predicate<X>, Processor<X, Y>> entry: map.entrySet()) { predicate = entry.getKey(); processor = entry.getValue(); if (predicate.apply(input)) return processor.process(report, input); } if (byDefault != null) return byDefault.process(report, input); throw new ProcessingException( BUNDLE.getMessage("processing.noProcessor")); }
@Override public Y process(final ProcessingReport report, final X input) throws ProcessingException { Predicate<X> predicate; Processor<X, Y> processor; for (final Map.Entry<Predicate<X>, Processor<X, Y>> entry: map.entrySet()) { predicate = entry.getKey(); processor = entry.getValue(); if (predicate.apply(input)) return processor.process(report, input); } if (byDefault != null) return byDefault.process(report, input); throw new ProcessingException( BUNDLE.getMessage("processing.noProcessor")); }
@Override public OUT process(final ProcessingReport report, final IN input) throws ProcessingException { final K key = f.apply(input); Processor<IN, OUT> processor = processors.get(key); if (processor == null) processor = defaultProcessor; if (processor == null) // Not even a default processor. Ouch. throw new ProcessingException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("processing.noProcessor")) .put("key", key)); return processor.process(report, input); }
@Override public OUT process(final ProcessingReport report, final IN input) throws ProcessingException { final K key = f.apply(input); Processor<IN, OUT> processor = processors.get(key); if (processor == null) processor = defaultProcessor; if (processor == null) // Not even a default processor. Ouch. throw new ProcessingException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("processing.noProcessor")) .put("key", key)); return processor.process(report, input); }
@Override public OUT process(final ProcessingReport report, final IN input) throws ProcessingException { final K key = f.apply(input); Processor<IN, OUT> processor = processors.get(key); if (processor == null) processor = defaultProcessor; if (processor == null) // Not even a default processor. Ouch. throw new ProcessingException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("processing.noProcessor")) .put("key", key)); return processor.process(report, input); }
@Test public void exceptionsAreCorrectlyThrown() throws ProcessingException { final ProcessingException exception = new ProcessingException(MSG); when(processor.process(anyReport(), any(In.class))) .thenThrow(exception); try { ProcessingResult.of(processor, report, input); fail("No exception thrown!!"); } catch (ProcessingException e) { assertSame(exception, e); } }
@Test public void innerExceptionClassAndMessageAreReported() { final Exception inner = new Foo(FOO); final ProcessingException exception = new ProcessingException("", inner); final ProcessingMessage message = exception.getProcessingMessage(); assertMessage(message).hasField("exceptionClass", Foo.class.getName()) .hasField("exceptionMessage", inner.getMessage()); }
@Test public void thrownProcessingMessagesHaveLevelFatal() { final ProcessingMessage message = new ProcessingMessage(); new ProcessingException(message); assertMessage(message).hasLevel(LogLevel.FATAL); }
@Test public void processingExceptionMessageIsSameAsProcessingMessage() { final ProcessingMessage message = new ProcessingMessage() .setMessage(FOO); final ProcessingException exception = new ProcessingException(message); assertEquals(exception.getMessage(), message.toString()); }
/** * Get a schema tree from the given URI * * <p>Note that if the URI is relative, it will be resolved against this * registry's namespace, if any.</p> * * @param uri the URI * @return a schema tree * @throws ProcessingException URI is not an absolute JSON reference, or * failed to dereference this URI * @throws NullPointerException URI is null */ public SchemaTree get(final URI uri) throws ProcessingException { final JsonRef ref = JsonRef.fromURI(translator.translate(uri)); if (!ref.isAbsolute()) throw new ProcessingException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("refProcessing.uriNotAbsolute")) .putArgument("uri", ref)); final URI realURI = ref.toURI(); try { JsonNode node = preloadedSchemas.get(realURI); if (node == null) node = cache.get(realURI); return dereferencing.newTree(ref, node); } catch (ExecutionException e) { throw (ProcessingException) e.getCause(); } }
@Test public void uncheckedReportCorrectlyReportsException() throws ProcessingException { final ProcessingException exception = new ProcessingException(MSG); when(processor.process(anyReport(), any(In.class))) .thenThrow(exception); when(report.iterator()) .thenReturn(Iterators.<ProcessingMessage>emptyIterator()); final ProcessingResult<Out> result = ProcessingResult.uncheckedResult(processor, report, input); assertFalse(result.isSuccess()); final ProcessingReport r = result.getReport(); final List<ProcessingMessage> list = Lists.newArrayList(r); assertFalse(list.isEmpty()); final ProcessingMessage message = list.get(0); assertMessage(message).hasMessage(MSG).hasLevel(LogLevel.FATAL); }