Guillaume
Guillaume

Reputation: 18865

Spring-WS : specifying the Content-Type

I have a Spring Webservice based on AbstractJDomPayloadEndpoint. This service works fine, except that my client needs the HTTP header Content-Type to be set to the right charset (utf-8 in my case). I cant find where I can configure that.

I tried writing a simple servlet Filter :

chain.doFilter(request, response);
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Content-Type", "text/xml; charset=utf-8");

But this doesnt change the headers at all. I suspect that the content type header is set by Spring-WS, and the response is commited, so nothing I set in a filter will have an impact.

My appserver is WebLogic 9.2.3.

Upvotes: 1

Views: 6495

Answers (1)

skaffman
skaffman

Reputation: 403441

Yes, your filter code will fail because by the time doFilter() completes, the response will have been fully committed, and you won't be allowed to change the content type header.

I suggest writing a subclass of HttpServletResponseWrapper, overriding the setContentType() and/or setCharacterEncoding() methods to set the value to the one you want. You then pass the instance of the wrapper (which wraps the original response) to the doFilter().

Upvotes: 1

Related Questions