我正在尝试将带有 axis1.4 客户端的文件发送到 jaxws 服务。我的客户端代码如下。
System.out.println(service.getCalcImplPort().getFile(new DataHandler(new DataSource() {
@Override
public OutputStream getOutputStream() throws IOException {
// TODO Auto-generated method stub
return null;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "abc.txt";
}
@Override
public InputStream getInputStream() throws IOException {
InputStream bs = new ByteArrayInputStream("Hello world".getBytes());
return bs;
}
@Override
public String getContentType() {
// TODO Auto-generated method stub
return "application/soap+xml";
}
})));
当我从 tcpmon 查看时,我看到生成了下面的消息。
------=_Part_0_1601756168.1386618236799
内容类型:文本/xml;字符集=UTF-8 内容传输编码:二进制 内容编号:
------=_Part_0_1601756168.1386618236799 内容类型:application/soap+xml 内容传输编码:二进制 内容编号:
Hello World ------=_Part_0_1601756168.1386618236799--
XML部分是
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getFile xmlns="http://ws.kasim.com/"><arg0 href="cid:5C354342D8307DD2EC87841AD94BCCB0" xsi:type="xsd:base64Binary" xmlns=""/></getFile></soapenv:Body></soapenv:Envelope>
当我在服务器端检查时,我发现服务的 DataHandler 参数没有发送数据。首先,这是一条有效的 mtom 消息吗?如果没有,有人可以告诉我这里缺少什么吗?
谢谢。
最佳答案
我在互联网上搜索了很长时间后找到了解决方案。问题是我没有在客户端 stub 文件中设置 mtom 属性。添加下面的代码后,它开始工作。我没有删除问题,可能有人需要它。
call.setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT, Call.ATTACHMENT_ENCAPSULATION_FORMAT_MTOM);
关于java - axis1.4客户端使用Mtom发送文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20479408/