diff --git a/hapi-fhir-client-okhttp/src/main/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulRequest.java b/hapi-fhir-client-okhttp/src/main/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulRequest.java index bd34fd8575c..fcde3b710d4 100644 --- a/hapi-fhir-client-okhttp/src/main/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulRequest.java +++ b/hapi-fhir-client-okhttp/src/main/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulRequest.java @@ -105,4 +105,8 @@ public class OkHttpRestfulRequest extends BaseHttpRequest implements IHttpReques myRequestBuilder.removeHeader(theHeaderName); } + @Override + public String toString() { + return getHttpVerbName() + " " + getUri(); + } } diff --git a/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulRequestTest.java b/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulRequestTest.java new file mode 100644 index 00000000000..d62a99d96f2 --- /dev/null +++ b/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulRequestTest.java @@ -0,0 +1,27 @@ +package ca.uhn.fhir.okhttp.client; + +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class OkHttpRestfulRequestTest { + + @Test + void toString_afterCreation_GetUsefulDataForLogging() { + String theUrl = "https://example.com/fhir/meta"; + OkHttpRestfulClientFactory clientFactory = new OkHttpRestfulClientFactory(); + + OkHttpRestfulRequest okHttpRestfulRequest = new OkHttpRestfulRequest(clientFactory.getNativeClient(), theUrl, RequestTypeEnum.GET, null); + assertEquals("GET https://example.com/fhir/meta", okHttpRestfulRequest.toString()); + } + + @Test + void toString_afterCreationPostUsefulDataForLogging() { + String theUrl = "https://another.example.com/fhir/Task"; + OkHttpRestfulClientFactory clientFactory = new OkHttpRestfulClientFactory(); + + OkHttpRestfulRequest okHttpRestfulRequest = new OkHttpRestfulRequest(clientFactory.getNativeClient(), theUrl, RequestTypeEnum.POST, null); + assertEquals("POST https://another.example.com/fhir/Task", okHttpRestfulRequest.toString()); + } +} diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/4270-fix-logging-interceptor-with-okhttp.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/4270-fix-logging-interceptor-with-okhttp.yaml new file mode 100644 index 00000000000..4ff7457d8b4 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/4270-fix-logging-interceptor-with-okhttp.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 4270 +title: "When using the client LoggingInterceptor with OkHttp clients, the request URL was not + correctly logged. Thanks to Roel Scholten for the pull request!" diff --git a/pom.xml b/pom.xml index 4d54d650c2c..7b2eea3bd18 100644 --- a/pom.xml +++ b/pom.xml @@ -830,6 +830,10 @@ Vitor Pamplona PathCheck Foundation / EyeNetra Inc + + Roel-Scholten + Roel Scholten +