Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jax-ws: setting Content-Type of request

I've been trying to consume a .net WCF rest service using JAX-WS lately. Due to security of the service, I've have to set a custom HTTP header Authorization with some signature in it. This I've solved by doing something like this:

BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
                                Collections.singletonMap("Authorization",Collections.singletonList(authHeader)));

However, I get an exception when invoking the service:

com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/html; charset=UTF-8 Supported ones are: [text/xml]
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:284)
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:118)
com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:278)
com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:180)
com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)

And it seems to me that there might be a requirement for my request in the service to be text/xml content-type. How do I set this? I've googled a lot, and read some documentation but I can't seem to figure it out. The exception could of course also be something else than the Content-Type setting (since I've read that by default jax-ws uses text/xml) but I'm not sure.

Thanks in advance!

like image 580
El Che Avatar asked Aug 30 '09 20:08

El Che


1 Answers

You are getting a text/html content type back as a response.

Most of the time when I have got this error, it has been that the server is sending an html error page.

If you have a way to log the response, you should be able to see exactly what the problem is.

like image 82
Shiraz Bhaiji Avatar answered Nov 15 '22 04:11

Shiraz Bhaiji