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() );
}
}
--------------------------------------------
ServletHolder sh = new ServletHolder(new Smeup.smeui.uimainmodule.internalappserver.servlet.UploadServlet());
sh.getRegistration().setMultipartConfig(new MultipartConfigElement(vTmpFolder.getAbsolutePath(), 1048576, 1048576, 262144));