[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jetty-users] Missing initial multi part boundary
|
Federico,
Also the ordering of the Configurations that you are applying to your
WebAppContext is wrong - they must be in a very specific order:
"org.eclipse.jetty.webapp.WebInfConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration",
"org.eclipse.jetty.webapp.MetaInfConfiguration",
"org.eclipse.jetty.webapp.FragmentConfiguration",
"org.eclipse.jetty.plus.webapp.EnvConfiguration",
"org.eclipse.jetty.plus.webapp.PlusConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration",
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration"
See an embedded usage example here:
https://github.com/eclipse/jetty.project/blob/master/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java
Jan
On 30 July 2014 00:45, Federico Fortini <federico.fortini@xxxxxxxxx> wrote:
> 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)
>
>
>
>
>
>
>
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit
> https://dev.eclipse.org/mailman/listinfo/jetty-users
--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
'Expert Jetty/CometD developer,production,operations advice'