Skip to content

Commit a8116b0

Browse files
committed
fix: override writeTo to allow repeated consumption
1 parent fa58816 commit a8116b0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

arex-instrumentation/httpclient/arex-httpclient-apache-v4/src/main/java/io/arex/inst/httpclient/apache/common/ApacheHttpClientAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static void bufferRequestEntity(HttpEntityEnclosingRequest enclosingReque
142142
try {
143143
enclosingRequest.setEntity(new ArexBufferedHttpEntity(enclosingRequest.getEntity()));
144144
} catch (Exception ignore) {
145-
// ignore exception
145+
// ignore exception, fallback to original entity and ignore recording
146146
}
147147
}
148148

@@ -153,7 +153,7 @@ public static void bufferResponseEntity(HttpResponse response) {
153153
try {
154154
EntityUtils.updateEntity(response, new ArexBufferedHttpEntity(response.getEntity()));
155155
} catch (Exception e) {
156-
// ignore exception
156+
// ignore exception, fallback to original entity and ignore recording
157157
}
158158
}
159159

arex-instrumentation/httpclient/arex-httpclient-apache-v4/src/main/java/io/arex/inst/httpclient/apache/common/ArexBufferedHttpEntity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.ByteArrayOutputStream;
55
import java.io.IOException;
66
import java.io.InputStream;
7+
import java.io.OutputStream;
78
import org.apache.http.HttpEntity;
89
import org.apache.http.entity.HttpEntityWrapper;
910

@@ -36,4 +37,13 @@ public ArexBufferedHttpEntity(HttpEntity wrappedEntity) throws IOException {
3637
public InputStream getContent() throws IOException {
3738
return new ByteArrayInputStream(buffer);
3839
}
40+
41+
@Override
42+
public void writeTo(final OutputStream outStream) throws IOException {
43+
if (this.buffer != null) {
44+
outStream.write(this.buffer);
45+
} else {
46+
super.writeTo(outStream);
47+
}
48+
}
3949
}

0 commit comments

Comments
 (0)