[英]RESTFUL web service - media type=application/xml
我目前正在编写RESTFUL Web服务,并尝试将整数返回到Web服务。
我在浏览器中遇到500 Internal Server Error,当我检查Tomcat Log时,发生了上述错误。
12-Nov-2018 09:47:12.547 SEVERE [http-nio-8080-exec-52] org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo MessageBodyWriter not found for media type=application/xml, type=class java.lang.Integer, genericType=int.
我的代码:
@POST
@Path("/post")
@Produces(MediaType.APPLICATION_XML)
public static int adaptiveAuth(){
int message=1;
return message;
}
如果我将函数替换为String,它将不会出现任何错误。
@POST
@Path("/post")
@Produces(MediaType.APPLICATION_XML)
public static String adaptiveAuth(){
String message="POST STRING";
return message;
}
结果:STRING后
关于MediaType.APPLICATION_XML的RESTFUL是否有任何限制?
谢谢
您好尝试使用jax-rs规范中的Response对象
https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Response.html
最好返回响应对象,它使您可以灵活地定义状态,正文等。
您还可以查看有关此主题的现有答案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.