001package ca.uhn.fhir.rest.server.interceptor;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2017 University Health Network
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 * http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import java.io.IOException;
024
025import javax.servlet.ServletException;
026import javax.servlet.http.HttpServletRequest;
027import javax.servlet.http.HttpServletResponse;
028
029import org.hl7.fhir.instance.model.api.IBaseResource;
030
031import ca.uhn.fhir.model.api.Bundle;
032import ca.uhn.fhir.model.api.TagList;
033import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
034import ca.uhn.fhir.rest.method.RequestDetails;
035import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
036import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
037import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
038
039/**
040 * Base class for {@link IServerInterceptor} implementations. Provides a No-op implementation
041 * of all methods, always returning <code>true</code>
042 */
043public class InterceptorAdapter implements IServerInterceptor {
044
045        @Override
046        public boolean handleException(RequestDetails theRequestDetails, BaseServerResponseException theException, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse)
047                        throws ServletException, IOException {
048                return true;
049        }
050
051        @Override
052        public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
053                return true;
054        }
055
056        @Override
057        public void incomingRequestPreHandled(RestOperationTypeEnum theOperation, ActionRequestDetails theProcessedRequest) {
058                // nothing
059        }
060
061        @Override
062        public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) {
063                return true;
064        }
065
066        @Override
067        public boolean outgoingResponse(RequestDetails theRequestDetails) {
068                ServletRequestDetails details = (ServletRequestDetails) theRequestDetails;
069                return outgoingResponse(theRequestDetails, details.getServletRequest(), details.getServletResponse());
070        }
071
072        @Override
073        public boolean outgoingResponse(RequestDetails theRequestDetails, Bundle bundle) {
074                ServletRequestDetails details = (ServletRequestDetails) theRequestDetails;
075                return outgoingResponse(details, bundle, details.getServletRequest(), details.getServletResponse());
076        }
077
078        @Override
079        public boolean outgoingResponse(RequestDetails theRequestDetails, Bundle theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse)
080                        throws AuthenticationException {
081                return true;
082        }
083
084        @Override
085        public boolean outgoingResponse(RequestDetails theRequestDetails, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException {
086                return true;
087        }
088
089        @Override
090        public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) {
091                ServletRequestDetails details = (ServletRequestDetails) theRequestDetails;
092                return outgoingResponse(details, theResponseObject, details.getServletRequest(), details.getServletResponse());
093        }
094
095        @Override
096        public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse)
097                        throws AuthenticationException {
098                return true;
099        }
100
101        @Override
102        public boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject) {
103                ServletRequestDetails details = (ServletRequestDetails) theRequestDetails;
104                return outgoingResponse(details, theResponseObject, details.getServletRequest(), details.getServletResponse());
105        }
106
107        @Override
108        public boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse)
109                        throws AuthenticationException {
110                return true;
111        }
112
113        @Override
114        public BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException {
115                return null;
116        }
117
118        @Override
119        public void processingCompletedNormally(ServletRequestDetails theRequestDetails) {
120                // nothing
121        }
122
123}