2012-11-08 2 views
1

J'utilise Jersey pour WS. J'ai la méthode suivante:Paramètre Null dans la méthode de service web

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

Où est itemList POST param. Quand je tente d'appeler cette méthode avec params POST vides, je reçois une exception:

[#|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) 
     .... 
|#] 
+0

Quelle annotation '@ Consumes' utilisez-vous? Comment 'ConfigurationItemList' est-il mappé de/vers JSON/XML/...? –

+0

'@Consumes (MediaType.APPLICATION_JSON)' La conversion est faite par Jersey. –

Répondre

1

Je suppose que la seule solution possible consiste à utiliser votre propre fournisseur de données JAX-RS, qui traitera correctement les NULL s entrants. Voir aussi: JAX-RS/Jersey how to customize error handling?

+0

Merci! Oui, MessageBodyReader c'est la solution à mon problème. –

1

L'erreur que vous obtenez

java.io.EOFException: Aucun à la carte à l'objet en raison de la fin de entrée

est ce que j'attendrais pour une entrée vide. Comme il n'y a pas de JSON à consommer, qu'attendez-vous de JAX-RS?

Édition: Dans JAX-RS 2.0, validation will be included.

+0

Je veux attraper cette exception. –

Questions connexes