001package ca.uhn.fhir.rest.server.interceptor;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2016 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) throws ServletException,
047                        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, Bundle theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException {
068                return true;
069        }
070        
071    @Override
072    public boolean outgoingResponse(RequestDetails theRequestDetails, Bundle bundle) {
073        ServletRequestDetails details = (ServletRequestDetails) theRequestDetails;
074        return outgoingResponse(details, bundle, details.getServletRequest(), details.getServletResponse());
075    }   
076
077        @Override
078        public boolean outgoingResponse(RequestDetails theRequestDetails, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException {
079                return true;
080        }
081        
082    @Override
083    public boolean outgoingResponse(RequestDetails theRequestDetails) {
084        ServletRequestDetails details = (ServletRequestDetails) theRequestDetails;
085        return outgoingResponse(theRequestDetails, details.getServletRequest(), details.getServletResponse());
086    }   
087
088        @Override
089        public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException {
090                return true;
091        }
092        
093    @Override
094    public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) {
095        ServletRequestDetails details = (ServletRequestDetails) theRequestDetails;
096        return outgoingResponse(details, theResponseObject, details.getServletRequest(), details.getServletResponse());
097    }   
098        
099        @Override
100        public boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException {
101                return true;
102        }
103        
104    @Override
105    public boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject) {
106        ServletRequestDetails details = (ServletRequestDetails) theRequestDetails;
107        return outgoingResponse(details, theResponseObject, details.getServletRequest(), details.getServletResponse());
108    }   
109
110        @Override
111        public BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException {
112                return null;
113        }
114
115}