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
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to