【问题标题】:java.io.IOException: Incomplete parts with embedded Jetty Serverjava.io.IOException:嵌入式 Jetty 服务器的不完整部分
【发布时间】:2017-11-28 10:38:34
【问题描述】:

我正在编写一个小型文件服务器,它通过来自另一个软件的 HTTP-POST 请求获取文档。

请求总是“multipart/form-data”类型,所以我想通过 .getParts() 拆分它;

不幸的是,我总是收到“java.io.IOException: Incomplete parts”或者找不到该部分。

我的代码有问题还是请求有问题?

我在 Eclipse 中使用嵌入式 Jetty 服务器

    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);

日志是

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

MultiPartConfig 由

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

传输的 PDF 文件正文的开头:

--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--

【问题讨论】:

    标签: java multipart embedded-jetty


    【解决方案1】:

    请求似乎有问题。 我在接收请求时将“文件名”标签更改为“名称”。 现在它正在运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-18
      • 2012-04-21
      • 2022-08-18
      • 1970-01-01
      • 2013-04-20
      • 2021-11-09
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多