Java SOAPExceptionImpl:无效的内容类型:text/html。这是一条错误消息而不是SOAP响应吗?
我需要有关调用web服务的帮助。 我使用Java SOAPExceptionImpl:无效的内容类型:text/html。这是一条错误消息而不是SOAP响应吗?,java,soap,spring-ws,Java,Soap,Spring Ws,我需要有关调用web服务的帮助。 我使用org.springframework.ws.client调用ws,代码如下: Response response = (Response) getWebServiceTemplate().marshalSendAndReceive( "http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import",
org.springframework.ws.client
调用ws,代码如下:
Response response = (Response) getWebServiceTemplate().marshalSendAndReceive(
"http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import",
request,
new SoapActionCallback("http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import"));
我还可以使用此链接调用WS并接收响应http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import
(看起来很奇怪)使用SOAP UP。它很好用
从IDE运行代码后,我收到下一个堆栈跟踪:
Exception in thread "main" java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:677)
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:969)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
at com.mayacomp.feeder.Application.main(Application.java:33)
Caused by: org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:216)
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:60)
at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
at com.mayacomp.feeder.Client.createApplication(ExternalChannelClient.java:133)
at com.mayacomp.feeder.Application.lambda$0(Application.java:45)
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:674)
... 5 more
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(Unknown Source)
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.<init>(Unknown Source)
at com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl.<init>(Unknown Source)
at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl.createMessage(Unknown Source)
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:188)
... 13 more
at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611)
但应具备:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://mayacom/Generic/Ws">
<soapenv:Header/>
<soapenv:Body>
<ws:request>
您的服务返回错误的
内容类型HTTP头
请参阅堆栈跟踪:
Exception in thread "main" java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:677)
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:969)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
at com.mayacomp.feeder.Application.main(Application.java:33)
Caused by: org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:216)
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:60)
at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
at com.mayacomp.feeder.Client.createApplication(ExternalChannelClient.java:133)
at com.mayacomp.feeder.Application.lambda$0(Application.java:45)
at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:674)
... 5 more
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(Unknown Source)
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.<init>(Unknown Source)
at com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl.<init>(Unknown Source)
at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl.createMessage(Unknown Source)
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:188)
... 13 more
at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611)
这意味着响应解析,而com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identificationContentType
只想处理type=text/xml
或type=application/soap+xml此问题的可能解决方案
1) 检查JAR是否存在于给定的位置或类路径
2) 您的端点URL必须有效
在我的例子中,url中还有一个额外的正斜杠(/)
示例
不正确-(导致上述问题)
正确-(使用Postman检查是否有效)我是否可以让客户端在响应中使用内容类型:text/html?我还检查了wireshare中的响应。在验证步骤之前,确实有内容类型:text/html
和有关异常的信息,如一般异常:java.lang.exception:Error:响应中没有根元素代码>。我无法忍受,但当我从soap UI发送soap请求时,它工作正常。