1

I'm trying to add a new layer to GeoServer programmatically, So at first i have added a new workspace and then a new datastores, so far eveything is good, but when i'm trying to add a new layer i get error 500 which is:

Cannot cast org.geoserver.catalog.impl.LayerInfoImpl to org.geoserver.catalog.FeatureTypeInfo

What i'm doing is that i'm using below code:

<layer>
<name>Shahrestan</name>
<type>VECTOR</type>
<defaultStyle>
<name>polygon</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:1024/geoserver/rest/styles/polygon.xml" type="application/xml"/>
</defaultStyle>
<resource class="featureType">
<name>cite:Shahrestan</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:1024/geoserver/rest/workspaces/cite/datastores/kamal/featuretypes/Shahrestan.xml" type="application/xml"/>
</resource>
<attribution>
<logoWidth>0</logoWidth>
<logoHeight>0</logoHeight>
</attribution>
</layer>

And send it to the url below:

http://localhost:1024/geoserver/rest/workspaces/cite/datastores/kamal/featuretypes

Please note that i have already created a new layer using geoserver ui, and then i went through the geoserver rest index to get the xml codes

http://localhost:1024/geoserver/rest

But still i'm getting error. What's wrong?

0

Your problem is that you are sending a LayerInfo representation to an endpoint that expects a FeatureTypeInfo representation. If you make a request to the endpoint it will show you what is expected, for example do a GET on

http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_roads.xml

You get this back (note how the enclosing tag is FeatureType):

<featureType>
<name>tasmania_roads</name>
<nativeName>tasmania_roads</nativeName>
<namespace>
<name>topp</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/namespaces/topp.xml" type="application/xml"/>
</namespace>
<title>Tasmania roads</title>
<abstract>Main Tasmania roads</abstract>
<keywords>
<string>Roads</string>
<string>Tasmania</string>
</keywords>
<nativeCRS>
GEOGCS["GCS_WGS_1984", DATUM["WGS_1984", SPHEROID["WGS_1984", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Longitude", EAST], AXIS["Latitude", NORTH]]
</nativeCRS>
<srs>EPSG:4326</srs>
<nativeBoundingBox>
<minx>145.19754</minx>
<maxx>148.27298000000002</maxx>
<miny>-43.423512</miny>
<maxy>-40.852802</maxy>
<crs>EPSG:4326</crs>
</nativeBoundingBox>
<latLonBoundingBox>
<minx>145.19754</minx>
<maxx>148.27298000000002</maxx>
<miny>-43.423512</miny>
<maxy>-40.852802</maxy>
<crs>EPSG:4326</crs>
</latLonBoundingBox>
<projectionPolicy>FORCE_DECLARED</projectionPolicy>
<enabled>true</enabled>
<metadata>
<entry key="kml.regionateFeatureLimit">10</entry>
<entry key="cacheAgeMax">3600</entry>
<entry key="cachingEnabled">true</entry>
<entry key="indexingEnabled">false</entry>
<entry key="dirName">tasmania_roads</entry>
</metadata>
<store class="dataStore">
<name>topp:taz_shapes</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes.xml" type="application/xml"/>
</store>
<maxFeatures>0</maxFeatures>
<numDecimals>0</numDecimals>
<overridingServiceSRS>false</overridingServiceSRS>
<skipNumberMatched>false</skipNumberMatched>
<circularArcPresent>false</circularArcPresent>
<attributes>
<attribute>
<name>the_geom</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>org.locationtech.jts.geom.MultiLineString</binding>
</attribute>
<attribute>
<name>TYPE</name>
<minOccurs>0</minOccurs>
<maxOccurs>1</maxOccurs>
<nillable>true</nillable>
<binding>java.lang.String</binding>
<length>7</length>
</attribute>
</attributes>
</featureType>

You almost certainly need to be hitting http://localhost:8080/geoserver/rest/layers/topp:tasmania_roads.xml (for example) which returns (starting with a Layer tag):

<layer>
<name>tasmania_roads</name>
<path>/</path>
<type>VECTOR</type>
<defaultStyle>
<name>simple_roads</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/styles/simple_roads.xml" type="application/xml"/>
</defaultStyle>
<resource class="featureType">
<name>topp:tasmania_roads</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_roads.xml" type="application/xml"/>
</resource>
<attribution>
<logoWidth>0</logoWidth>
<logoHeight>0</logoHeight>
</attribution>
</layer>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.