【问题标题】:How to set content type as text/xml in response message header using spring如何使用spring在响应消息头中将内容类型设置为text/xml
【发布时间】:2015-04-22 06:32:05
【问题描述】:

我开发了一个spring webservice,它会返回一个空响应,但问题是内容类型是text/palin。我想将内容类型设置为 text/xml,已搜索选项但无法获得确切的方法。

这是我的代码:

@Endpoint
public class Service{

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

}

谁能尽快解释一下,因为这阻碍了我目前的工作。

【问题讨论】:

  • 可以使用@Consumes(MediaType.APPLICATION_XML)注解。

标签: java web-services soap spring-ws


【解决方案1】:

如果你使用的是 Spring 3.1,你可以这样做

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

}

添加生产属性并设置内容类型

还有一种方法

您可以将response.setContentType("text/xml"); 放入您的方法中

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

【讨论】:

  • 我尝试了第一个选项,但没有运气。但是使用第二个选项我没有发送任何响应,那么我如何设置内容类型作为响应。
  • 你在你的问题中说“但问题是内容类型是 text/palin。我想将内容类型设置为 text/xml”。我告诉你如何设置内容类型
  • 我们发现WAS服务器实际上正在将响应xml中的内容类型替换为text/palin,因为在服务器配置文件中MIME类型设置为text/plain。
猜你喜欢
  • 1970-01-01
  • 2017-06-16
  • 2018-05-22
  • 1970-01-01
  • 2011-07-26
  • 2018-10-05
  • 1970-01-01
  • 1970-01-01
  • 2011-07-12
相关资源
最近更新 更多