Class BaseValidatingInterceptor<T>
- java.lang.Object
-
- ca.uhn.fhir.rest.server.interceptor.BaseValidatingInterceptor<T>
-
- Direct Known Subclasses:
RequestValidatingInterceptor,ResponseValidatingInterceptor
public abstract class BaseValidatingInterceptor<T> extends Object
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 anHTTP 422 Unprocessable Entity.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_RESPONSE_HEADER_VALUEDefault value:
${row}:${col} ${severity} ${message} (${location})
-
Constructor Summary
Constructors Constructor Description BaseValidatingInterceptor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BaseValidatingInterceptor<T>addValidatorModule(ca.uhn.fhir.validation.IValidatorModule theModule)protected voidfail(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult)Fail the request by throwing anUnprocessableEntityExceptionas a result of a validation failure.ca.uhn.fhir.validation.ResultSeverityEnumgetAddResponseOutcomeHeaderOnSeverity()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.intgetMaximumHeaderLength()The maximum length for an individual header.StringgetResponseOutcomeHeaderName()The name of the header specified bysetAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)List<ca.uhn.fhir.validation.IValidatorModule>getValidatorModules()booleanisIgnoreValidatorExceptions()If set totrue(default isfalse) this interceptor will exit immediately and allow processing to continue if the validator throws any exceptions.protected voidpostProcessResult(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult)Hook for subclasses (e.g.protected voidpostProcessResultOnFailure(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult)Hook for subclasses on failure (e.g.voidsetAddResponseHeaderOnSeverity(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.voidsetAddResponseOutcomeHeaderOnSeverity(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.voidsetFailOnSeverity(ca.uhn.fhir.validation.ResultSeverityEnum theSeverity)Sets the minimum severity at which an issue detected by the validator will fail/reject the request.voidsetIgnoreValidatorExceptions(boolean theIgnoreValidatorExceptions)If set totrue(default isfalse) this interceptor will exit immediately and allow processing to continue if the validator throws any exceptions.voidsetMaximumHeaderLength(int theMaximumHeaderLength)The maximum length for an individual header.protected voidsetResponseHeaderName(String theResponseHeaderName)Sets the name of the response header to add validation failures tovoidsetResponseHeaderValue(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)voidsetResponseHeaderValueNoIssues(String theResponseHeaderValueNoIssues)Sets the header value to add when no issues are found at or exceeding the threshold specified bysetAddResponseHeaderOnSeverity(ResultSeverityEnum)voidsetResponseOutcomeHeaderName(String theResponseOutcomeHeaderName)The name of the header specified bysetAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)voidsetValidatorModules(List<ca.uhn.fhir.validation.IValidatorModule> theValidatorModules)protected ca.uhn.fhir.validation.ValidationResultvalidate(T theRequest, RequestDetails theRequestDetails)Note: May return null
-
-
-
Field Detail
-
DEFAULT_RESPONSE_HEADER_VALUE
public static final String DEFAULT_RESPONSE_HEADER_VALUE
Default value:
${row}:${col} ${severity} ${message} (${location})- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BaseValidatingInterceptor
public BaseValidatingInterceptor()
-
-
Method Detail
-
addValidatorModule
public BaseValidatingInterceptor<T> addValidatorModule(ca.uhn.fhir.validation.IValidatorModule theModule)
-
fail
protected void fail(RequestDetails theRequestDetails, ca.uhn.fhir.validation.ValidationResult theValidationResult)
Fail the request by throwing anUnprocessableEntityExceptionas a result of a validation failure. Subclasses may change this behaviour by providing alternate behaviour.
-
getAddResponseOutcomeHeaderOnSeverity
public ca.uhn.fhir.validation.ResultSeverityEnum 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.
-
getMaximumHeaderLength
public int getMaximumHeaderLength()
The maximum length for an individual header. If an individual header would be written exceeding this length, the header value will be truncated.
-
getResponseOutcomeHeaderName
public String getResponseOutcomeHeaderName()
The name of the header specified bysetAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)
-
getValidatorModules
public List<ca.uhn.fhir.validation.IValidatorModule> getValidatorModules()
-
isIgnoreValidatorExceptions
public boolean 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
-
setAddResponseHeaderOnSeverity
public 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. Default isResultSeverityEnum.INFORMATION. Set tonullto disable this behaviour.
-
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.
-
setFailOnSeverity
public 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. Default isResultSeverityEnum.ERROR. Set tonullto disable this behaviour.
-
setIgnoreValidatorExceptions
public 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.This setting is mostly useful in testing situations
-
setMaximumHeaderLength
public void setMaximumHeaderLength(int theMaximumHeaderLength)
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.
-
setResponseHeaderName
protected void setResponseHeaderName(String theResponseHeaderName)
Sets the name of the response header to add validation failures to
-
setResponseHeaderValue
public void 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)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
-
setResponseHeaderValueNoIssues
public void setResponseHeaderValueNoIssues(String theResponseHeaderValueNoIssues)
Sets the header value to add when no issues are found at or exceeding the threshold specified bysetAddResponseHeaderOnSeverity(ResultSeverityEnum)
-
setResponseOutcomeHeaderName
public void setResponseOutcomeHeaderName(String theResponseOutcomeHeaderName)
The name of the header specified bysetAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum)
-
setValidatorModules
public void setValidatorModules(List<ca.uhn.fhir.validation.IValidatorModule> theValidatorModules)
-
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
-
-