Search code examples
javaweb-servicessoapspring-ws

How to set content type as text/xml in response message header using spring


I have developed a spring webservice which will return an empty response, but the problem is content-type is going as text/palin. i want to set the content type as text/xml, have searched for options but couldn't get exact way to do it.

here is my code:

@Endpoint
public class Service{

    @PayloadRoot(namespace = "http://sample.com/webservice", localPart = "sendReport")
    @ResponsePayload
    public void recieveReport(@RequestPayload SendReport report){
        // processing the report response
    }

}

Can some one please explin soon, as this is blocking my current work.


Solution

  • If you are using Spring 3.1 you can do this

    @RequestMapping(value = "/getDealers", method = RequestMethod.GET, 
    produces = "text/xml; charset=utf-8")
    @ResponseBody
    public String sendMobileData() {
    
    }
    

    add the produces attribute & set the content type

    There is one more way

    you can put response.setContentType("text/xml"); in your method

    public String yourAction(HttpServletResponse response) {
        response.setContentType("application/json");
    }