我正在使用MTOM将附加文件从客户端流式传输到服务器.
应用MTOM并将文件作为二进制流传输.但根Content-Type始终是“text / xml”,应该是“application / xml xop”.
问题仅发生在websphere中.内容类型在websphere中设置为“text / xml”.
在websphere liberity配置文件中,内容类型设置为“application / xml xop”
------=_Part_7283_-2062365125.1458743649653
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <511212039242.1458743649653.IBM.WEBSERVICES@lsrv4665.linux.rabobank.nl>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<Content><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:58cf03d2-322f-4819-80fb-3b001f497d12%40www.test.com"/>
</Content>
</soapenv:Body>
</soapenv:Envelope>
Content-Type: application/pdf; name=attachment.pdf
Content-Transfer-Encoding: binary
最佳答案 我收集了几个答案.希望第一个答案适合你.为了预防措施,我还添加了一些链接的其他答案.希望它会拯救你.
ANS-1:
服务器端(Weblogic中的JAX-WS)
使用@MTOM注释或mtom.xml策略
客户端(Weblogic中的JAX-WS)
Pass MTOMFeature() as argument:
MtomService port = service.getMailServicePort(new MTOMFeature());
通过SOAPUI MTOM附件,3个步骤:
>在请求属性中设置启用MTOM = true
>上传附件(例如A3.pdf),注意contentID
>在xml请求中设置MTOM contentID
这是一个带有weblogic图像的完整示例.希望它适合您的问题.(链接为Sending attachment: MTOM / XOP vs SWA and inline attachment)
另一个资源链接:
> Steps to Use MTOM/XOP to Send Binary Data
> Error consuming webservice, content type “application/xop+xml” does
not match expected type “text/xml”
ANS-2:
拉入saaj-impl 1.3.23并且更喜欢javax.xml.soap.*的应用程序类解决了这个问题.
资源链接:https://jira.spring.io/browse/SWS-855
ANS-3:
从mkyong的tutorial开始,可以解决在客户端和服务器上启用mtom的问题.
在服务器上启用MTOM:
启用服务器通过MTOM发送附件非常简单,只需使用javax.xml.ws.soap.MTOM注释Web服务实现类.
在客户端上启用MTOM:
允许客户端通过MTOM向服务器发送附件需要一些额外的努力,请参阅以下示例:
//codes enable MTOM in client
BindingProvider bp = (BindingProvider) imageServer;
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);
ANS-4
积分转到@ BalusC.他的精彩教程给出了一个很棒的答案.
通过HTTP提供页面时,将忽略元标记.
使用JSP时
你应该把<%@ page pageEncoding =“UTF-8”%>在顶部.
使用Servlet时,
你应该做response.setCharacterEncoding(“UTF-8”);.
两者都将在内容类型标头中隐式设置正确的字符集.您可能会发现本文很有用:Unicode – How to get characters right?.对于JSP / Servlet解决方案,请从this chapter开始.
资源链接:
> How to set the “Content-Type … charset” in the request header using a HTML link
对于研究,您可以通过以下方式
对于Java servlet,您应该拥有该行
response.setContentType( “text / html的”);
在doGet或doPost方法的顶部,其中response是对HttpServletResponse的引用.
相关链接:
> How to set up your server to send the correct MIME types
> Character Encoding problem with IBM’s JSF and Ajax
另一个答案
我已经弄明白是什么导致了这个问题,但我不明白为什么.当请求出现错误操作时,该行为就会出现.附件是一个简单的MPG的zip,带有请求,响应和错误规则,以证明这一点.该请求有一个错误操作,一个执行dp:reject(强制错误)的简单xform,以及一个结果操作.错误规则包含结果操作和set var操作.如果您保留on-error in,则响应内容类型将返回为“text / xml”.如果删除on-error,则content-type会正确返回“application / json”. (从以下资源链接复制)
资源链接: