0

I`m programming a little file server which gets documents via HTTP-POST requests from another software.

The requests are always "multipart/form-data" types, so I`d like to split it via .getParts();

Unfortunately I always get a "java.io.IOException: Incomplete parts" or it does not find the part.

Is there something wrong with my code or is there a problem with the request?

I`m using a embedded Jetty server with Eclipse

    public void create_document() {
    String lv_path = gr_request.getParameter("contRep") + File.separator + gr_request.getParameter("docId");
    Part lr_part = null;
    try {
        System.out.println(gr_request.getContentType());
        //for testing
        Part lr_test = gr_request.getPart("data");
        System.out.println("1");
        System.out.println(lr_test);

        //the actual part
        Collection<Part> lr_parts = gr_request.getParts();
        for (Iterator<Part> i = lr_parts.iterator(); i.hasNext();) {
            lr_part = ((Iterator<Part>) lr_parts).next();

            //again for testing
            System.out.println("content Type" + lr_part.getContentType());
            System.out.println("name" + lr_part.getName());
            System.out.println("content Type" + lr_part.getContentType());
            String test = lv_path + ".jpg";
            lr_part.write(test);

the log is

2017-11-28 11:07:47.941:INFO:oejs.Server:main: jetty-9.0.4.v20130625
2017-11-28 11:07:48.222:INFO:oejs.ServerConnector:main: StartedServerConnector@7165cbeb{HTTP/1.1}{0.0.0.0:1090}
Erkannte Aktion: CREATE_DOCUMENT
2017-11-2811:07:54.469:WARN:oejs.Request:qtp424058530-15:java.io.IOException:Incomplete parts
multipart/form-data; boundary=KoZIhvcNAQcB
1
null

The MultiPartConfig was done by

MultipartConfigElement multipartConfigElement = newMultipartConfigElement((String)null);
ir_request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, multipartConfigElement);

Beginning of the body of a transmitted PDF file:

--KoZIhvcNAQcB
Content-Disposition: form-data; filename="data"
X-compId: data
Content-Type: application/pdf
Content-Length: 182370

%PDF-1.7
%ยตยตยตยต
1 0 obj
...and so on...
182188
%%EOF
--KoZIhvcNAQcB--

1 Answers1

0

It seems that there is a problem with the request. I changed the "filename" tag to "name" while receiving the request. Now it's running