【问题标题】:SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?SOAPExceptionImpl:无效的内容类型:文本/html。这是错误消息而不是 SOAP 响应吗?
【发布时间】:2015-11-17 15:38:33
【问题描述】:

我需要有关调用 Web 服务的帮助。 我用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"));

我还可以使用 SOAP UP 使用此链接http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import(看起来很奇怪)调用 WS 并接收响应。它工作正常。

从 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

所以根本问题是: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?

您能否推荐一些解决方法来解决此问题? 如果需要,我已准备好获取任何其他信息。

更新 据我了解,问题在于接下来的事情:

在客户端发送的请求中我有:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <ns3:request xmlns:ns3="http://mayacom/Generic/Ws">

但应该有:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://mayacom/Generic/Ws">
    <soapenv:Header/>
    <soapenv:Body>
        <ws:request>

如何设置?

@Bean
public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("com.mayacomp.feeder.Client");
    return marshaller;
}


@Bean
public ExternalChannelClient externalChannelClient(Jaxb2Marshaller marshaller) {
    ExternalChannelClient client = new ExternalChannelClient();
    client.setDefaultUri("http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import");
    client.setMarshaller(marshaller);
    client.setUnmarshaller(marshaller);
    return client;
}   

【问题讨论】:

    标签: java soap spring-ws


    【解决方案1】:

    您的服务返回错误的Content-Type HTTP 标头。

    查看堆栈跟踪:

    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.identifyContentType 只想处理type=text/xml 或type=application/soap+xml。

    【讨论】:

    • 我能否以某种方式让客户端使用内容类型:text/html 作为响应?
    • 我还检查了wireshare中的响应。确实有content-type: text/html 和有关异常的信息,例如&lt;faultstring xsi:type="xsd:string"&gt;General exception before validation step: java.lang.Exception: Error: No Root element in response!&lt;/faultstring&gt;。
    • 我无法理解,但是当我从 Soap UI 发送肥皂请求时,它工作正常。
    • @Artem Bilan 解决方案是什么,因为我在这里有同样的问题stackoverflow.com/questions/68830582/…
    【解决方案2】:

    这个问题的可能解决方案

    1) 检查您的 jars 是否存在于给定位置或类路径中

    2) 您的端点 URL 必须有效。

    在我的例子中,url 中有一个额外的正斜杠(/)

    示例 不正确 - http://localhost:8088//mockService(导致上述问题)

    正确 - http://localhost:8088/mockService(检查它是否正在使用 Postman)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-12
      • 2022-06-13
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 2017-07-14
      • 1970-01-01
      • 2017-11-08
      相关资源
      最近更新 更多