diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerInterceptor.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerInterceptor.java index 8b35f6413cb..3471d3e587b 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerInterceptor.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerInterceptor.java @@ -92,10 +92,7 @@ public interface IServerInterceptor { /** * This method is called just before the actual implementing server method is invoked. - *
- * Note about exceptions: - *
- * + * * @param theRequestDetails * A bean containing details about the request that is about to be processed, including details such as the * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been @@ -157,77 +154,40 @@ public interface IServerInterceptor { boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse); /** - * This method is called after the server implementation method has been called, but before any attempt to stream the - * response back to the client - * - * @param theRequestDetails - * A bean containing details about the request that is about to be processed, including details such as the - * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been - * pulled out of the {@link HttpServletRequest servlet request}. - * @return Returntrue
if processing should continue normally. This is generally the right thing to do.
- * If your interceptor is providing a response rather than letting HAPI handle the response normally, you
- * must return false
. In this case, no further processing will occur and no further interceptors
- * will be called.
- * @throws AuthenticationException
- * This exception may be thrown to indicate that the interceptor has detected an unauthorized access
- * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
+ * Use {@link #outgoingResponse(RequestDetails, IBaseResource, HttpServletRequest, HttpServletResponse)} instead
+ *
+ * @deprecated As of HAPI FHIR 3.2.0, this method is deprecated and will be removed in a future version of HAPI FHIR.
*/
+ @Deprecated
boolean outgoingResponse(RequestDetails theRequestDetails);
/**
- * This method is called after the server implementation method has been called, but before any attempt to stream the
- * response back to the client
- *
- * @param theRequestDetails
- * A bean containing details about the request that is about to be processed, including details such as the
- * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
- * pulled out of the {@link HttpServletRequest servlet request}.
- * @param theServletRequest
- * The incoming request
- * @param theServletResponse
- * The response. Note that interceptors may choose to provide a response (i.e. by calling
- * {@link HttpServletResponse#getWriter()}) but in that case it is important to return false
- * to indicate that the server itself should not also provide a response.
- * @return Return true
if processing should continue normally. This is generally the right thing to do.
- * If your interceptor is providing a response rather than letting HAPI handle the response normally, you
- * must return false
. In this case, no further processing will occur and no further interceptors
- * will be called.
- * @throws AuthenticationException
- * This exception may be thrown to indicate that the interceptor has detected an unauthorized access
- * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
+ * Use {@link #outgoingResponse(RequestDetails, IBaseResource, HttpServletRequest, HttpServletResponse)} instead
+ *
+ * @deprecated As of HAPI FHIR 3.2.0, this method is deprecated and will be removed in a future version of HAPI FHIR.
*/
+ @Deprecated
boolean outgoingResponse(RequestDetails theRequestDetails, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
/**
- * This method is called after the server implementation method has been called, but before any attempt to stream the
- * response back to the client
- *
- * @param theRequestDetails
- * A bean containing details about the request that is about to be processed, including details such as the
- * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
- * pulled out of the {@link HttpServletRequest servlet request}.
- * @param theResponseObject
- * The actual object which is being streamed to the client as a response
- * @return Return true
if processing should continue normally. This is generally the right thing to do.
- * If your interceptor is providing a response rather than letting HAPI handle the response normally, you
- * must return false
. In this case, no further processing will occur and no further interceptors
- * will be called.
- * @throws AuthenticationException
- * This exception may be thrown to indicate that the interceptor has detected an unauthorized access
- * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
+ * Use {@link #outgoingResponse(RequestDetails, IBaseResource, HttpServletRequest, HttpServletResponse)} instead
+ *
+ * @deprecated As of HAPI FHIR 3.2.0, this method is deprecated and will be removed in a future version of HAPI FHIR.
*/
+ @Deprecated
boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject);
/**
* This method is called after the server implementation method has been called, but before any attempt to stream the
- * response back to the client
+ * response back to the client.
*
* @param theRequestDetails
* A bean containing details about the request that is about to be processed, including details such as the
* resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
* pulled out of the {@link HttpServletRequest servlet request}.
* @param theResponseObject
- * The actual object which is being streamed to the client as a response
+ * The actual object which is being streamed to the client as a response. This may be
+ * null
if the response does not include a resource.
* @param theServletRequest
* The incoming request
* @param theServletResponse
@@ -246,49 +206,19 @@ public interface IServerInterceptor {
throws AuthenticationException;
/**
- * This method is called after the server implementation method has been called, but before any attempt to stream the
- * response back to the client
- *
- * @param theRequestDetails
- * A bean containing details about the request that is about to be processed, including details such as the
- * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
- * pulled out of the {@link HttpServletRequest servlet request}.
- * @param theResponseObject
- * The actual object which is being streamed to the client as a response
- * @return Return true
if processing should continue normally. This is generally the right thing to do.
- * If your interceptor is providing a response rather than letting HAPI handle the response normally, you
- * must return false
. In this case, no further processing will occur and no further interceptors
- * will be called.
- * @throws AuthenticationException
- * This exception may be thrown to indicate that the interceptor has detected an unauthorized access
- * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
+ * Use {@link #outgoingResponse(RequestDetails, IBaseResource, HttpServletRequest, HttpServletResponse)} instead
+ *
+ * @deprecated As of HAPI FHIR 3.2.0, this method is deprecated and will be removed in a future version of HAPI FHIR.
*/
+ @Deprecated
boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject);
/**
- * This method is called after the server implementation method has been called, but before any attempt to stream the
- * response back to the client
- *
- * @param theRequestDetails
- * A bean containing details about the request that is about to be processed, including details such as the
- * resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
- * pulled out of the {@link HttpServletRequest servlet request}.
- * @param theResponseObject
- * The actual object which is being streamed to the client as a response
- * @param theServletRequest
- * The incoming request
- * @param theServletResponse
- * The response. Note that interceptors may choose to provide a response (i.e. by calling
- * {@link HttpServletResponse#getWriter()}) but in that case it is important to return false
- * to indicate that the server itself should not also provide a response.
- * @return Return true
if processing should continue normally. This is generally the right thing to do.
- * If your interceptor is providing a response rather than letting HAPI handle the response normally, you
- * must return false
. In this case, no further processing will occur and no further interceptors
- * will be called.
- * @throws AuthenticationException
- * This exception may be thrown to indicate that the interceptor has detected an unauthorized access
- * attempt. If thrown, processing will stop and an HTTP 401 will be returned to the client.
+ * Use {@link #outgoingResponse(RequestDetails, IBaseResource, HttpServletRequest, HttpServletResponse)} instead
+ *
+ * @deprecated As of HAPI FHIR 3.2.0, this method is deprecated and will be removed in a future version of HAPI FHIR.
*/
+ @Deprecated
boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException;
/**
@@ -328,7 +258,7 @@ public interface IServerInterceptor {
*/
void processingCompletedNormally(ServletRequestDetails theRequestDetails);
- public static class ActionRequestDetails {
+ class ActionRequestDetails {
private final FhirContext myContext;
private final IIdType myId;
private final String myResourceType;
diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java
index 497ced4f3e9..11df89bfa80 100644
--- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java
+++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java
@@ -1,13 +1,12 @@
package ca.uhn.fhir.rest.server;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
@@ -15,6 +14,7 @@ import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import ca.uhn.fhir.rest.annotation.Create;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -26,7 +26,9 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Patient;
+import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.*;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
@@ -56,7 +58,7 @@ public class InterceptorDstu3Test {
@After
public void after() {
- for (IServerInterceptor next : new ArrayList