Issue with GetMapResponse

Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Issue with GetMapResponse

Raj Hans

Hello,

 

I have been trying to get the WMS feature of geotools to work and am having difficulty with the map request. It always throws an exception. When I take the same URL and paste into a web browser I get the image that I am expecting. I have tried a few different map servers with the same result. Any ideas? Output and code is below.

Thanks,

Raj

 

 

Output:

 

java.io.IOException: Server returned HTTP response code: 400 for URL: http://ows.terrestris.de/osm/service?SERVICE=WMS&LAYERS=TOPO-OSM-WMS,TOPO-WMS,OSM-Overlay-WMS,OSM-WMS&FORMAT=image%2Fpng&HEIGHT=600&TRANSPARENT=TRUE&REQUEST=GetMap&BBOX=-180, -85.0511287798, 180, 85.011287798&WIDTH=600&STYLES=,,,&SRS=EPSG:4326&VERSION=1.1.1

                at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839)

                at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)

                at org.geotools.data.ows.SimpleHttpClient$SimpleHTTPResponse.<init>(SimpleHttpClient.java:171)

                at org.geotools.data.ows.SimpleHttpClient.get(SimpleHttpClient.java:102)

                at org.geotools.data.ows.AbstractOpenWebService.internalIssueRequest(AbstractOpenWebService.java:442)

                at org.geotools.data.wms.WebMapServer.issueRequest(WebMapServer.java:439)

 

 

Code:

 

      WebMapServer wms = null;

        try {

            URL url = new URL("http://ows.terrestris.de/osm/service?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities");

 

            wms = new WebMapServer(url);

 

            WMSCapabilities capabilities = wms.getCapabilities();

 

            String serverName = capabilities.getService().getName();

            String serverTitle = capabilities.getService().getTitle();

            System.err.println("Capabilities retrieved from server: " + serverName + " (" + serverTitle + ")");

 

            //Get formats for GetMap operation

            List<String> formats = wms.getCapabilities().getRequest().getGetMap().getFormats();

            if (formats != null) {

                System.err.println("Formats:");

                for (int i = 0; i < formats.size(); i++) {

                    System.err.println("Format:" + formats.get(i));

                }

            }

 

            List layers = capabilities.getLayerList();

            if (layers != null) {

                for (int i = 0; i < layers.size(); i++) {

                    System.err.println("Layer:" + layers.get(i).toString());

                }

            }

 

            GetMapRequest request = wms.createGetMapRequest();

 

            request.setFormat("image/png");

            request.setDimensions("600", "600");

            request.setTransparent(true);

            request.setSRS("EPSG:4326");

            request.setBBox("-180, -85.0511287798, 180, 85.011287798");

            System.err.println("Named Layers __________");

            for (org.geotools.data.ows.Layer layer : WMSUtils.getNamedLayers(capabilities)) {

                System.err.println("Layer:" + layer.getName());

                request.addLayer(layer);

            }

            GetMapResponse response = null;

            try {

                System.err.println(request.getFinalURL());

                response = (GetMapResponse) wms.issueRequest(request);  ß THROWS EXCEPTION HERE

            } catch (ServiceException e) {

                System.err.println("Server sendet eine ServiceException: " + e.getMessage());

            }

        } catch (MalformedURLException ex) {

            Logger.getLogger(GTMapViewer.class.getName()).log(Level.SEVERE, null, ex);

        } catch (IOException ex) {

            Logger.getLogger(GTMapViewer.class.getName()).log(Level.SEVERE, null, ex);

        } catch (ServiceException ex) {

            Logger.getLogger(GTMapViewer.class.getName()).log(Level.SEVERE, null, ex);

        }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Issue with GetMapResponse

Ian Turton
This is a bit of an odd one - the fix is to remove the spaces from your bounding box - request.setBBox("-180,-85.0511287798,180,85.011287798");

and then it works fine. 

However, I'm not sure who's fault it is - TBH geotools probably should only take a proper envelope, I can't recall what the WMS spec says about spaces in the bbox but I suspect they are ok if you encode them (which is why it works from the browser) so it is probably a bug that the bbox is URL encoded before being sent. 

Can you raise a bug at https://osgeo-org.atlassian.net/projects/GEOT/issues and assign it to me - I'll try to look at it when I get a chance.

Ian

On 11 July 2017 at 13:58, Raj Hans <[hidden email]> wrote:

Hello,

 

I have been trying to get the WMS feature of geotools to work and am having difficulty with the map request. It always throws an exception. When I take the same URL and paste into a web browser I get the image that I am expecting. I have tried a few different map servers with the same result. Any ideas? Output and code is below.

Thanks,

Raj

 

 

Output:

 

java.io.IOException: Server returned HTTP response code: 400 for URL: http://ows.terrestris.de/osm/service?SERVICE=WMS&LAYERS=TOPO-OSM-WMS,TOPO-WMS,OSM-Overlay-WMS,OSM-WMS&FORMAT=image%2Fpng&HEIGHT=600&TRANSPARENT=TRUE&REQUEST=GetMap&BBOX=-180, -85.0511287798, 180, 85.011287798&WIDTH=600&STYLES=,,,&SRS=EPSG:4326&VERSION=1.1.1

                at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839)

                at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)

                at org.geotools.data.ows.SimpleHttpClient$SimpleHTTPResponse.<init>(SimpleHttpClient.java:171)

                at org.geotools.data.ows.SimpleHttpClient.get(SimpleHttpClient.java:102)

                at org.geotools.data.ows.AbstractOpenWebService.internalIssueRequest(AbstractOpenWebService.java:442)

                at org.geotools.data.wms.WebMapServer.issueRequest(WebMapServer.java:439)

 

 

Code:

 

      WebMapServer wms = null;

        try {

            URL url = new URL("http://ows.terrestris.de/osm/service?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities");

 

            wms = new WebMapServer(url);

 

            WMSCapabilities capabilities = wms.getCapabilities();

 

            String serverName = capabilities.getService().getName();

            String serverTitle = capabilities.getService().getTitle();

            System.err.println("Capabilities retrieved from server: " + serverName + " (" + serverTitle + ")");

 

            //Get formats for GetMap operation

            List<String> formats = wms.getCapabilities().getRequest().getGetMap().getFormats();

            if (formats != null) {

                System.err.println("Formats:");

                for (int i = 0; i < formats.size(); i++) {

                    System.err.println("Format:" + formats.get(i));

                }

            }

 

            List layers = capabilities.getLayerList();

            if (layers != null) {

                for (int i = 0; i < layers.size(); i++) {

                    System.err.println("Layer:" + layers.get(i).toString());

                }

            }

 

            GetMapRequest request = wms.createGetMapRequest();

 

            request.setFormat("image/png");

            request.setDimensions("600", "600");

            request.setTransparent(true);

            request.setSRS("EPSG:4326");

            request.setBBox("-180, -85.0511287798, 180, 85.011287798");

            System.err.println("Named Layers __________");

            for (org.geotools.data.ows.Layer layer : WMSUtils.getNamedLayers(capabilities)) {

                System.err.println("Layer:" + layer.getName());

                request.addLayer(layer);

            }

            GetMapResponse response = null;

            try {

                System.err.println(request.getFinalURL());

                response = (GetMapResponse) wms.issueRequest(request);  ß THROWS EXCEPTION HERE

            } catch (ServiceException e) {

                System.err.println("Server sendet eine ServiceException: " + e.getMessage());

            }

        } catch (MalformedURLException ex) {

            Logger.getLogger(GTMapViewer.class.getName()).log(Level.SEVERE, null, ex);

        } catch (IOException ex) {

            Logger.getLogger(GTMapViewer.class.getName()).log(Level.SEVERE, null, ex);

        } catch (ServiceException ex) {

            Logger.getLogger(GTMapViewer.class.getName()).log(Level.SEVERE, null, ex);

        }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




--
Ian Turton

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Loading...