Web服务方法中的空参数

时间:2012-11-08 04:52:50

标签: java web-services jersey jax-rs

我使用泽西为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)
       ....
|#]

2 个答案:

答案 0 :(得分:1)

你得到的错误

  

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

是我对空输入的期望。由于没有JSON可供使用,您期望JAX-RS做什么?

编辑:在JAX-RS 2.0中,validation will be included

答案 1 :(得分:1)

我怀疑唯一可行的解​​决方法是使用您自己的JAX-RS数据提供程序,它将正确处理传入的NULL。另见:JAX-RS / Jersey how to customize error handling?