Skip to content

Commit ce71fcc

Browse files
laurittrask
andauthored
Read response body in jax-rs client and google http client tests (#5672)
* Read response body in jax-rs client and google http client tests * Apply suggestions from code review Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]>
1 parent bb677a0 commit ce71fcc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

instrumentation/google-http-client-1.19/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/AbstractGoogleHttpClientTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ protected final HttpRequest buildRequest(String method, URI uri, Map<String, Str
7373
@Override
7474
protected final int sendRequest(
7575
HttpRequest request, String method, URI uri, Map<String, String> headers) throws Exception {
76-
return sendRequest(request).getStatusCode();
76+
HttpResponse response = sendRequest(request);
77+
// read request body to avoid broken pipe errors on the server side
78+
response.parseAsString();
79+
return response.getStatusCode();
7780
}
7881

7982
protected abstract HttpResponse sendRequest(HttpRequest request) throws Exception;

instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
4444
try {
4545
def body = BODY_METHODS.contains(method) ? Entity.text("") : null
4646
def response = request.build(method, body).invoke()
47+
// read response body to avoid broken pipe errors on the server side
48+
response.readEntity(String)
4749
try {
4850
response.close()
4951
} catch (IOException ignore) {
@@ -61,6 +63,8 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
6163
request.async().method(method, (Entity) body, new InvocationCallback<Response>() {
6264
@Override
6365
void completed(Response response) {
66+
// read response body
67+
response.readEntity(String)
6468
requestResult.complete(response.status)
6569
}
6670

0 commit comments

Comments
 (0)