java SOAPExceptionImpl:无效的内容类型:文本/html。这是错误消息而不是 SOAP 响应吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33760970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:06:11  来源:igfitidea点击:

SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?

javasoapspring-ws

提问by May12

I need help with calling a web service. I use org.springframework.ws.clientto call WS, code looks like:

我需要有关调用 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"));

Also I can call WS and receive response using this link http://ip:port/DefaultRequestListener?workflow=WsdlCPF&soapAction=Import(it looks strange) using SOAP UP. It works fine.

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

After run code from IDE I receive next stack trace:

从 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
<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">
(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

So the root problem is: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?

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

Could you recommend some workarounds to solve this problem? I am ready to get any additional info if need.

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

UPDATEAs I understood the problem is in the next things:

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

In the request sent by client I have:

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

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

but should have:

但应该有:

@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;
}   

How do I set it up?

我该如何设置?

at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611)

回答by Artem Bilan

Your service returns wrong Content-TypeHTTP header.

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

See you stack trace:

见堆栈跟踪:

##代码##

That means response parsing, and com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentTypewould like to deal only with type=text/xmlor type=application/soap+xml.

这意味着响应解析,并且com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType只想处理type=text/xmlor type=application/soap+xml

回答by Ramchandra Chougale

Probable solutions to this problem

这个问题的可能解决方案

1) Check if your jars are present at given location or classpath

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

2) Your endpoint URL must be valid.

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

In my case there is an additional forward slash(/) in url

就我而言,网址中有一个额外的正斜杠(/)

Exampleincorrect - http://localhost:8088//mockService(which is causing above issue)

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

correct - http://localhost:8088/mockService(check if it is working using Postman)

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