java - Jetty 12 proxy server file upload streaming does not work - Stack Overflow

I am migrating from jetty 11 to jetty 12 embedded proxy server. The app is a spring boot proxy server w

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742311657a4420012.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信