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

时间:2011-11-11 09:34:23

标签: java web-services soap struts ebay

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

他们提供了相同的sample.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

3 个答案:

答案 0 :(得分:26)

  

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

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

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

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

首先检查这些,然后我的建议是尝试查看线路上的内容(前面有Fiddler),然后比较网络应用中的不同之处,而不是sample.jar哪个有效。

答案 1 :(得分:0)

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

实际上,我们收到此错误是因为SaajSoapMessageFactory不是以@Bean的方式“手动”创建的,因此它在Spring生命周期中没有负责,也没有调用afterPropertiesSet方法。

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

希望获得帮助,

答案 2 :(得分:-5)

让它工作,似乎我的JDK已损坏所有外部jar文件,我添加它以使其工作。升级到Java 7,现在似乎工作正常。