[Geoserver-users] RE ST Style creation and/or updating

Hi all,

I'm trying to create styles programmatically on GeoServer (1.7.4 - latest
REST plugin installed).

The styles are generated in code, and I have tested that the generated style
can be added in GeoServer manually through the config interface.

My trouble is obviously with the HTTP request that I'm using - this is all
through C# by the way. I have found conflicting information in connection
with the specification of what the REST interface expects with regards to
styles.

For a style creation, I am writing the SDL into my web request, and sending
it to the URL http://localhost:8080/geoserver/rest/styles with a POST
request. Is this correct? Am I supposed to send through the 'name'
parameter in the URL (as in ...rest/styles?name=myNewStyle, or
...?myNewStyle.sld) or should I write the parameter into my request as here:
http://vinothnat.blogspot.com/2007/09/httpwebrequest-post-method.html (I've
tried both, to no avail)...

Any pointers?

Thanks in advance,
Reinhardt
--
View this message in context: http://www.nabble.com/REST-Style-creation-and-or-updating-tp23822754p23822754.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

Hi Reinhardt,

Could you perhaps share the code snippet that you are using to do the upload. One thing to do is make sure the Content-type header:

Content-type: application/vnd.ogc.sld+xml

Also, are you getting any errors on the server side. If you turn up logging to GEOSERVER_DEVELOPER_LOGGING (to go the UI and go to Config - > Server), and then execute the request you might see some errors in the log.

It might also help to have the code snippet you are using to upload the style.

Thanks,

-Justin

SouthAfrican wrote:

Hi all,

I'm trying to create styles programmatically on GeoServer (1.7.4 - latest
REST plugin installed).

The styles are generated in code, and I have tested that the generated style
can be added in GeoServer manually through the config interface.

My trouble is obviously with the HTTP request that I'm using - this is all
through C# by the way. I have found conflicting information in connection
with the specification of what the REST interface expects with regards to
styles.

For a style creation, I am writing the SDL into my web request, and sending
it to the URL http://localhost:8080/geoserver/rest/styles with a POST
request. Is this correct? Am I supposed to send through the 'name'
parameter in the URL (as in ...rest/styles?name=myNewStyle, or
...?myNewStyle.sld) or should I write the parameter into my request as here:
http://vinothnat.blogspot.com/2007/09/httpwebrequest-post-method.html (I've
tried both, to no avail)...

Any pointers?

Thanks in advance,
Reinhardt

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Hi Reinhardt,

It is appreciated if you can keep your questions on the public list. Thanks.

Reinhardt Bron wrote:

Hi Justin,

"Content-type: application/vnd.ogc.sld+xml"

That line did it - I've been struggling the whole day and last night with this issue, and have very little hair left!!! Thank you!!!! What baffles me is that that isn't specified anywhere in the documentation...? OK, now that I've searched the document, I find it - but not where you'd expect to find it...

Apologies, it is indeed not very evident. I just updated the documentation.

But anyway, so I am now successfully updating styles on the GeoServer from my application - <BIG sigh of relief!>. Final hurdle is the creation - which isn't quite working yet. I'm getting a 403 (Forbidden) error, but I suspect this might be because of the way I am requesting the SLD to be created.

Once again, the details of my request are as follows:
URL: http://localhost:8080/geoserver/rest/styles/
Content Type: application/vnd.ogc.sld+xml
Request Type: POST

Hmmm... everything looks ok. A 403 seems wierd to me... does the style already exist? If so you should use a PUT if you want to update it, rather than a POST.

Could you include the SLD? It would be helpful if I could try it out over here.

Style is valid, accepted by GeoServer when input manually, and has a <sld:Name> tag defined under the <sld:NamedStyle> tag. Would GeoServer infer the name from the SLD correctly, or would I have to send the name of the style through as a request parameter?

In the documentation, style creation is documented as follows:
Method = POST
Response = 201 with Location header
Formats = SLD, XML, JSON
Parameter = /name

/and then "The name parameter specifies the name to be given to the style. This option is most useful when POSTing
a style in SLD format, and an appropriate name can be not be inferred from the SLD itself."

Any pointers would, again, be greatly appreciated!

Depends on your SLD, there are multiple places a Name can show up. If you can supply your SLD I can tell you. But yes, the "name" parameter will be respected before anything in the SLD if specified.

-Justin

Thanks,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

Could you perhaps share the code snippet that you are using to do the upload. One thing to do is make sure the Content-type header:

Content-type: application/vnd.ogc.sld+xml

Also, are you getting any errors on the server side. If you turn up logging to GEOSERVER_DEVELOPER_LOGGING (to go the UI and go to Config - > Server), and then execute the request you might see some errors in the log.

It might also help to have the code snippet you are using to upload the style.

Thanks,

-Justin

SouthAfrican wrote:

Hi all,

I'm trying to create styles programmatically on GeoServer (1.7.4 - latest
REST plugin installed).

The styles are generated in code, and I have tested that the generated style
can be added in GeoServer manually through the config interface.

My trouble is obviously with the HTTP request that I'm using - this is all
through C# by the way. I have found conflicting information in connection
with the specification of what the REST interface expects with regards to
styles.

For a style creation, I am writing the SDL into my web request, and sending
it to the URL http://localhost:8080/geoserver/rest/styles with a POST
request. Is this correct? Am I supposed to send through the 'name'
parameter in the URL (as in ...rest/styles?name=myNewStyle, or
...?myNewStyle.sld) or should I write the parameter into my request as here:
http://vinothnat.blogspot.com/2007/09/httpwebrequest-post-method.html (I've
tried both, to no avail)...

Any pointers?

Thanks in advance,
Reinhardt

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Hi Justin,

As I said in my previous e-mail, the updating works perfectly, it’s the creation of a style that I’m having difficulty with!

My SLD looks exactly the same as it does in the inital post - only with a different value in the Name tag, which obviously doesn’t exist on the GeoServer yet.

I could hack out my C# code to post that to you too if that would help.

Thanks again,
Reinhardt

Justin Deoliveira wrote:

Hmmm... i don't see the SLD. Did you include it as an attachment?

Reinhardt Bron wrote:

Hi Justin,

As I said in my previous e-mail, the updating works perfectly, it's the creation of a style that I'm having difficulty with!

My SLD looks exactly the same as it does in the inital post - only with a different value in the Name tag, which obviously doesn't exist on the GeoServer yet.

I could hack out my C# code to post that to you too if that would help.

Thanks again,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

It is appreciated if you can keep your questions on the public list. Thanks.

Reinhardt Bron wrote:

Hi Justin,

"Content-type: application/vnd.ogc.sld+xml"

That line did it - I've been struggling the whole day and last night with this issue, and have very little hair left!!! Thank you!!!! What baffles me is that that isn't specified anywhere in the documentation...? OK, now that I've searched the document, I find it - but not where you'd expect to find it...

Apologies, it is indeed not very evident. I just updated the documentation.

But anyway, so I am now successfully updating styles on the GeoServer from my application - <BIG sigh of relief!>. Final hurdle is the creation - which isn't quite working yet. I'm getting a 403 (Forbidden) error, but I suspect this might be because of the way I am requesting the SLD to be created.

Once again, the details of my request are as follows:
URL: http://localhost:8080/geoserver/rest/styles/
Content Type: application/vnd.ogc.sld+xml
Request Type: POST

Hmmm... everything looks ok. A 403 seems wierd to me... does the style already exist? If so you should use a PUT if you want to update it, rather than a POST.

Could you include the SLD? It would be helpful if I could try it out over here.

Style is valid, accepted by GeoServer when input manually, and has a <sld:Name> tag defined under the <sld:NamedStyle> tag. Would GeoServer infer the name from the SLD correctly, or would I have to send the name of the style through as a request parameter?

In the documentation, style creation is documented as follows:
Method = POST
Response = 201 with Location header
Formats = SLD, XML, JSON
Parameter = /name

/and then "The name parameter specifies the name to be given to the style. This option is most useful when POSTing
a style in SLD format, and an appropriate name can be not be inferred from the SLD itself."

Any pointers would, again, be greatly appreciated!

Depends on your SLD, there are multiple places a Name can show up. If you can supply your SLD I can tell you. But yes, the "name" parameter will be respected before anything in the SLD if specified.

-Justin

Thanks,
Reinhardt

Justin Deoliveira wrote:

Hi Reinhardt,

Could you perhaps share the code snippet that you are using to do the upload. One thing to do is make sure the Content-type header:

Content-type: application/vnd.ogc.sld+xml

Also, are you getting any errors on the server side. If you turn up logging to GEOSERVER_DEVELOPER_LOGGING (to go the UI and go to Config - > Server), and then execute the request you might see some errors in the log.

It might also help to have the code snippet you are using to upload the style.

Thanks,

-Justin

SouthAfrican wrote:

Hi all,

I'm trying to create styles programmatically on GeoServer (1.7.4 - latest
REST plugin installed).

The styles are generated in code, and I have tested that the generated style
can be added in GeoServer manually through the config interface.

My trouble is obviously with the HTTP request that I'm using - this is all
through C# by the way. I have found conflicting information in connection
with the specification of what the REST interface expects with regards to
styles.

For a style creation, I am writing the SDL into my web request, and sending
it to the URL http://localhost:8080/geoserver/rest/styles with a POST
request. Is this correct? Am I supposed to send through the 'name'
parameter in the URL (as in ...rest/styles?name=myNewStyle, or
...?myNewStyle.sld) or should I write the parameter into my request as here:
http://vinothnat.blogspot.com/2007/09/httpwebrequest-post-method.html (I've
tried both, to no avail)...

Any pointers?

Thanks in advance,
Reinhardt

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.