Class BaseValidatingInterceptor<T>
java.lang.Object
ca.uhn.fhir.rest.server.interceptor.ValidationResultEnrichingInterceptor
ca.uhn.fhir.rest.server.interceptor.BaseValidatingInterceptor<T>
- Direct Known Subclasses:
RequestValidatingInterceptor
,ResponseValidatingInterceptor
This interceptor intercepts each incoming request and if it contains a FHIR resource, validates that resource. The
interceptor may be configured to run any validator modules, and will then add headers to the response or fail the
request with an
HTTP 422 Unprocessable Entity
.-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Default value:
${row}:${col} ${severity} ${message} (${location})
Fields inherited from class ca.uhn.fhir.rest.server.interceptor.ValidationResultEnrichingInterceptor
REQUEST_VALIDATION_RESULT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddValidatorModule
(ca.uhn.fhir.validation.IValidatorModule theModule) Specify a validator module to use.protected void
fail
(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult) Fail the request by throwing anUnprocessableEntityException
as a result of a validation failure.ca.uhn.fhir.validation.ResultSeverityEnum
If the validation produces a result with at least the given severity, a header with the name specified bysetResponseOutcomeHeaderName(String)
will be added containing a JSON encoded OperationOutcome resource containing the validation results.int
The maximum length for an individual header.The name of the header specified bysetAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)
List
<ca.uhn.fhir.validation.IValidatorModule> boolean
If set totrue
(default isfalse
) this interceptor will exit immediately and allow processing to continue if the validator throws any exceptions.protected void
postProcessResult
(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult) Hook for subclasses (e.g.protected void
postProcessResultOnFailure
(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult) Hook for subclasses on failure (e.g.void
setAddResponseHeaderOnSeverity
(ca.uhn.fhir.validation.ResultSeverityEnum theSeverity) Sets the minimum severity at which an issue detected by the validator will result in a header being added to the response.void
setAddResponseOutcomeHeaderOnSeverity
(ca.uhn.fhir.validation.ResultSeverityEnum theAddResponseOutcomeHeaderOnSeverity) If the validation produces a result with at least the given severity, a header with the name specified bysetResponseOutcomeHeaderName(String)
will be added containing a JSON encoded OperationOutcome resource containing the validation results.void
setFailOnSeverity
(ca.uhn.fhir.validation.ResultSeverityEnum theSeverity) Sets the minimum severity at which an issue detected by the validator will fail/reject the request.void
setIgnoreValidatorExceptions
(boolean theIgnoreValidatorExceptions) If set totrue
(default isfalse
) this interceptor will exit immediately and allow processing to continue if the validator throws any exceptions.void
setMaximumHeaderLength
(int theMaximumHeaderLength) The maximum length for an individual header.protected void
setResponseHeaderName
(String theResponseHeaderName) Sets the name of the response header to add validation failures tovoid
setResponseHeaderValue
(String theResponseHeaderValue) Sets the value to add to the response header with the name specified bysetResponseHeaderName(String)
when validation produces a message of severity equal to or greater thansetAddResponseHeaderOnSeverity(ResultSeverityEnum)
void
setResponseHeaderValueNoIssues
(String theResponseHeaderValueNoIssues) Sets the header value to add when no issues are found at or exceeding the threshold specified bysetAddResponseHeaderOnSeverity(ResultSeverityEnum)
void
setResponseOutcomeHeaderName
(String theResponseOutcomeHeaderName) The name of the header specified bysetAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)
void
setValidator
(ca.uhn.fhir.validation.FhirValidator theValidator) Provides the validator to use.void
setValidatorModules
(List<ca.uhn.fhir.validation.IValidatorModule> theValidatorModules) protected ca.uhn.fhir.validation.ValidationResult
validate
(T theRequest, RequestDetails theRequestDetails) Note: May return nullMethods inherited from class ca.uhn.fhir.rest.server.interceptor.ValidationResultEnrichingInterceptor
addValidationResultsToOperationOutcome, addValidationResultToRequestDetails
-
Field Details
-
DEFAULT_RESPONSE_HEADER_VALUE
Default value:
${row}:${col} ${severity} ${message} (${location})
- See Also:
-
-
Constructor Details
-
BaseValidatingInterceptor
public BaseValidatingInterceptor()
-
-
Method Details
-
addValidatorModule
public BaseValidatingInterceptor<T> addValidatorModule(ca.uhn.fhir.validation.IValidatorModule theModule) Specify a validator module to use.- See Also:
-
setValidator
Provides the validator to use. This can be used as an alternative toaddValidatorModule(IValidatorModule)
- See Also:
-
fail
protected void fail(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult) Fail the request by throwing anUnprocessableEntityException
as a result of a validation failure. Subclasses may change this behaviour by providing alternate behaviour. -
getAddResponseOutcomeHeaderOnSeverity
If the validation produces a result with at least the given severity, a header with the name specified bysetResponseOutcomeHeaderName(String)
will be added containing a JSON encoded OperationOutcome resource containing the validation results. -
setAddResponseOutcomeHeaderOnSeverity
public void setAddResponseOutcomeHeaderOnSeverity(ca.uhn.fhir.validation.ResultSeverityEnum theAddResponseOutcomeHeaderOnSeverity) If the validation produces a result with at least the given severity, a header with the name specified bysetResponseOutcomeHeaderName(String)
will be added containing a JSON encoded OperationOutcome resource containing the validation results. -
getMaximumHeaderLength
The maximum length for an individual header. If an individual header would be written exceeding this length, the header value will be truncated. -
setMaximumHeaderLength
The maximum length for an individual header. If an individual header would be written exceeding this length, the header value will be truncated. Value must be greater than 100. -
getResponseOutcomeHeaderName
The name of the header specified bysetAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)
-
setResponseOutcomeHeaderName
The name of the header specified bysetAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)
-
getValidatorModules
-
setValidatorModules
-
isIgnoreValidatorExceptions
If set totrue
(default isfalse
) this interceptor will exit immediately and allow processing to continue if the validator throws any exceptions.This setting is mostly useful in testing situations
-
setIgnoreValidatorExceptions
If set totrue
(default isfalse
) this interceptor will exit immediately and allow processing to continue if the validator throws any exceptions.This setting is mostly useful in testing situations
-
setAddResponseHeaderOnSeverity
Sets the minimum severity at which an issue detected by the validator will result in a header being added to the response. Default isResultSeverityEnum.INFORMATION
. Set tonull
to disable this behaviour.- See Also:
-
setFailOnSeverity
Sets the minimum severity at which an issue detected by the validator will fail/reject the request. Default isResultSeverityEnum.ERROR
. Set tonull
to disable this behaviour. -
setResponseHeaderName
Sets the name of the response header to add validation failures to- See Also:
-
setResponseHeaderValue
Sets the value to add to the response header with the name specified bysetResponseHeaderName(String)
when validation produces a message of severity equal to or greater thansetAddResponseHeaderOnSeverity(ResultSeverityEnum)
This field allows the following substitutions:
Name Value ${line} The line in the request ${col} The column in the request ${location} The location in the payload as a string (typically this will be a path) ${severity} The severity of the issue ${message} The validation message - See Also:
-
setResponseHeaderValueNoIssues
Sets the header value to add when no issues are found at or exceeding the threshold specified bysetAddResponseHeaderOnSeverity(ResultSeverityEnum)
-
postProcessResult
protected void postProcessResult(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult) Hook for subclasses (e.g. add a tag (coding) to an incoming resource when a given severity appears in the ValidationResult). -
postProcessResultOnFailure
protected void postProcessResultOnFailure(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult) Hook for subclasses on failure (e.g. add a response header to an incoming resource upon rejection). -
validate
protected ca.uhn.fhir.validation.ValidationResult validate(T theRequest, RequestDetails theRequestDetails) Note: May return null
-