admin管理员组文章数量:1334182
I am migrating from jetty 11 to jetty 12 embedded proxy server. The app is a spring boot proxy server which also proxies file upload request.
In jetty 11, it reads parts from HttpServletRequest and gets inputStream, that gets copied to MultiPartContentProvider as follows
@Override
void sendProxyRequest(HttpServletRequest request, HttpServletResponse response, Request proxyRequest)
Collection<Part> parts = request.getParts();
// get file part
// and then copy to MultiPartContentProvider as below
MultiPartContentProvider multiPart = new MultiPartContentProvider();
multiPart.addFieldPart("field", new StringContentProvider("foo"), null);
multiPart.addFilePart(part.getName(), part.getSubmittedFileName(), new InputStreamContentProvider(part.getInputStream()), headers);
multiPart.close();
proxyRequest.content(multiPart)
// send request successfull
Now , I am migrating to Spring boot 3.3, using jetty 12, servlet 6, jakarta 10. I am using jakarta servlet and not Jetty handlers. The code block is almost similar as before
class Servlet extends .eclipse.jetty.ee10.proxy.ProxyServlet {
@Override
void sendProxyRequest(HttpServletRequest request, HttpServletResponse response, .eclipse.jetty.client.Request proxyRequest)
Collection<Part> parts = request.getParts();
// get file part
// and then copy to MultiPartRequestContent as below
MultiPartRequestContent multiPart = new MultiPartContentProvider();
multiPart.addPart(new MultiPart.ContentSourcePart("field", null, HttpFields.EMPTY, new StringRequestContent("foo")));
multiPart.addPart(new MultiPart.ContentSourcePart(part.getName(), part.getSubmittedFileName(), headers, new InputStreamRequestContent(part.getInputStream())));
multiPart.close();
proxyRequest.body(multiPart)
// send request
}
}
However, in this case, the downstream service can't read file with EOF exception. If I explicitly read the inputStream, copy it to ByteArrayOutputStream
using IO.copy()
method from jetty utils, and provide it to InputStreamRequestContent
as ByteArrayInputStream
, the downstream service gets the complete file.
However reading the inputStream again, copying it to bufferArray and then sending creates a memory overhead.
Is there any suggestion to why the before approach does not work in Jetty 12? Any recommendations will be highly appreciated. I hope this will be useful for others migrating to Jetty 12 as well.
本文标签: javaJetty 12 proxy server file upload streaming does not workStack Overflow
版权声明:本文标题:java - Jetty 12 proxy server file upload streaming does not work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742311657a2450989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论