10

I have a webservice which has to return player details in response. The problem is, when I send same request in SoapUI I get valid response, but when I do this through Java, I get back this message in

<faultstring> Unsupported content type: text/plain; charset=ISO-8859-1 </faultstring>.

Any ideas why it is the problem?

This is request I am sending:

> <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:gen=" ">   
> <soapenv:Header/>   
> <soapenv:Body>
>       <gen:GetPlayerDetails>
>          <request>
>             <systemUID>C_GS01</systemUID>
>             <sessionID>TVM0MgAAB9IAAAFEjXyfxbvZ2oU_</sessionID>
>          </request>
>       </gen:GetPlayerDetails>    
> </soapenv:Body>
> </soapenv:Envelope>

SOLVED thanks to @helderdarocha Made some changes (last line) in my HTTP client class:

        HttpClient httpclient = HttpClientBuilder.create().build();
        StringEntity strEntity = new StringEntity(request);
        HttpPost post = new HttpPost("http://10.47.44.163:8080" + endPointURI);
        post.addHeader("Content-type", "text/xml");
mrk2
  • 797
  • 3
  • 9
  • 20

1 Answers1

10

You are probably sending a request without the appropriate headers. You have to declare the type of data your client accepts as a response using the Accept header:

Accept: application/xml; application/json;

Additionally, if you are sending data, you have to declare the Content-type of what you are sending, and it should be compatible with the data your service accepts.

Content-type: application/xml

If you are sending payload in XML, for example.

helderdarocha
  • 23,209
  • 4
  • 50
  • 65
  • well, when I print the request to console to see what am I sending, I get exact same request that was sent in SoapUI – mrk2 Mar 04 '14 at 16:03
  • Add your request headers to your question. – helderdarocha Mar 04 '14 at 16:06
  • I mean the HTTP header. That's the important part. What comes before the XML that is being sent to the server. The HTTPClient must generate HTTP headers which will inform the server what kind of data is in the body. If the body contains XML, it has to send a `Content-type: application/xml` at least (or even be more specific if the server requires that). – helderdarocha Mar 04 '14 at 16:14
  • where can I see the HTTP header? – mrk2 Mar 04 '14 at 16:23
  • Try using an interactive HTTP client like this one https://addons.mozilla.org/en-US/firefox/addon/restclient/ (it was created for REST, but you can paste your SOAP xml and send it as payload as well). You can experiment adding `Content-type` headers and see how they work. – helderdarocha Mar 04 '14 at 16:27
  • To see the HTTP header that is generated by the client that is working, you need some kind of HTTP request interceptor. Your request should send something like `request.addHeader("Content-Type", "application/xml");` – helderdarocha Mar 04 '14 at 16:30
  • Yes. You were sending no "Content-type", so the default was "text/plain". If you send "text/xml" the server can identify the contents and process the SOAP request. – helderdarocha Mar 04 '14 at 16:39
  • In practice, `text/xml` or `application/xml` shouldn't make any difference: http://stackoverflow.com/questions/4832357/whats-the-difference-between-text-xml-vs-application-xml-for-webservice-respons – helderdarocha Mar 04 '14 at 16:41
  • now I am trying to figure out how to set Content type for my Http client – mrk2 Mar 04 '14 at 16:42
  • Content-type is a header. You can always use something like `request.addHeader("Content-type", "text/xml");` – helderdarocha Mar 04 '14 at 16:43