MTOM - 根内容类型始终为 text/xml
MTOM - Root content type was always text/xml
我正在使用 MTOM 将附件从客户端流式传输到服务器。
应用了 MTOM,文件以二进制形式流式传输。但是根 Content-Type 总是 "text/xml" 应该是 "application/xml+xop".
问题仅出现在 websphere 中。内容类型在websphere中设置为"text/xml".
在websphere liberity profile中,内容类型设置为"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
我收集了几个答案。希望第一个答案适合你。为了预防起见,我还用 links 添加了一些其他答案。希望它能拯救你。
回答 1:
服务器端(Weblogic 中的JAX-WS)
使用@MTOM
注释或mtom.xml
政策
客户端(Weblogic 中的JAX-WS)
Pass MTOMFeature() as argument:
MtomService port = service.getMailServicePort(new MTOMFeature());
通过 SOAPUI 连接 MTOM,3 个步骤:
Set Enable MTOM = true
在请求属性中
- 上传附件(例..A3.pdf),注意contentID
- 在 xml 请求中设置 MTOM contentID
这是一个带有 weblogic 图像的完整示例。希望它能解决您的问题。(link for Sending attachment: MTOM / XOP vs SWA and inline attachment)
另一个资源Link:
答案 2:
拉入 saaj-impl 1.3.23
并为 javax.xml.soap.*
推荐应用程序 classes 解决了这个问题。
资源Link:https://jira.spring.io/browse/SWS-855
答案 3:
来自mkyong的tutorial,可以解决在客户端和服务器上启用mtom。
在服务器上启用 MTOM:
启用服务器通过 MTOM 发送附件非常简单,只需将 Web 服务实现 class 注释为 javax.xml.ws.soap.MTOM
。
在客户端启用 MTOM:
启用客户端通过 MTOM 将附件发送到服务器需要一些额外的努力,请参见以下示例:
//codes enable MTOM in client
BindingProvider bp = (BindingProvider) imageServer;
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);
答案 4
归功于@BalusC。他通过出色的教程给出了很棒的答案。
当通过 HTTP 提供页面时,元标记将被忽略。
当使用JSP,时
你应该把 <%@ page pageEncoding="UTF-8" %>
放在最上面。
使用Servlet时,
你应该response.setCharacterEncoding("UTF-8");
.
两者都会在内容类型 header 中隐式设置正确的字符集。您可能会发现这篇文章很有用:Unicode - How to get characters right?. For JSP/Servlet solutions, start at this chapter.
资源Link:
为了研究,你可以通过以下
对于 Java servlet,您应该有行
response.setContentType("text/html");
在 doGet
或 doPost
方法的顶部,其中 response 是对 HttpServletResponse
.
的引用
相关Link:
- How to set up your server to send the correct MIME types
- Character Encoding problem with IBM's JSF and Ajax
另一个答案
我已经弄清楚是什么导致了这个问题,但我不明白为什么。当对请求执行 on-error 操作时,该行为就会表现出来。附件是一个简单 MPG 的 zip,其中包含演示此操作的请求、响应和错误规则。该请求有一个 on-error 操作,一个执行 dp:reject(强制错误)的简单 xform,以及一个结果操作。错误规则有一个 results 操作和一个 set var 操作。如果您保留 on-error,响应 content-type 将返回为 "text/xml"。如果你去掉on-error,content-type正确returns"application/json"。 (从以下资源复制 link)
资源Link:
可以使用 saaj-impl jar 解决这个问题。
pom.xml
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3.16</version>
<scope>provided</scope>
</dependency>
调度员-servlet.xml
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="messageFactory">
<bean class="com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl" />
</property>
</bean>
我正在使用 MTOM 将附件从客户端流式传输到服务器。
应用了 MTOM,文件以二进制形式流式传输。但是根 Content-Type 总是 "text/xml" 应该是 "application/xml+xop".
问题仅出现在 websphere 中。内容类型在websphere中设置为"text/xml".
在websphere liberity profile中,内容类型设置为"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
我收集了几个答案。希望第一个答案适合你。为了预防起见,我还用 links 添加了一些其他答案。希望它能拯救你。
回答 1:
服务器端(Weblogic 中的JAX-WS)
使用@MTOM
注释或mtom.xml
政策
客户端(Weblogic 中的JAX-WS)
Pass MTOMFeature() as argument:
MtomService port = service.getMailServicePort(new MTOMFeature());
通过 SOAPUI 连接 MTOM,3 个步骤:
Set Enable MTOM = true
在请求属性中- 上传附件(例..A3.pdf),注意contentID
- 在 xml 请求中设置 MTOM contentID
这是一个带有 weblogic 图像的完整示例。希望它能解决您的问题。(link for Sending attachment: MTOM / XOP vs SWA and inline attachment)
另一个资源Link:
答案 2:
拉入 saaj-impl 1.3.23
并为 javax.xml.soap.*
推荐应用程序 classes 解决了这个问题。
资源Link:https://jira.spring.io/browse/SWS-855
答案 3:
来自mkyong的tutorial,可以解决在客户端和服务器上启用mtom。
在服务器上启用 MTOM:
启用服务器通过 MTOM 发送附件非常简单,只需将 Web 服务实现 class 注释为 javax.xml.ws.soap.MTOM
。
在客户端启用 MTOM:
启用客户端通过 MTOM 将附件发送到服务器需要一些额外的努力,请参见以下示例:
//codes enable MTOM in client
BindingProvider bp = (BindingProvider) imageServer;
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);
答案 4
归功于@BalusC。他通过出色的教程给出了很棒的答案。
当通过 HTTP 提供页面时,元标记将被忽略。
当使用JSP,时
你应该把 <%@ page pageEncoding="UTF-8" %>
放在最上面。
使用Servlet时,
你应该response.setCharacterEncoding("UTF-8");
.
两者都会在内容类型 header 中隐式设置正确的字符集。您可能会发现这篇文章很有用:Unicode - How to get characters right?. For JSP/Servlet solutions, start at this chapter.
资源Link:
为了研究,你可以通过以下
对于 Java servlet,您应该有行
response.setContentType("text/html");
在 doGet
或 doPost
方法的顶部,其中 response 是对 HttpServletResponse
.
相关Link:
- How to set up your server to send the correct MIME types
- Character Encoding problem with IBM's JSF and Ajax
另一个答案
我已经弄清楚是什么导致了这个问题,但我不明白为什么。当对请求执行 on-error 操作时,该行为就会表现出来。附件是一个简单 MPG 的 zip,其中包含演示此操作的请求、响应和错误规则。该请求有一个 on-error 操作,一个执行 dp:reject(强制错误)的简单 xform,以及一个结果操作。错误规则有一个 results 操作和一个 set var 操作。如果您保留 on-error,响应 content-type 将返回为 "text/xml"。如果你去掉on-error,content-type正确returns"application/json"。 (从以下资源复制 link)
资源Link:
可以使用 saaj-impl jar 解决这个问题。
pom.xml
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3.16</version>
<scope>provided</scope>
</dependency>
调度员-servlet.xml
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="messageFactory">
<bean class="com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl" />
</property>
</bean>