无法创建消息:SOAP 版本的内容类型不正确。Got text/xml;charset=UTF-8,但预期的 application/soap+xml

2022-09-04 07:51:23

我正在尝试使用eBay提供的大型商家服务API将文件上传到eBay。

他们提供了相同的样本.jar文件。当我们在命令提示符下执行.jar文件时,它似乎工作正常,但是当我尝试将其源集成到我的Web应用程序中时,它会给我这个错误。另外,我尝试使用Netbeans创建一个Web服务客户端并尝试使用它,但它仍然给了我同样的错误。我还将 SOAP 版本从 1.1 更改为 1.2,但这似乎也不起作用。以下是完整的堆栈跟踪。

Nov 11, 2011 2:59:41 PM com.sun.xml.internal.messaging.saaj.soap.MessageImpl init
SEVERE: SAAJ0533: Cannot create message: incorrect content-type for SOAP version. Got text/xml; charset=UTF-8, but expected application/soap+xml
Nov 11, 2011 2:59:41 PM com.sun.xml.internal.messaging.saaj.soap.MessageImpl init
SEVERE: SAAJ0535: Unable to internalize message
Exception in thread "main" javax.xml.ws.WebServiceException: Couldn't create SOAP message due to exception: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to internalize message
        at com.sun.xml.internal.ws.util.SOAPConnectionUtil.getSOAPMessage(SOAPConnectionUtil.java:83)
        at com.sun.xml.internal.ws.encoding.soap.client.SOAPXMLDecoder.toSOAPMessage(SOAPXMLDecoder.java:102)
        at com.sun.xml.internal.ws.protocol.soap.client.SOAPMessageDispatcher.receive(SOAPMessageDispatcher.java:440)
        at com.sun.xml.internal.ws.protocol.soap.client.SOAPMessageDispatcher.doSend(SOAPMessageDispatcher.java:260)
        at com.sun.xml.internal.ws.protocol.soap.client.SOAPMessageDispatcher.send(SOAPMessageDispatcher.java:139)
        at com.sun.xml.internal.ws.encoding.soap.internal.DelegateBase.send(DelegateBase.java:86)
        at com.sun.xml.internal.ws.client.EndpointIFInvocationHandler.implementSEIMethod(EndpointIFInvocationHandler.java:174)
        at com.sun.xml.internal.ws.client.EndpointIFInvocationHandler.invoke(EndpointIFInvocationHandler.java:108)
        at $Proxy28.createUploadJob(Unknown Source)
        at com.SwiftConnectV1.fileprocess.LMS.BulkDataExchangeActions.createUploadJob(BulkDataExchangeActions.java:138)
        at com.SwiftConnectV1.fileprocess.LMS.LMSClientJobs.createUploadJob(LMSClientJobs.java:154)
        at com.SwiftConnectV1.fileprocess.LMS.LMSSample.main(LMSSample.java:74)
Caused by: Couldn't create SOAP message due to exception: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to internalize message
        at com.sun.xml.internal.ws.util.SOAPUtil.createMessage(SOAPUtil.java:154)
        at com.sun.xml.internal.ws.util.SOAPConnectionUtil.getSOAPMessage(SOAPConnectionUtil.java:78)
        ... 11 more
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to internalize message
        at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.init(MessageImpl.java:475)
        at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.<init>(MessageImpl.java:278)
        at com.sun.xml.internal.messaging.saaj.soap.ver1_2.Message1_2Impl.<init>(Message1_2Impl.java:61)
        at com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl.createMessage(SOAPMessageFactory1_2Impl.java:62)
        at com.sun.xml.internal.ws.util.SOAPUtil.createMessage(SOAPUtil.java:152)
        ... 12 more
Caused by: com.sun.xml.internal.messaging.saaj.soap.SOAPVersionMismatchException: Cannot create message: incorrect content-type for SOAP version. Got: text/xml; charset=UTF-8 Expected: application/soap+xml
        at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.init(MessageImpl.java:356)
        ... 16 more

答案 1

SAAJ0533: 无法创建消息: SOAP 版本的内容类型不正确。Got text/xml;charset=UTF-8,但预期的 application/soap+xml

根据异常消息,我说你有一些东西混淆了。

对于发送的所有 SOAP 消息,标头应为:Content-type

  • text/xml对于 SOAP v1.1
  • application/soap+xml对于 SOAP v1.2。

首先检查这些,然后我的建议是尝试查看网络上发生了什么(例如Fiddler),然后比较Web应用程序中的不同之处,而不是哪些工作正常。sample.jar


答案 2

SAAJ0533: 无法创建消息: SOAP 版本的内容类型不正确。Got text/xml;charset=UTF-8,但预期的 application/soap+xml

实际上,我们得到这个错误是因为SaajSoapMessageFactory是“手动”创建的,而不是作为@Bean,所以它没有被Spring生命周期负责,也没有调用afterPropertiesSet方法。

因此,请遵循以下示例和建议:

希望这个帮助,


推荐