Issue 11041

web services need to respond with an invalid request instead of 500 for invalid inputs

11041
Reporter: mdoering
Assignee: fmendez
Type: Bug
Summary: web services need to respond with an invalid request instead of 500 for invalid inputs
Priority: Major
Resolution: Fixed
Status: Closed
Created: 2012-04-26 16:38:44.547
Updated: 2013-12-16 17:51:03.374
Resolved: 2012-07-02 12:04:44.552
        
Description: If you POST an invalid json to the registry web services you get a http 500 when it should be a 401:

$ curl --basic --user admin:none --data-binary '1' --header 'content-type: application/json' http://staging.gbif.org:8080/registry-ws/organization/f9b67ad0-9c9b-11d9-b9db-b8a03c50a862/identifier

Apache Tomcat/6.0.26 - Error report 

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class org.gbif.registry.api.model.Identifier] from JSON integral number; no single-int-arg constructor/factory method
	com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
	com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
	com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
	com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
	com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
	com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
	com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
	com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)

root cause

org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class org.gbif.registry.api.model.Identifier] from JSON integral number; no single-int-arg constructor/factory method
	org.codehaus.jackson.map.deser.std.StdValueInstantiator.createFromInt(StdValueInstantiator.java:286)
	org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromNumber(BeanDeserializer.java:782)
	org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:587)
	org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
	org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
	org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
	com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
	com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)
	com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
]]>
    


Author: fmendez@gbif.org
Comment: 401 should be used for responding:Unauthorized. Probably a better response could be "400 Bad Request".
Created: 2012-06-20 15:14:16.266
Updated: 2012-06-20 15:14:16.266


Author: fmendez@gbif.org
Comment: Jose has fixed this bug!
Created: 2012-07-02 12:04:44.575
Updated: 2012-07-02 12:04:44.575