Revert the revert

This commit is contained in:
Luke deGruchy 2023-11-30 18:54:49 -05:00
parent 8237c0795d
commit 0c8258f93c
3 changed files with 24 additions and 1 deletions

View File

@ -93,6 +93,10 @@ public enum Pointcut implements IPointcut {
* <li> * <li>
* ca.uhn.fhir.rest.client.api.IRestfulClient - The client object making the request * ca.uhn.fhir.rest.client.api.IRestfulClient - The client object making the request
* </li> * </li>
* <li>
* ca.uhn.fhir.rest.client.api.ClientResponseContext - Contains an IHttpRequest, an IHttpResponse, and an IRestfulClient
* and also allows the client to mutate the contained IHttpResponse
* </li>
* </ul> * </ul>
* </p> * </p>
* Hook methods must return <code>void</code>. * Hook methods must return <code>void</code>.
@ -101,7 +105,8 @@ public enum Pointcut implements IPointcut {
void.class, void.class,
"ca.uhn.fhir.rest.client.api.IHttpRequest", "ca.uhn.fhir.rest.client.api.IHttpRequest",
"ca.uhn.fhir.rest.client.api.IHttpResponse", "ca.uhn.fhir.rest.client.api.IHttpResponse",
"ca.uhn.fhir.rest.client.api.IRestfulClient"), "ca.uhn.fhir.rest.client.api.IRestfulClient",
"ca.uhn.fhir.rest.client.api.ClientResponseContext"),
/** /**
* <b>Server Hook:</b> * <b>Server Hook:</b>

View File

@ -36,6 +36,7 @@ import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.RequestFormatParamStyleEnum; import ca.uhn.fhir.rest.api.RequestFormatParamStyleEnum;
import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.client.api.ClientResponseContext;
import ca.uhn.fhir.rest.client.api.IHttpClient; import ca.uhn.fhir.rest.client.api.IHttpClient;
import ca.uhn.fhir.rest.client.api.IHttpRequest; import ca.uhn.fhir.rest.client.api.IHttpRequest;
import ca.uhn.fhir.rest.client.api.IHttpResponse; import ca.uhn.fhir.rest.client.api.IHttpResponse;
@ -352,13 +353,24 @@ public abstract class BaseClient implements IRestfulClient {
response = httpRequest.execute(); response = httpRequest.execute();
final Class<? extends IBaseResource> returnType = (binding instanceof ResourceResponseHandler)
? ((ResourceResponseHandler<? extends IBaseResource>) binding).getReturnType()
: null;
final ClientResponseContext clientResponseContext =
new ClientResponseContext(httpRequest, response, this, getFhirContext(), returnType);
HookParams responseParams = new HookParams(); HookParams responseParams = new HookParams();
responseParams.add(IHttpRequest.class, httpRequest); responseParams.add(IHttpRequest.class, httpRequest);
responseParams.add(IHttpResponse.class, response); responseParams.add(IHttpResponse.class, response);
responseParams.add(IRestfulClient.class, this); responseParams.add(IRestfulClient.class, this);
responseParams.add(ClientResponseContext.class, clientResponseContext);
getInterceptorService().callHooks(Pointcut.CLIENT_RESPONSE, responseParams); getInterceptorService().callHooks(Pointcut.CLIENT_RESPONSE, responseParams);
// Replace the contents of the response with whatever the hook returned, or the same response as before if
// it no-op'd
response = clientResponseContext.getHttpResponse();
String mimeType; String mimeType;
if (Constants.STATUS_HTTP_204_NO_CONTENT == response.getStatus()) { if (Constants.STATUS_HTTP_204_NO_CONTENT == response.getStatus()) {
mimeType = null; mimeType = null;

View File

@ -0,0 +1,6 @@
---
type: add
issue: 5502
jira: SMILE-7262
title: "It is now possible to mutate an HTTP response from the CLIENT_RESPONSE Pointcut, and pass this mutated response
to downstream processing."