3

By default, GeoServer comes preconfigured with some example workspaces, datastores and layers. One of these workspaces is called it.geosolutions.

If I try to delete this workspace via cUrl and the REST API:

curl -v -u admin:geoserver -XDELETE  http://localhost:8080/geoserver/rest/workspaces/it.geosolutions?recurse=true

, then cUrl returns

HTTP/1.1 404 Not Found

However, if I run the same command on a workspace that does not contain special characters, such as the pre-configured cite workspace:

curl -v -u admin:geoserver -XDELETE  http://localhost:8080/geoserver/rest/workspaces/cite?recurse=true

, then cUrl returns

HTTP/1.1 200 OK

Hence, I guess that the problem in the former case is due to the . in the workspace's name. How can I properly escape such special characters in the URL?

3 Answers 3

3

While typing the question, I found out how to do it. However, sharing is caring ;-) Maybe this will be useful to somebody else one day.

For escaping URLs when using cUrl to access the GeoServer REST API, special characters can be replaced with their respective ASCII codes, so that the problematic example above becomes:

curl -v -u admin:geoserver -XDELETE  http://localhost:8080/geoserver/rest/workspaces/it%2Egeosolutions?recurse=true

Note that the . has been replaced by %2E.

1

Instead of manually looking up ASCII codes, try URL encoding the string. I don't know much about Curl, but I found a few posts that should help anyone else having this problem. This one deals with Unix/Linux and this one deals with the bash shell.

In most languages, you should be able to find a way to URL encode the string and append it to your URL. This is far easier and more reproducible than manually searching for encoding replacements.

2
  • Just as a side note, to be safe, you should always URL encode an unknown string when appending it to your URL just in case there are special characters. Also, if you're dealing with other cultures, you should probably make sure you know what encoding the string you're doing to URL encode comes in.
    – Branco
    Jul 16, 2015 at 16:26
  • 1
    I'm not able to figure it out from the provided links - could anybody please give an example of how this would work for the case described in the question?
    – Dirk
    Jul 22, 2015 at 11:12
1

This solution doesn't seem to work in GeoServer 2.16.2:

$ curl -v -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/it%2Egeosolutions
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'admin'
> GET /geoserver/rest/workspaces/it%2Egeosolutions HTTP/1.1
> Host: localhost:8080
> Authorization: Basic YWRtaW46Z2Vvc2VydmVy
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 404 
< X-Frame-Options: SAMEORIGIN
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Date: Thu, 20 Feb 2020 23:11:10 GMT
< 
* Connection #0 to host localhost left intact
No such workspace: 'it' found(geoserver)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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