在理解JAX-WS服务中的MTOM概念时,我有点困惑。我有一个have服务,它公开了一个返回Image的方法。下面是SIB和publisher代码
//@MTOM
@WebService(endpointInterface= "com.test.clear.TestImageInterface")
@BindingType(value = SOAPBinding.SOAP11HTTP_MTOM_BINDING)
public class TestImageImpl implements TestImageInterface{
@WebMethod
@Override
// Create a named image from the raw bytes.
public Image getImageByName(String name) {
Path path = Paths.get("..\..\..\"+name);
try {
byte[ ] bytes = Files.readAllBytes(path);
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Iterator iterators = ImageIO.getImageReadersByFormatName("jpeg");
ImageReader iterator = (ImageReader) iterators.next();
ImageInputStream iis = ImageIO.createImageInputStream(in);
iterator.setInput(iis, true);
return iterator.read(0);
}
catch(IOException e) {
System.err.println(e);
return null;
}
}
}publisher >>
Endpoint.publish("http://localhost:8080/TestWS/getImage", new TestImageImpl());我的困惑是理解什么时候使用@MTOM,什么时候使用@BindingType注释。如果我使用其中一个注解或同时使用两个注解,我看不到publisher类发布的WSDL有什么不同。下面是生成的WSDL
<wsp:Policy wsu:Id="TestImageImplPortBinding_MTOM_Policy">
<ns1:OptimizedMimeSerialization xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" wsp:Optional="true"/>
<binding name="TestImageImplPortBinding" type="tns:TestImageInterface">
<wsp:PolicyReference URI="#TestImageImplPortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
...
...
</definitions>另外,我也看不到从Service获取的SOAP响应有什么不同。ie:我得到了
< Xop:include href:cid / > and got file as attachment in 这是否意味着在服务器端启用MTOM可以使用这两个注释中的任何一个?
在从SIB中删除两个注释后,我尝试在publisher端以编程方式设置MTOM,如下所示:
SOAPBinding binding = (SOAPBinding) endpoint.getBinding();
binding.setMTOMEnabled(true);但是,生成的WSDL根本没有MTOM策略。
那么,当需要以编程方式设置MTOM时呢?
有人能解释一下MIME类型和MTOM的工作原理吗?
提前谢谢你。
发布于 2017-11-09 15:35:10
https://stackoverflow.com/questions/47180203
复制相似问题