Wednesday, August 10, 2011

Return code 400 when creating a new feature type

I came across a 400 return code when I tried to use REST Configuration API of GeoServer to create a new feature type. The reference doesn't give any explanation to it. From GeoServer's log, I got

ERROR [geoserver.rest] - No such feature type:
ERROR [geoserver.rest] -org.geoserver.rest.RestletException
        at org.geoserver.catalog.rest.FeatureTypeFinder.findTarget(FeatureTypeFinder.java:40)
        at org.restlet.Finder.handle(Finder.java:268)
        at org.geoserver.rest.BeanDelegatingRestlet.handle(BeanDelegatingRestlet.java:37)
        at org.restlet.Filter.doHandle(Filter.java:105)
        at org.restlet.Filter.handle(Filter.java:134)
        at org.restlet.Router.handle(Router.java:444)
        at com.noelios.restlet.ext.servlet.ServletConverter.service(ServletConverter.java:129)
        at org.geoserver.rest.RESTDispatcher.handleRequestInternal(RESTDispatcher.java:77)

INFO [org.geoserver] - Loaded feature type '', enabled

ERROR [geoserver.rest] - Trying to create new feature type inside the store, but no attributes were specified
ERROR [geoserver.rest] -org.geoserver.rest.RestletException
        at org.geoserver.catalog.rest.FeatureTypeResource.buildFeatureType(FeatureTypeResource.java:174)
        at org.geoserver.catalog.rest.FeatureTypeResource.handleObjectPost(FeatureTypeResource.java:124)
        at org.geoserver.rest.ReflectiveResource.handlePost(ReflectiveResource.java:122)
        at org.restlet.Finder.handle(Finder.java:296)
        at org.geoserver.rest.BeanDelegatingRestlet.handle(BeanDelegatingRestlet.java:37)
        at org.restlet.Filter.doHandle(Filter.java:105)
        at org.restlet.Filter.handle(Filter.java:134)
        at org.restlet.Router.handle(Router.java:444)
        at com.noelios.restlet.ext.servlet.ServletConverter.service(ServletConverter.java:129)
        at org.geoserver.rest.RESTDispatcher.handleRequestInternal(RESTDispatcher.java:77)

It shows that I'm trying to publish a feature type that doesn't exist. Problem solved here but I'd like to go the extra mile, check the source of FeatureTypeResource#buildFeatureType.

170  if(fti.getName() == null) {
171     throw new RestletException("Trying to create new feature type inside the store, " +
172              "but no feature type name was specified", Status.CLIENT_ERROR_BAD_REQUEST);
173  } else if(fti.getAttributes() == null || fti.getAttributes() == null) {
174      throw new RestletException("Trying to create new feature type inside the store, " +
175              "but no attributes were specified", Status.CLIENT_ERROR_BAD_REQUEST);
176  }

WTF is line 173 doing?