Convert validating intercwptors to use new framework

This commit is contained in:
James Agnew 2019-07-18 08:25:35 -04:00
parent ee7cff9445
commit 9fc10242b7
3 changed files with 11 additions and 5 deletions

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.rest.server.interceptor;
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.api.Interceptor;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
@ -43,7 +44,8 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
* interceptor may be configured to run any validator modules, and will then add headers to the response or fail the
* request with an {@link UnprocessableEntityException HTTP 422 Unprocessable Entity}.
*/
abstract class BaseValidatingInterceptor<T> extends InterceptorAdapter {
@Interceptor
abstract class BaseValidatingInterceptor<T> {
/**
* Default value:<br/>

View File

@ -27,6 +27,8 @@ import java.nio.charset.Charset;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Pointcut;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -67,7 +69,7 @@ public class RequestValidatingInterceptor extends BaseValidatingInterceptor<Stri
return theValidator.validateWithResult(theRequest);
}
@Override
@Hook(Pointcut.SERVER_INCOMING_REQUEST_POST_PROCESSED)
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
EncodingEnum encoding = RestfulServerUtils.determineRequestEncodingNoDefault(theRequestDetails);
if (encoding == null) {
@ -102,7 +104,7 @@ public class RequestValidatingInterceptor extends BaseValidatingInterceptor<Stri
return myAddValidationResultsToResponseOperationOutcome;
}
@Override
@Hook(Pointcut.SERVER_OUTGOING_RESPONSE)
public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) {
if (myAddValidationResultsToResponseOperationOutcome) {
if (theResponseObject instanceof IBaseOperationOutcome) {

View File

@ -23,6 +23,8 @@ package ca.uhn.fhir.rest.server.interceptor;
import java.util.HashSet;
import java.util.Set;
import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Pointcut;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -54,7 +56,7 @@ public class ResponseValidatingInterceptor extends BaseValidatingInterceptor<IBa
public void addExcludeOperationType(RestOperationTypeEnum theOperationType) {
Validate.notNull(theOperationType, "theOperationType must not be null");
if (myExcludeOperationTypes == null) {
myExcludeOperationTypes = new HashSet<RestOperationTypeEnum>();
myExcludeOperationTypes = new HashSet<>();
}
myExcludeOperationTypes.add(theOperationType);
}
@ -64,7 +66,7 @@ public class ResponseValidatingInterceptor extends BaseValidatingInterceptor<IBa
return theValidator.validateWithResult(theRequest);
}
@Override
@Hook(Pointcut.SERVER_OUTGOING_RESPONSE)
public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) {
RestOperationTypeEnum operationType = theRequestDetails.getRestOperationType();
if (operationType != null && myExcludeOperationTypes != null && myExcludeOperationTypes.contains(operationType)) {