带有bodyfile的wiremock offmoryError用于大文件
在以下存根请求中,我将与bodyfile
一起使用加载大文件(> 300mb
)从本地磁盘上的特定位置使用流:
public void mockGetUrlContent(String url) {
stubFor(get(urlEqualTo(url))
.willReturn(ok()
.withBodyFile(FilenameUtils.getName(url))));
}
一旦调用了存根,wiremock tries tries要完成服务事件并为了记录响应,它使用 方法下面:
public static LoggedResponse from(Response response) {
return new LoggedResponse(
response.getStatus(),
response.getHeaders() == null || response.getHeaders().all().isEmpty()
? null
: response.getHeaders(),
response.getBody(),
response.getFault());
}
当访问WireMock的wempons> Response> Response>
方法它将流中的流转换为
byte []
,在此点上,它会在OUTOFMEMORYERROR
(Java Heap Space)上吹来
public byte[] getBody() {
try (InputStream stream = bodyStreamSource == null ? null : getBodyStream()) {
return stream == null ? null : ByteStreams.toByteArray(stream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
。错误的?
高度赞赏您的帮助!
In the following stub request, I use withBodyFile
which loads large files (>300MB
) from specific locations on local disk using streams:
public void mockGetUrlContent(String url) {
stubFor(get(urlEqualTo(url))
.willReturn(ok()
.withBodyFile(FilenameUtils.getName(url))));
}
Once the stub is being called, wiremock tries to complete a served event and in order to log the response it uses the from
method below:
public static LoggedResponse from(Response response) {
return new LoggedResponse(
response.getStatus(),
response.getHeaders() == null || response.getHeaders().all().isEmpty()
? null
: response.getHeaders(),
response.getBody(),
response.getFault());
}
When reached to wiremock's Response
getBody
method it converts the stream in to byte[]
and in that points it blows on OutOfMemoryError
(Java heap space).:
public byte[] getBody() {
try (InputStream stream = bodyStreamSource == null ? null : getBodyStream()) {
return stream == null ? null : ByteStreams.toByteArray(stream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Any ideas about what am I doing wrong?
Your help is highly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WireMock 2.34.0有解决方案。
为了确保已记录的响应主体仅限于特定尺寸,您需要使用新的配置参数启动WireMock,
在运行独立时,指定字节中的最大大小添加CLI参数:
在Java中运行时,将以下内容添加到配置构建器:
WireMock 2.34.0 has a solution to this.
To ensure that logged response bodies are limited to a particular size you need to start WireMock with a new configuration parameter specifying the max size in bytes
When running standalone add the CLI parameter:
When running in Java add the following to the configuration builder: