我目前正在编写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;
}
结果:发布时间:
关于MediaType.APPLICATION_XML的RESTFUL是否有任何限制?
谢谢
答案 0 :(得分:0)
您好尝试使用jax-rs规范中的Response对象
https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Response.html
最好返回响应对象,以便您可以灵活地定义状态,正文等。
您还可以看到有关此主题的现有答案:
Returning an Integer from RESTful web services method in java