Spring-WS : specifying the Content-Type

瘦欲@ 提交于 2019-12-04 05:06:57

问题


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.


回答1:


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().



来源:https://stackoverflow.com/questions/3914807/spring-ws-specifying-the-content-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!