Mule/Jersey 针对文件上传请求返回 400

发布于 2024-11-17 10:17:07 字数 1741 浏览 1 评论 0原文

我正在编写一个使用 Jersey 实现一些 Web 服务的 Mule 应用程序。我想上传一个文件。我编写了以下框架

@POST
@Path("/getHtml")
@Consumes("multipart/form-data")
@Produces("text/plain")
public String getSummaryHtml(
        @FormDataParam("payload") String junk,
        @FormDataParam("x12file") InputStream file
        ) {
    LOG.info("called getSummaryHtml");

    return "got";
}

如果两个 FormDataParam 参数被注释掉,我就能够卷曲到服务器并获得预期的响应。在取消注释参数的情况下,以下curl(与之前相同)会得到 400 错误响应。

curl -v -X POST --form [email protected] --form payload=junk http://localhost:8080/jersey/X12ToSummaryHtml/getHtml/

* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /jersey/X12ToSummaryHtml/getHtml/ HTTP/1.1
> User-Agent: curl/7.21.3 (i386-redhat-linux-gnu) libcurl/7.21.3 NSS/3.12.10.0 zlib/1.2.5 libidn/1.19 libssh2/1.2.7
> Host: localhost:8080
> Accept: */*
> Content-Length: 2706
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------55b24ac88245
> 
< HTTP/1.1 100 Continue
< Content-Type: text/plain
< Content-Length: 0
< Connection: close
< HTTP/1.1 400 Bad Request
< Content-Type: multipart/form-data; boundary=----------------------------55b24ac88245
< Date: Sat, 25 Jun 2011 01:29:10 MDT
< Server: Mule Core/3.1.1
< Expires: Sat, 25 Jun 2011 01:29:10 MDT
< http.status: 400
< MULE_ENCODING: UTF-8
< Transfer-Encoding: chunked
< Connection: close
< 
* Closing connection #0

我需要做什么才能成功将文件发布到此代码并处理它?

I'm writing a mule application that implements some web services using Jersey. I'd like to upload a file. I've written the following skeleton

@POST
@Path("/getHtml")
@Consumes("multipart/form-data")
@Produces("text/plain")
public String getSummaryHtml(
        @FormDataParam("payload") String junk,
        @FormDataParam("x12file") InputStream file
        ) {
    LOG.info("called getSummaryHtml");

    return "got";
}

If the two FormDataParam parameters are commented out, I am able to curl to the server and get the expected response. With the parameters uncommented, the following curl (same one that works previously) gets me a 400 error in response.

curl -v -X POST --form [email protected] --form payload=junk http://localhost:8080/jersey/X12ToSummaryHtml/getHtml/

* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /jersey/X12ToSummaryHtml/getHtml/ HTTP/1.1
> User-Agent: curl/7.21.3 (i386-redhat-linux-gnu) libcurl/7.21.3 NSS/3.12.10.0 zlib/1.2.5 libidn/1.19 libssh2/1.2.7
> Host: localhost:8080
> Accept: */*
> Content-Length: 2706
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------55b24ac88245
> 
< HTTP/1.1 100 Continue
< Content-Type: text/plain
< Content-Length: 0
< Connection: close
< HTTP/1.1 400 Bad Request
< Content-Type: multipart/form-data; boundary=----------------------------55b24ac88245
< Date: Sat, 25 Jun 2011 01:29:10 MDT
< Server: Mule Core/3.1.1
< Expires: Sat, 25 Jun 2011 01:29:10 MDT
< http.status: 400
< MULE_ENCODING: UTF-8
< Transfer-Encoding: chunked
< Connection: close
< 
* Closing connection #0

What do I need to do to successfully POST a file to this code and process it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文