4

So I just used 2 working days trying to figure this out. We are automatic rendering process for maps. All the data is given in SQL base and my job is to write "wrapper" so we can implement this in our in-house framework. I managed all but one needed requests. That request is POST featuretype since this is a way of creating a layer that can later be rendered.

I have all requests saved in postman for pre-testing on example data given by geoserver itself. I can't even get response with status code 201 and always get 500 internal server error. This status is described as possible syntax error in sytax. But I actually just copied and pasted exampled and used geoserver provided data.

This is the requst: http://127.0.0.1:8080/geoserver/rest/workspaces/tiger/datastores/nyc/featuretypes

and its body:

{
  "name": "poi",
  "nativeName": "poi",
  "namespace": {
    "name": "tiger",
    "href": "http://localhost:8080/geoserver/rest/namespaces/tiger.json"
  },
  "title": "Manhattan (NY) points of interest",
  "abstract": "Points of interest in New York, New York (on Manhattan). One of the attributes contains the name of a file with a picture of the point of interest.",
  "keywords": {
    "string": [
      "poi",
      "Manhattan",
      "DS_poi",
      "points_of_interest",
      "sampleKeyword\\@language=ab\\;",
      "area of effect\\@language=bg\\;\\@vocabulary=technical\\;",
      "Привет\\@language=ru\\;\\@vocabulary=friendly\\;"
    ]
  },
  "metadataLinks": {
    "metadataLink": [
      {
        "type": "text/plain",
        "metadataType": "FGDC",
        "content": "www.google.com"
      }
    ]
  },
  "dataLinks": {
    "org.geoserver.catalog.impl.DataLinkInfoImpl": [
      {
        "type": "text/plain",
        "content": "http://www.google.com"
      }
    ]
  },
  "nativeCRS": "GEOGCS[\"WGS 84\", \n  DATUM[\"World Geodetic System 1984\", \n    SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], \n    AUTHORITY[\"EPSG\",\"6326\"]], \n  PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], \n  UNIT[\"degree\", 0.017453292519943295], \n  AXIS[\"Geodetic longitude\", EAST], \n  AXIS[\"Geodetic latitude\", NORTH], \n  AUTHORITY[\"EPSG\",\"4326\"]]",
  "srs": "EPSG:4326",
  "nativeBoundingBox": {
    "minx": -74.0118315772888,
    "maxx": -74.00153046439813,
    "miny": 40.70754683896324,
    "maxy": 40.719885123828675,
    "crs": "EPSG:4326"
  },
  "latLonBoundingBox": {
    "minx": -74.0118315772888,
    "maxx": -74.00857344353275,
    "miny": 40.70754683896324,
    "maxy": 40.711945649065406,
    "crs": "EPSG:4326"
  },
  "projectionPolicy": "REPROJECT_TO_DECLARED",
  "enabled": true,
  "metadata": {
    "entry": [
      {
        "@key": "kml.regionateStrategy",
        "$": "external-sorting"
      },
      {
        "@key": "kml.regionateFeatureLimit",
        "$": "15"
      },
      {
        "@key": "cacheAgeMax",
        "$": "3000"
      },
      {
        "@key": "cachingEnabled",
        "$": "true"
      },
      {
        "@key": "kml.regionateAttribute",
        "$": "NAME"
      },
      {
        "@key": "indexingEnabled",
        "$": "false"
      },
      {
        "@key": "dirName",
        "$": "DS_poi_poi"
      }
    ]
  },
  "store": {
    "@class": "dataStore",
    "name": "tiger:nyc",
    "href": "http://localhost:8080/geoserver/rest/workspaces/tiger/datastores/nyc.json"
  },
  "cqlFilter": "INCLUDE",
  "maxFeatures": 100,
  "numDecimals": 6,
  "responseSRS": {
    "string": [
      4326
    ]
  },
  "overridingServiceSRS": true,
  "skipNumberMatched": true,
  "circularArcPresent": true,
  "linearizationTolerance": 10,
  "attributes": {
    "attribute": [
      {
        "name": "the_geom",
        "minOccurs": 0,
        "maxOccurs": 1,
        "nillable": true,
        "binding": "com.vividsolutions.jts.geom.Point"
      },
      {},
      {},
      {}
    ]
  }
}

So it is example case and I can't get any useful response from the server. I get the code 500 with body name (the first item in json). Similarly I get same code with body FeatureTypeInfo when trying with xml body(first tag).

I already tried the request in new instance of geoserver in Docker (changed the port) and still no success.

I check if datastore, workspace is available and that layer "poi" doesn't yet exists.

Here are also some logs of request (similar for xml body):

2018-08-03 07:35:02,198 ERROR [geoserver.rest] - com.thoughtworks.xstream.mapper.CannotResolveClassException: name at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:79) at .....

Does anyone know the solution to this and got it working. I am using GeoServer 2.13.1

JGH
  • 15,928
  • 4
  • 31
  • 48
Blaž Lipuš
  • 61
  • 1
  • 4

3 Answers3

2

So i was still looking for the answer and using this post (https://gis.stackexchange.com/questions/12970/create-a-layer-in-geoserver-using-rest) got to the right content to POST featureType and hence creating a layer in GeoServer.

The documentation is off in REST API docs.

Using above link I found out that when using JSON there is a missing insertion in JSON. For API to work here we need to add:

{featureType:
  name: "...",
  nativeName: "...",
  .
  .
  .}

So that it doesn't start with "name" attribute but it is contained in "featureType".

I didn't try that for XML also but I guess it could be similar.

Hope this helps someone out there struggling like I did.

Blaž Lipuš
  • 61
  • 1
  • 4
1

Blaz is correct here, you need an outer object of FeatureType and then an inner object with your config. So;

{
"featureType": {
    "name": "layer",
    "nativeName": "poi",
    "your config": "stuff"
}

I find though that using a post request I get very little if any response and its not obvious if the layer creation worked. But you can call http://IP:8080/geoserver/rest/layers.json to check if your new layer is there.

Mark Allen
  • 39
  • 3
1

It costs me a lot of time to create FeatureTypes using REST API. Use Json like this really works:

{
"featureType": {
    "name": "layer",
    "nativeName": "poi"
    "otherProperties...":"values..."
}

And use Json below to create Workspace:

{
    "workspace": {
        "name": "test_workspace"
    }
}

The REST API is out of date now. That's disappointing. Is there anyone knows how to get the lastest REST API document?

Dust
  • 11
  • 1