Getting Error in SOAP POST request using Apache CXF but curl works Getting Error in SOAP POST request using Apache CXF but curl works curl curl

Getting Error in SOAP POST request using Apache CXF but curl works


SOAP works on xml and I can see the you have the following error

Caused by: org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType. Incoming portion of HTML stream:

Which is saying that your response is coming in HTML,Response-Code: 500Encoding: ISO-8859-1Content-Type: text/html;chars

So there might be a problem with your WebService try using SOAP UI

also this link will be quite helpful talks about the same issue.https://forums.mulesoft.com/questions/27468/web-service-consumer-response-was-of-unexpected-te.html


If you can't access the log on the server you can try to check if your code request and the curl request are different.

To do that you can sniff the http request with a sniffer like tcpmon.

Tcpmon operates as a proxy between your client and the server. It intercepts all requests and print the details of each request and response.


The turnaround was to use core java HttpURLConnection to achieve this.

A method something like this helped the cause ad post a webservice call without any framework.:

public HttpURLConnection getHttpConn(String webservice_url) throws IOException {URL endpoint = new URL(webservice_url);URLConnection connection = endpoint.openConnection();HttpURLConnection httpConn = (HttpURLConnection) connection;byte[] encodedBytes = Base64.encodeBase64((getUsername()+":"+getPassword()).getBytes());httpConn.setRequestMethod(getRequestMethod());httpConn.setRequestProperty(HTTP_ACCEPT_ENCODING, getAccept_Encoding());httpConn.setRequestProperty(HTTP_CONTENT_TYPE, getContentType());httpConn.setRequestProperty(getContent_Length(), getContent_Length());httpConn.setRequestProperty(HTTP_HOST, getHost());httpConn.setRequestProperty(getConnection(), getConnection());httpConn.setRequestProperty(HTTP_COOKIE2, getCookie2());httpConn.setRequestProperty(HTTP_COOKIE, getCookie());httpConn.setRequestProperty("Authorization", "Basic "+new String(encodedBytes));httpConn.setDoOutput(true);httpConn.setDoInput(true);return httpConn;}

Ensure to configure the http client in the CXF config file (cxf.xml).

As documented in Apache CXF document:

1.Add the http-conduit namespace and xsd:

<beans ...       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration       ...       xsi:schemaLocation="...           http://cxf.apache.org/transports/http/configuration           http://cxf.apache.org/schemas/configuration/http-conf.xsd       ...">

2.Add the http-conduit tag/element and set the RecieveTimeout/ConnectionTimeout to 180000ms:

<http-conf:conduit name="*.http-conduit">      <http-conf:client                       ConnectionTimeout="300000"                      ReceiveTimeout="300000"/>       </http-conf:conduit>