Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Missing initial multi part boundary

Hello I'm tryng to uploading a file on an embedded Jetty 9.2.1 server.

I use jetty HttpClient class, to upload in HTTPS.

--------------------------------------------------------
            SslContextFactory sslContextFactory = new SslContextFactory(true);
            //HttpClientTransportOverHTTP t = new HttpClientTransportOverHTTP();
            httpClient = new HttpClient( sslContextFactory);


---------------------------------------------------------


        Request r = httpClient.newRequest("https://localhost:8000/UploadService);
        r.header(HttpHeader.CONTENT_TYPE, "multipart/form-data");
        r.file(Paths.get(aFileArrToUpload[0].getAbsolutePath()), "application/pdf");
        Enumeration keys = aParameters.keys();
        while(keys.hasMoreElements()){
            String vParName = (String)keys.nextElement();
            String vParvalue = aParameters.getProperty(vParName);
            r.param(vParName, vParvalue);
        }
        r.method(HttpMethod.POST);
        ContentResponse response = r.send();


----------------------------------------------------------
UploadServlet is annotated by

@MultipartConfig(fileSizeThreshold=1024*1024*2, // 2MB
maxFileSize=1024*1024*10,      // 10MB
maxRequestSize=1024*1024*50)   // 50MB
public class UploadServlet extends UIAbstractServlet {

    private static final MultipartConfigElement MULTI_PART_CONFIG = new MultipartConfigElement(System.getProperty("java.io.tmpdir"));

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse aResponse) throws ServletException, IOException {
        if (request.getContentType() != null && request.getContentType().startsWith("multipart/form-data")) {
              request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, MULTI_PART_CONFIG);
            }
       
        Collection<Part> p = request.getParts();

        for (Iterator<Part> iterator = p.iterator(); iterator.hasNext();)
        {
            Part part = iterator.next();
            System.out.println( "NAME=" + part.getName() );
           
        }
       
    }

--------------------------------------------
SERVER

 String wardir = "target/sample-webapp-1-SNAPSHOT";

             iContext = new WebAppContext();
             iContext.setResourceBase(wardir);
             iContext.setDescriptor(wardir + "/WEB-INF/web.xml");
             iContext.setConfigurations(new Configuration[] {
                     new AnnotationConfiguration(), new WebXmlConfiguration(),
                     new WebInfConfiguration(), new JettyWebXmlConfiguration(),
                     new PlusConfiguration(), new MetaInfConfiguration(),
                     new FragmentConfiguration(), new EnvConfiguration() });

             iContext.setContextPath("/");
             iContext.setParentLoaderPriority(true);

 iServer.setHandler(iContext);

ServletHolder sh = new ServletHolder(new Smeup.smeui.uimainmodule.internalappserver.servlet.UploadServlet());
            sh.getRegistration().setMultipartConfig(new MultipartConfigElement(vTmpFolder.getAbsolutePath(), 1048576, 1048576, 262144));
            iContext.addServlet(sh, "/UploadService");

-----------------------------------------------------------------

When I try to get part in the servlet i have an exception:

java.io.IOException: Missing initial multi part boundary
    at org.eclipse.jetty.util.MultiPartInputStreamParser.parse(MultiPartInputStreamParser.java:515)
    at org.eclipse.jetty.util.MultiPartInputStreamParser.getParts(MultiPartInputStreamParser.java:408)
    at org.eclipse.jetty.server.Request.getParts(Request.java:2144)
    at org.eclipse.jetty.server.Request.getParts(Request.java:2123)
    at Smeup.smeui.uimainmodule.internalappserver.servlet.UploadServlet.doPut(UploadServlet.java:49)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:566)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98)
    at org.eclipse.jetty.server.Server.handle(Server.java:461)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:534)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:745)







Back to the top