001package ca.uhn.fhir.rest.server.interceptor; 002 003/* 004 * #%L 005 * HAPI FHIR - Server Framework 006 * %% 007 * Copyright (C) 2014 - 2019 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 ca.uhn.fhir.rest.api.server.ResponseDetails; 030import org.hl7.fhir.instance.model.api.IBaseResource; 031 032import ca.uhn.fhir.model.api.TagList; 033import ca.uhn.fhir.rest.api.RestOperationTypeEnum; 034import ca.uhn.fhir.rest.api.server.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, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException { 074 return true; 075 } 076 077 @Override 078 public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) { 079 ServletRequestDetails details = (ServletRequestDetails) theRequestDetails; 080 return outgoingResponse(details, theResponseObject, details.getServletRequest(), details.getServletResponse()); 081 } 082 083 @Override 084 public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) 085 throws AuthenticationException { 086 return true; 087 } 088 089 @Override 090 public boolean outgoingResponse(RequestDetails theRequestDetails, ResponseDetails theResponseDetails, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException { 091 return true; 092 } 093 094 @Override 095 public boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject) { 096 ServletRequestDetails details = (ServletRequestDetails) theRequestDetails; 097 return outgoingResponse(details, theResponseObject, details.getServletRequest(), details.getServletResponse()); 098 } 099 100 @Override 101 public boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) 102 throws AuthenticationException { 103 return true; 104 } 105 106 @Override 107 public BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException { 108 return null; 109 } 110 111 @Override 112 public void processingCompletedNormally(ServletRequestDetails theRequestDetails) { 113 // nothing 114 } 115 116}