使用 Metro,向客户端添加 MTOMFeature 会导致 MIMEParsingException,为什么?

发布于 2024-09-12 06:37:23 字数 1419 浏览 4 评论 0原文

我们有一个支持 MTOM 的 Web 服务,该服务通过 Grails 和 Metro 1.0.2 插件发布:

@MTOM
@WebService(targetNamespace="http://com.domain")
class TestService {

    @WebMethod
    int uploadFile(@XmlMimeType("application/octet-stream")DataHandler data) {

        data.dataSource.inputStream.eachLine {
            println "reading: -> ${it}"
        }
        return 0
    }
}

遵循此 教程,我们设置了一个 Java 测试客户端,如下所示

public class Client {

    public static void main(String[] argv) {

        MTOMFeature feat = new MTOMFeature();
        TestService service = new TestServiceService().getTestServicePort(feat);
        Map<String, Object> ctxt = ((BindingProvider)service).getRequestContext();
        ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
        service.uploadFile(new DataHandler(new FileDataSource("c:/file.xml")));
    }
}

当我运行客户端时,收到以下错误消息:

由于以下原因无法创建 SOAP 消息 例外: org.jvnet.mimepull.MIMEParsingException: 缺少开始边界

但是,当我不添加 MTOMFeature 时,只是这样做 TestService service = new TestServiceService().getTestServicePort(); 文件上传正常。但据我了解,如果服务器端和客户端均未启用 MTOM,则整个文件将保留在内存中(而不是流式传输)。所以,我的问题是

  • 为什么我们会收到该错误?
  • 如果我不添加 MTOMFeature,文件是否仍会通过 MTOM 传输?

我将非常感谢任何帮助/提示!

We have an MTOM-enabled web service that is published with Grails and the Metro 1.0.2 plugin:

@MTOM
@WebService(targetNamespace="http://com.domain")
class TestService {

    @WebMethod
    int uploadFile(@XmlMimeType("application/octet-stream")DataHandler data) {

        data.dataSource.inputStream.eachLine {
            println "reading: -> ${it}"
        }
        return 0
    }
}

Following this tutorial, we set up a Java test-client that looks like this

public class Client {

    public static void main(String[] argv) {

        MTOMFeature feat = new MTOMFeature();
        TestService service = new TestServiceService().getTestServicePort(feat);
        Map<String, Object> ctxt = ((BindingProvider)service).getRequestContext();
        ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
        service.uploadFile(new DataHandler(new FileDataSource("c:/file.xml")));
    }
}

When I run the client, I get the following error message:

Couldn't create SOAP message due to
exception:
org.jvnet.mimepull.MIMEParsingException:
Missing start boundary

However, when I don't add the MTOMFeature, and just do
TestService service = new TestServiceService().getTestServicePort(); the files gets uploaded ok. But as I understand it if MTOM is not enabled on both server and client side, the entire file will be kept in memory (and not streamed). So, my questions are

  • Why do we get that error?
  • If I don't add the MTOMFeature, will the file still be MTOM-transmitted?

I would be very grateful for any help/tips!

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

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

发布评论

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

评论(1

梦言归人 2024-09-19 06:37:23

经过一番研究和测试,答案是:

  • 错误是因为grails添加了自己的过滤,包括服务。因此,通过像 UrlMappings.groovy 中的 static excepts = ["/services/*"] 那样排除服务的过滤,它就可以工作。
  • 不会。如果没有 MTOMFeature,该文件将被视为请求中的任何其他数据。这意味着存储在内存中,从而导致大文件出现问题。

After some research and testing, the answers are:

  • The error is because grails adds its own filtering, including services. So, by excluding the services from being filtered like this static excludes = ["/services/*"] in UrlMappings.groovy, it works.
  • No. Without the MTOMFeature the file will just be treated as any other data in the request. That means being stored in the memory, thus causing problems for big files.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文