'Error reading XMLStreamReader: Unexpected character 'N' (code 78) in prolog; expected '<'

I am getting WstxUnexpectedCharException when hitting a soap service. My code is generating the request, that request is looking fine, and when same request i am using in SOAP UI, it is giving proper response.

org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader: Unexpected character 'N' (code 78) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:293) ~[cxf-rt-bindings-soap-3.1.11.jar:3.1.11]
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:70) ~[cxf-rt-bindings-soap-3.1.11.jar:3.1.11]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:801) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1680) [cxf-rt-transports-http-3.1.11.jar:3.1.11]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1559) [cxf-rt-transports-http-3.1.11.jar:3.1.11]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1356) [cxf-rt-transports-http-3.1.11.jar:3.1.11]
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:653) [cxf-rt-transports-http-3.1.11.jar:3.1.11]
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277) [cxf-core-3.1.11.jar:3.1.11]
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) [cxf-rt-frontend-simple-3.1.11.jar:3.1.11]
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139) [cxf-rt-frontend-jaxws-3.1.11.jar:3.1.11]


Solution 1:[1]

In my case, the error was due because I changed the SOAP endpoint to a server like putsreq.com which echoes the incoming requests.

Since its response to my xml was Hello Word instead of a valid XML, Apache CXF complained with the error :

Error reading XMLStreamReader: Unexpected character 'H' (code 72) in prolog; expected '<'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pierre C