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