From 436e898819498ec59c9834c0c6b330a6e6b32dc7 Mon Sep 17 00:00:00 2001 From: Diederik Muylwyk Date: Fri, 17 Mar 2017 17:02:05 -0400 Subject: [PATCH] Added a hook for post-processing request details and validation results on failure. --- .../rest/server/interceptor/BaseValidatingInterceptor.java | 6 ++++++ src/changes/changes.xml | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/BaseValidatingInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/BaseValidatingInterceptor.java index e6170c7e00d..e22d7e0f6d0 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/BaseValidatingInterceptor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/BaseValidatingInterceptor.java @@ -267,6 +267,11 @@ abstract class BaseValidatingInterceptor extends InterceptorAdapter { */ protected void postProcessResult(RequestDetails theRequestDetails, ValidationResult theValidationResult) { } + /** + * Hook for subclasses on failure (e.g. add a response header to an incoming resource upon rejection). + */ + protected void postProcessResultOnFailure(RequestDetails theRequestDetails, ValidationResult theValidationResult) { } + /** * Note: May return null */ @@ -314,6 +319,7 @@ abstract class BaseValidatingInterceptor extends InterceptorAdapter { if (myFailOnSeverity != null) { for (SingleValidationMessage next : validationResult.getMessages()) { if (next.getSeverity().ordinal() >= myFailOnSeverity) { + postProcessResultOnFailure(theRequestDetails, validationResult); fail(theRequestDetails, validationResult); return validationResult; } diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e4fa4eff160..3448d43e454 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -202,6 +202,11 @@ the JPA database, improving performance of this operation. Thanks to Joel Schneider for the pull request and analysis! + + A new post-processing hook for subclasses of BaseValidatingInterceptor is now + available. The hook exposes the request details on validation failure prior to throwing an + UnprocessableEntityException. +