0

I have two configurations of Tomcat with the same version of GeoServer and the print module installed as below.

  • The old configuration is Tomcat 8.0.44/GeoServer 2.11.1
  • The new configuration is Tomcat 9.0.10/GeoServer 2.11.1

Using the old configuration I can POST to localhost:1080/geoserver/pdf/print.pdf in SoapUI with the spec file generated from the Print Module demo in the body and this returns a pdf. An application has been written in C# based around this method of generating a pdf.

Using the new configuration (as Tomcat 8.0.x is now end of life, and also a combination of Tomcat 8.5.32/GeoServer 2.11.1) the same POST returns an error message:

<data contentType="text/plain" contentLength="55"><![CDATA[Error while 
generating PDF:
Missing 'spec' parameter
]]></data>

If the POST is changed to a GET with ?spec={SPEC} then this works but for our actual application requirements a POST is the only way to ensure that all of the vector data gets sent to the print module.

Does anyone have experience of using Tomcat 8.5 or above with GeoServer's Print Module using a POST to print.pdf?

The default SPEC file that has been used in SOAPUI testing is

{
    "units":"degrees",
    "srs":"EPSG:4326",
    "layout":"A4 portrait",
    "dpi":75,
    "layers":[
    {
        "baseURL":"http://localhost:1080/geoserver/wms",
        "opacity":1,
        "singleTile":false,
        "type":"WMS",
        "layers":["topp:states"],
        "format":"image/jpeg",
        "styles":[""],
        "customParams":{}
    },
    {
        "type":"Vector",
        "styles":
        {
            "1":
            {
                "externalGraphic":"http://geoserver.org/img/geoserver-logo.png",
                "strokeColor":"red",
                "fillColor":"red",
                "fillOpacity":0.7,
                "strokeWidth":2,
                "pointRadius":12
            }
        },
        "styleProperty":"_gx_style",
        "geoJson":{
        "type":"FeatureCollection",
        "features":[{
            "type":"Feature",
            "id":"OpenLayers.Feature.Vector_52",
            "properties":{"_gx_style":1},
            "geometry":{
            "type":"Polygon",
            "coordinates":[[[-97,39],[-98,40],[-96,41],[-97,39]]]
        }
    },
    {
        "type":"Feature",
        "id":"OpenLayers.Feature.Vector_61",
        "properties":{"_gx_style":1},
        "geometry":{
            "type":"LineString",
            "coordinates":[[-97,40],[-98,39],[-99,38]]
        }
    },
    {
        "type":"Feature",
        "id":"OpenLayers.Feature.Vector_64",
        "properties":{"_gx_style":1},
        "geometry":{
            "type":"Point",
            "coordinates":[-98,38]
        }
    }
    ]},
    "name":"vector",
    "opacity":1
    }],
    "pages":[{
        "center":[-98.000000000002,40],
        "scale":4000000,
        "rotation":"0",
        "mapTitle":"A custom title",
        "comment":"A custom comment"
    }]
}
1

To get this working in Tomcat 9 I had to send the post data as

ContentType = "application/x-www-form-urlencoded";

and encoded the post json in JavaScript as

"spec=" + encodeUri(jsonObject)

or for my C# implementation i used

postData = "spec=" + HttpUtility.UrlEncode(jsonStr);
byte[] data = Encoding.ASCII.GetBytes(postData);
httpWebRequest.ContentLength = data.Length;
Stream requestStream = httpWebRequest.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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