1

我将泽西岛用于 WS。我有以下方法:

@Path("...")
@POST
public Response updateConfigs(@Context HttpServletRequest request, ....
        ConfigurationItemList itemList) {
    ...
}

其中 itemList 是 POST 参数。当我尝试使用空 POST 参数调用此方法时,出现异常:

[#|2012-10-12T14:08:52.623+0200|SEVERE|glassfish3.1.1|com.sun.jersey.spi.container.ContainerResponse|_ThreadID=25;_ThreadName=Thread-2;|The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.io.EOFException: No content to map to Object due to end of input
       at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2173)
       at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2106)
       at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1004)
       ...
|#]

[#|2012-10-12T14:08:52.624+0200|WARNING|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=25;_ThreadName=Thread-2;|StandardWrapperValve[...ApplicationConfig]: PWC1406: Servlet.service() for servlet ....ApplicationConfig threw exception
java.io.EOFException: No content to map to Object due to end of input
       at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2173)
       at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2106)
       at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1004)
       at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
       ....
|#]
4

2 回答 2

1

你得到的错误

java.io.EOFException:由于输入结束,没有要映射到 Object 的内容

是我对空输入的期望。既然没有 JSON 可供消费,那么您希望 JAX-RS 做什么?

编辑:在 JAX-RS 2.0 中,将包含验证

于 2012-11-08T08:35:59.303 回答
1

我怀疑唯一可能的解决方法是使用您自己的 JAX-RS 数据提供程序,它将正确处理传入NULL的 s。另请参阅:JAX-RS/Jersey 如何自定义错误处理?

于 2012-11-08T13:52:53.817 回答