Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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.

After run code from IDE I receive next stack trace:

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

So the root problem is: 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.

UPDATE As I understood the problem is in the next things:

In the request sent by client I have:

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

but should have:

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

How do I set it up?

@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;
}   
like image 439
May12 Avatar asked Nov 17 '15 15:11

May12


2 Answers

Your service returns wrong Content-Type HTTP header.

See you stack trace:

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

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

like image 115
Artem Bilan Avatar answered Sep 28 '22 16:09

Artem Bilan


Probable solutions to this problem

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

2) Your endpoint URL must be valid.

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

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

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

like image 34
Ramchandra Chougale Avatar answered Sep 28 '22 17:09

Ramchandra Chougale