I am setting the SLD Body of a WMS layer on the client side. I set the style in JSON and I have some functions that convert the JSON to SLD (OpenLayers functions). It works fine for displaying the layer with all its colors.

But when I use a legend (GetLegendGraphic from GeoServer), I have a limit in the size of the SLD Body. The limit of characters is about 20.000. When I perform the GetLegendGraphic request and the url is longer than (about) 20.000 characters, an error occurs and the legend is not displayed. BUT the layer is still correctly displayed (as you can see in the images below).

Below the 20.000 characters, the legend works fine.

I find it strange that the layer is correctly displayed and the legend isn't. Both are fetched via GeoServer requests.

Could you help me solve this?

I wanted a way to accept long strings in the GetLegendGraphic or a way to compress the string with the SLD body (so that it has fewer characters).


SLD Body with 18006 characters (this shows a correct legend)


SLD Body with 24245 characters (this does not show the legend, still draws the layer correctly)


  • 3
    What's your server setup? It's probably not actually a GeoServer issue, but rather a Tomcat/Jetty/Apache/??? issue.
    – stuporglue
    Jan 22, 2015 at 20:30
  • 1
    Also, can you prepare the SLD body and then save it to the server as a named style so you can just refer to the style, or is it dynamic somehow?
    – stuporglue
    Jan 22, 2015 at 20:32
  • 2
    Hi @stuporglue. Your tip about configuring the Tomcat server solved the problem. We increased the 'maxPostSize' in the Tomcat configuration. Thank you so much. You deserve some points for giving the answer. Thanks. :D
    – joaorodr84
    Jan 22, 2015 at 22:43
  • 1
    Glad to help out!
    – stuporglue
    Jan 23, 2015 at 6:14

1 Answer 1


You could post the sld to a php-file which writes a sld-file on the server(considering some security aspects). Then you could point to this file:

Example: 4 times the same layer, getlegendgraphic with 4 different sld's:





Or as user stuporglue mentioned you could use geoservers rest interface but there you would have to consider how to erase unused styles again: http://docs.geoserver.org/stable/en/user/rest/examples/curl.html

  • Thanks @Thomas, but the solution proposed by stuporglue worked like a charm. :)
    – joaorodr84
    Jan 23, 2015 at 1:13

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.