|
21 | 21 | import io.qameta.allure.attachment.DefaultAttachmentProcessor; |
22 | 22 | import io.qameta.allure.attachment.FreemarkerAttachmentRenderer; |
23 | 23 | import io.qameta.allure.attachment.http.HttpResponseAttachment; |
24 | | -import org.apache.http.HttpEntity; |
25 | 24 | import org.apache.http.HttpResponse; |
26 | 25 | import org.apache.http.HttpResponseInterceptor; |
27 | | -import org.apache.http.entity.HttpEntityWrapper; |
| 26 | +import org.apache.http.entity.BufferedHttpEntity; |
28 | 27 | import org.apache.http.protocol.HttpContext; |
29 | 28 | import org.apache.http.util.EntityUtils; |
30 | 29 |
|
31 | | -import java.io.ByteArrayInputStream; |
32 | 30 | import java.io.IOException; |
33 | | -import java.io.InputStream; |
34 | | -import java.nio.charset.StandardCharsets; |
35 | 31 | import java.util.stream.Stream; |
36 | 32 |
|
37 | 33 | import static io.qameta.allure.attachment.http.HttpResponseAttachment.Builder.create; |
@@ -67,37 +63,17 @@ public void process(final HttpResponse response, |
67 | 63 | .forEach(header -> builder.setHeader(header.getName(), header.getValue())); |
68 | 64 |
|
69 | 65 | if (response.getEntity() != null) { |
70 | | - final LoggableEntity loggableEntity = new LoggableEntity(response.getEntity()); |
71 | | - response.setEntity(loggableEntity); |
| 66 | + if (!response.getEntity().isRepeatable()) { |
| 67 | + final BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(response.getEntity()); |
| 68 | + response.setEntity(bufferedEntity); |
| 69 | + } |
72 | 70 |
|
73 | | - builder.setBody(loggableEntity.getBody()); |
| 71 | + builder.setBody(EntityUtils.toString(response.getEntity())); |
74 | 72 | } else { |
75 | 73 | builder.setBody("No body present"); |
76 | 74 | } |
77 | 75 |
|
78 | 76 | final HttpResponseAttachment responseAttachment = builder.build(); |
79 | 77 | processor.addAttachment(responseAttachment, renderer); |
80 | 78 | } |
81 | | - |
82 | | - /** |
83 | | - * Required to allow consume httpEntity twice. |
84 | | - */ |
85 | | - private static class LoggableEntity extends HttpEntityWrapper { |
86 | | - |
87 | | - private final byte[] rawContent; |
88 | | - |
89 | | - LoggableEntity(final HttpEntity wrappedEntity) throws IOException { |
90 | | - super(wrappedEntity); |
91 | | - rawContent = EntityUtils.toByteArray(wrappedEntity); |
92 | | - } |
93 | | - |
94 | | - public String getBody() { |
95 | | - return new String(rawContent, StandardCharsets.UTF_8); |
96 | | - } |
97 | | - |
98 | | - @Override |
99 | | - public InputStream getContent() { |
100 | | - return new ByteArrayInputStream(rawContent); |
101 | | - } |
102 | | - } |
103 | 79 | } |
0 commit comments