public ExceptionRecognizerComposite(final List<? extends ExceptionRecognizer> exceptionRecognizers) { for (final ExceptionRecognizer er : exceptionRecognizers) { add(er); } }
/** * For recognizers already {@link #add(ExceptionRecognizer) add}ed, simply {@link #injectServices()} and {@link #initRecognizers(Map) initializes}. * * <p> * Typical usage: * </p> * <pre> * public void init(Map<String,String> properties) { * add(new ExceptionRecognizerForThisException()); * add(new ExceptionRecognizerForThatException()); * add(new ExceptionRecognizerForTheOtherException()); * super.init(properties); * } * </pre> * */ @PostConstruct @Override @Programmatic public void init(final Map<String, String> properties) { injectServices(); initRecognizers(properties); }
protected IRequestablePage errorPageFor(Exception ex) { List<ExceptionRecognizer> exceptionRecognizers = Lists.newArrayList(); exceptionRecognizers.add(pageExpiredExceptionRecognizer); if(inIsisSession()) { exceptionRecognizers.addAll(getServicesInjector().lookupServices(ExceptionRecognizer.class)); } else { final MetaModelInvalidException mmie = IsisContext.getMetaModelInvalidExceptionIfAny(); if(mmie != null) { Set<String> validationErrors = mmie.getValidationErrors(); return new MmvErrorPage(validationErrors); } // not sure whether this can ever happen now... LOG.warn("Unable to obtain exceptionRecognizers (no session), will be treated as unrecognized exception", ex); } String recognizedMessageIfAny = new ExceptionRecognizerComposite(exceptionRecognizers).recognize(ex); ExceptionModel exceptionModel = ExceptionModel.create(recognizedMessageIfAny, ex); return isSignedIn() ? new ErrorPage(exceptionModel) : newSignInPage(exceptionModel); }
@Test public void whenEmpty() { assertThat(composite.recognize(new RuntimeException()), is(nullValue())); }
@Before public void setUp() throws Exception { composite = new ExceptionRecognizerComposite(); composite.container = mockContainer; composite.translationService = mockTranslationService; context.ignoring(mockContainer); context.ignoring(mockTranslationService); }
@Programmatic @PostConstruct public void init(Map<String,String> properties) { final boolean disabled = getElseFalse(properties, KEY_DISABLE); if(disabled) { return; } addChildren(); super.init(properties); }
/** * Returns the non-<tt>null</tt> recognition of the first {@link #add(ExceptionRecognizer) add}ed * (that is also an {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2}). * * <p> * If none (as {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2}) recognize * the exception, then falls back to using {@link #recognize(Throwable)}, returning a * {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2.Recognition} with a * category of {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer2.Category#CLIENT_ERROR}. * </p> */ @Programmatic public final Recognition recognize2(final Throwable ex) { for (final ExceptionRecognizer ers : exceptionRecognizers) { if(ers instanceof ExceptionRecognizer2) { final ExceptionRecognizer2 recognizer2 = (ExceptionRecognizer2) ers; final Recognition recognition = recognizer2.recognize2(ex); if(recognition != null) { return recognition; } } } // backward compatible so far as possible. return Recognition.of(Category.OTHER, recognize(ex)); }