Note that there are some explanatory texts on larger screens.

plurals
  1. POJAX-WS Dispatch Request setting Content-Type
    primarykey
    data
    text
    <p>I'm trying to POST a JAX-RS resource using the Service / Dispatch mechanism. The problem is that the Content-Type of the outgoing request is locked to <code>text/xml</code>. I can't see a way changing this to some other kind of type, for example <code>application/xml</code>.</p> <p>The RESTfull webservice consumes only <code>application/xml</code> and <code>application/json</code>. This is the code I use:</p> <pre><code>public static void main(String[] args) { QName qName = new QName("GREETINGS"); Service service = Service.create(qName); service.addPort(qName, HTTPBinding.HTTP_BINDING, "http://localhost:8081/gf-ws-1/resources/greetings"); // change headers of the outgoing request Map&lt;String, Object&gt; headers = new HashMap&lt;String, Object&gt;(); headers.put("Content-Type", Arrays.asList(new String[] {"application/xml"})); headers.put("Accept", Arrays.asList(new String[] {"zoo"})); headers.put("foo", Arrays.asList(new String[] {"bar"})); Dispatch&lt;Source&gt; dispatch = service.createDispatch(qName, Source.class, Service.Mode.PAYLOAD); dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, "POST"); dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers); dispatch.invokeOneWay(new StreamSource(new StringReader("&lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;greeting&gt;&lt;value&gt;Hello World!&lt;/value&gt;&lt;/greeting&gt;"))); // get the response code: [HTTP/1.1 415 Unsupported Media Type] because of content type System.out.println(((Map&lt;String, Object&gt;) dispatch.getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS)).get(null)); } </code></pre> <p>The <code>Accept</code> header is modified to <code>zoo</code>, <code>foo</code> header is added with value <code>bar</code>, but <code>Content-Type</code> remains unchanged. I think I could use a filter and modify the <code>Content-Type</code> based on some conditions, or even based on foo header but this seems counter intuitive.</p> <p>Here are all the headers of the request:</p> <pre><code>POST /gf-ws-1/resources/greetings HTTP/1.1 Accept: zoo Content-Type: text/xml foo: bar User-Agent: Metro/2.2.0-1 (tags/2.2.0u1-7139; 2012-06-02T10:55:19+0000) JAXWS-RI/2.2.6-2 JAXWS/2.2 svn-revision#unknown Host: localhost:8080 Connection: keep-alive Content-Length: 86 </code></pre> <p>Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload