I'm trying to publish a layer using a geoserver rest library (geoserver manager), but nothing works.
First I tried this piece of code:
String srs = "EPSG:29193"; GSFeatureTypeEncoder feature = new GSFeatureTypeEncoder(); feature.setName(nomeCamada); feature.setTitle(nomeCamada); feature.setNativeCRS(srs); feature.setEnabled(true); GSLayerEncoder layerEncoder = new GSLayerEncoder(); layerEncoder.setEnabled(true); layerEncoder.setQueryable(true); layerEncoder.setDefaultStyle(estilo); publisher.publishDBLayer(workspace, store, feature, layerEncoder);
I've previously created three styles (style1, style2, style3 - all of them are in the same workspace of the layers that I'm trying to publish) to test them with the layers. If I try to set
estilo = "style1";, it's ignored and the default style is set. For some layers, it's set to polygon, for others it's set line and so on.
It only works if
estilo has a value of one default style that comes with geoserver, that is: polygon, point, line, green etc.
I think it worths to mention that if I do all the actions manually (choose the layer, choose the default style) it works perfectly.
After some researches, I found this solution: https://stackoverflow.com/questions/15573984/geoserver-manager-adding-a-new-layer
But in my geoserver-manager version, there isn't this
configureLayer(GSLayerEncoder layerEncoder, String layerName) method with this number of parameters. The
configureLayer() method has three parameters (as stated here: http://demo.geo-solutions.it/share/github/gsman/apidocs/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.html): String workspace, String resourceName, GSLayerEncoder layer.
With resourceName, I understand the layer's name, right? I tried to configure before publishing (using the layer's name in the place of resourceName), but it returns false indicating it wasn't set and the problem's still up. (I've also tried to use the store name for resourceName, but there's still the problem)
Has someone already got into this problem? What can I do?
I'm using geoserver-manager-1.7, geoserver 2.4.4, jdk7 and tomcat 6.0.30.
I found something:
I must publish the layer before configuring layer, that is, I must
publisher.publishDBLayer(workspace, store, feature, layerEncoder);first.
After that, I must configure the layer:
publisher.configureLayer(workspace, nomeCamada, layerEncoder);
The second parameter of
configureLayer()method, i.e., resourceName is the layer's name.
But, even after successful publishing and configuring, the selected style isn't being selected. Instead the default is chosen. I'm still stuck.
I removed the workspace from the styles. Now I can set them to the layer, but that was a workaround. I'm still looking for the solution. If I found it, I'll post here.