4269 implement a toString for OkHttpRestfulRequest to have better log… (#4270)

* 4269 implement a toString for OkHttpRestfulRequest to have better loggin…

Implement a toString for OkHttpRestfulRequest logging to have better logging.
Currently this still differs from the ApacheHttpRequest.java as we do not have the used protocol (http/1.1/alpn) on request creation. This is added to the Response object.

* Add credit for #4269

Co-authored-by: James Agnew <jamesagnew@gmail.com>
This commit is contained in:
Roel-Scholten 2022-11-11 16:56:12 +01:00 committed by GitHub
parent 9a45576793
commit e5cf3ef396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 0 deletions

View File

@ -105,4 +105,8 @@ public class OkHttpRestfulRequest extends BaseHttpRequest implements IHttpReques
myRequestBuilder.removeHeader(theHeaderName); myRequestBuilder.removeHeader(theHeaderName);
} }
@Override
public String toString() {
return getHttpVerbName() + " " + getUri();
}
} }

View File

@ -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());
}
}

View File

@ -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!"

View File

@ -830,6 +830,10 @@
<name>Vitor Pamplona</name> <name>Vitor Pamplona</name>
<organization>PathCheck Foundation / EyeNetra Inc</organization> <organization>PathCheck Foundation / EyeNetra Inc</organization>
</developer> </developer>
<developer>
<id>Roel-Scholten</id>
<name>Roel Scholten</name>
</developer>
</developers> </developers>
<licenses> <licenses>