使用 Metro,向客户端添加 MTOMFeature 会导致 MIMEParsingException,为什么?
我们有一个支持 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 doTestService 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一番研究和测试,答案是:
static excepts = ["/services/*"]
那样排除服务的过滤,它就可以工作。After some research and testing, the answers are:
static excludes = ["/services/*"]
in UrlMappings.groovy, it works.