[Axis2]incorrect content-type for SOAP version
来源:互联网 发布:聚合数据短信接口 编辑:程序博客网 时间:2024/05/14 08:50
在测试的过程中遇到了一个奇怪的异常:
com.sun.xml.internal.messaging.saaj.soap.SOAPVersionMismatchException: Cannot create message: incorrect content-type for SOAP version.Got: application/soap+xml; action="http://smarttrust.com/opm/ws/opm/ActivateRequest"; charset=UTF-8 Expected: text/xml
通过异常信息,可以很明显的发现是携带SOAP消息的HTTP报文请求头的Content-Type字段出了问题
通过抓包可以看到HTTP报文请求头的格式是下面这个样子的(还要注意的一点是,没有SOAPAction字段,而是action字段)
POST /opm HTTP/1.1Content-Type: application/soap+xml; charset=UTF-8; action="http://smarttrust.com/opm/ws/opm/ActivateRequest"User-Agent: Axis2Host: 10.160.68.107:9010Transfer-Encoding: chunked
之后我新建了一个测试工程,仔细的查看了下Axis2自动生成的代码,发现有这么一段:
public MathStub(org.apache.axis2.context.ConfigurationContext configurationContext,java.lang.String targetEndpoint, boolean useSeparateListener)throws org.apache.axis2.AxisFault {populateAxisService();populateFaults();_serviceClient = new org.apache.axis2.client.ServiceClient(configurationContext, _service);_serviceClient.getOptions().setTo(new org.apache.axis2.addressing.EndpointReference(targetEndpoint));_serviceClient.getOptions().setUseSeparateListener(useSeparateListener);_serviceClient.getOptions().setSoapVersionURI(org.apache.axiom.soap.SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);}
这部分是用来设置SOAP版本的
_serviceClient.getOptions().setSoapVersionURI(org.apache.axiom.soap.SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
如果使用SOAP11Constants(SOAP 1.1),HTTP请求头如下:
POST /test HTTP/1.1Content-Type: text/xml; charset=UTF-8SOAPAction: "urn:add"User-Agent: Axis2Host: 146.11.42.87:9876Transfer-Encoding: chunked
如果使用SOAP12Constants(SOAP 1.2) ,HTTP请求头如下:
POST /test HTTP/1.1Content-Type: application/soap+xml; charset=UTF-8; action="urn:add"User-Agent: Axis2Host: 146.11.42.87:9876Transfer-Encoding: chunked
如果不设置这个参数,HTTP请求头如下(和SOAP 1.1是一样的,可以确认默认使用SOAP 1.1):
POST /test HTTP/1.1Content-Type: text/xml; charset=UTF-8SOAPAction: "urn:add"User-Agent: Axis2Host: 146.11.42.87:9876Transfer-Encoding: chunked
HTTP响应头中的Content-Type字段也是一样的
参考:
http://stackoverflow.com/questions/8092031/cannot-create-message-incorrect-content-type-for-soap-version-got-text-xml-ch
0 0
- [Axis2]incorrect content-type for SOAP version
- Config log4j to print SOAP content with AXIS2
- axis2 soap
- axis2 soap
- taglib报The content of element type "taglib" must match "(tlib-version,jsp-version.....错误
- webservice soap axis2
- content-type
- Content Type
- content-type
- Content-Type
- Content-Type
- Content-Type
- Content-Type
- Content-Type
- Content-Type
- content type
- Content-Type
- content-type
- JNI编程经验(JNI Tips)
- 【博弈】【bzoj 2927】: [Poi1999]多边形之战
- xUtils
- 百信社区-餐饮外卖
- 开源项目之Android Afinal框架
- [Axis2]incorrect content-type for SOAP version
- easyui之 datagrid 多条件搜索、查询
- xcode6.1中打包ipa
- android--40条优化建议
- c++11特性与cocos2d-x 3.0之std::bind与std::function
- javascript初步学习1
- SMTP 返回错误协议Transient Error和Permanent Error区别
- Hive自定义UDF-RowNumber
- Hadoop集群中使用Hive查询报错