Source Code Cross Referenced for ServersTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » wms » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.data.wms.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2004-2006, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.data.wms.test;
017:
018:        import java.awt.image.BufferedImage;
019:        import java.io.IOException;
020:        import java.io.PrintStream;
021:        import java.net.URL;
022:        import java.net.URLEncoder;
023:        import java.util.ArrayList;
024:        import java.util.Arrays;
025:        import java.util.Iterator;
026:        import java.util.List;
027:        import java.util.Random;
028:
029:        import javax.imageio.ImageIO;
030:
031:        import junit.framework.TestCase;
032:
033:        import org.geotools.data.ows.CRSEnvelope;
034:        import org.geotools.data.ows.Layer;
035:        import org.geotools.data.ows.WMSCapabilities;
036:        import org.geotools.data.wms.WebMapServer;
037:        import org.geotools.data.wms.request.GetMapRequest;
038:        import org.geotools.data.wms.response.GetMapResponse;
039:        import org.geotools.ows.ServiceException;
040:        import org.xml.sax.SAXException;
041:
042:        public class ServersTest extends TestCase {
043:            public void testServers() throws Exception {
044:
045:                List servers = new ArrayList();
046:                /*
047:                 File serverFile = TestData.file(this, "servers.txt");
048:                 BufferedReader br = new BufferedReader(new FileReader(serverFile));
049:                 String line = null;
050:                 while ((line = br.readLine()) != null) {
051:                 try {
052:                 servers.add(new URL(line));
053:                 } catch (MalformedURLException e) {
054:
055:                 }
056:                 }
057:                 */
058:                //servers.add(new URL("http://office.refractions.net/~chodgson/googlemaps/googlewms.php?request=getcapabilities"));
059:                //    	URL[] servers = new URL[50];
060:                //		servers[0] = new URL("http://wms.jpl.nasa.gov/wms.cgi?VERSION=1.1.1&SERVICE=WMS&REQUEST=GetCapabilities");
061:                //    	servers[1] = new URL("http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?CONFIG=main&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities");
062:                //    	servers[2] = new URL("http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?VERSION=1.1.0&REQUEST=GetCapabilities");
063:                //  This returning Gzip content
064:                //    	servers[3] = new URL("http://wms.cits.rncan.gc.ca/cgi-bin/cubeserv.cgi?VERSION=1.1.0&REQUEST=GetCapabilities");
065:                //    	servers[4] = new URL("http://terraservice.net/ogccapabilities.ashx?version=1.1.1&request=GetCapabilties");
066:                //    	servers[5] = new URL("http://www2.demis.nl/mapserver/Request.asp?VERSION=1.3.0&SERVICE=WMS&REQUEST=GetCapabilities");
067:                //THIS ONE OFFLINE
068:                //        servers[6] = new URL("http://datamil.udel.edu/servlet/com.esri.wms.Esrimap?servicename=DE_census2k_sf1&VERSION=1.0.0&request=capabilities");
069:                //    	servers[7] = new URL("http://www.lifemapper.org/Services/WMS/?Service=WMS&VERSION=1.1.1&request=getcapabilities");
070:                //    	this server returns OGC for 1.3.0
071:                //    	servers[8] = new URL("http://globe.digitalearth.gov/viz-bin/wmt.cgi?VERSION=1.1.0&Request=GetCapabilities");
072:                //    	servers[9] = new URL("http://www.geographynetwork.ca/wmsconnector/com.esri.wsit.WMSServlet/Geobase_NRN_NewfoundlandAndLabrador_I_Detail?request=GetCapabilities");
073:                //    	servers[10] = new URL("http://gisdata.usgs.net/servlet/com.esri.wms.Esrimap?REQUEST=GetCapabilities&VERSION=1.3.0&SERVICE=WMS");
074:                //    	servers[11] = new URL("http://www.refractions.net:8080/geoserver/wms/?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"); //$NON-NLS-1$
075:                //1.0.0 freezes.
076:                //    	servers[12] = new URL("http://mapserv2.esrin.esa.it/cubestor/cubeserv/cubeserv.cgi?VERSION=1.1.1&REQUEST=GetCapabilities&SERVICE=WMS");
077:                //		servers[13] = new URL("http://mesonet.agron.iastate.edu/wms/comprad.php?request=getcapabilities");
078:                //		servers[14] = new URL("http://redspider.us/ionicweb/wfs/METRODC?request=getcapabilities&service=WMS&version=1.1.1");
079:                //		servers[15] = new URL("http://webservices.ionicsoft.com/ionicweb/wfs/BOSTON_ORA?service=WMS&request=GetCapabilities&vesrion=1.1.1");
080:                //		servers[16] = new URL("http://oceanesip.jpl.nasa.gov/de.xml");
081:                //		servers[17] = new URL("http://libcwms.gov.bc.ca/wmsconnector/com.esri.wsit.WMSServlet/ogc_layer_service?REQUEST=capabilities");
082:                //		servers[18] = new URL("http://www.geographynetwork.com/servlet/com.esri.wms.Esrimap?ServiceName=GFW_Forest&VERSION=1.0.0&request=capabilities");
083:                //		servers[19] = new URL("http://atlas.gc.ca/cgi-bin/atlaswms_en?VERSION=1.1.0&request=GetCapabilities");
084:                //OFFLINE		servers[20] = new URL("http://office.refractions.net:4001/cgi-bin/mapserv?map=/opt/dra2/orthophotos/tiles.map&request=getcapabilities");
085:                //		servers[21] = new URL("http://mesonet.agron.iastate.edu/wms/comprad.php?request=getcapabilities");
086:                //    	servers[22] = new URL("http://wms.larioja.org/request.asp?request=getcapabilities");
087:                //    	servers[23] = new URL("http://atlas.walis.wa.gov.au/servlet/com.esri.wms.Esrimap?VERSION=1.1.0&Request=getcapabilities");
088:                //    	servers[24] = new URL("http://iceds.ge.ucl.ac.uk/cgi-bin/wms?map=wms.map&SERVICE=WMS&REQUEST=GetCapabilities");
089:                //    	servers[25] = new URL("http://test.landmap.ac.uk/ecwp/ecw_wms.dll?request=GetCapabilities&service=wms");
090:                //    	servers[26] = new URL("http://emandev.cciw.ca/cgi-bin/mapserver/mapserv.exe?REQUEST=GetCapabilities&MAP=C:/Inetpub/wwwroot/emanco/cgi-bin/mapserver/naturewatch.map&VERSION=1.1.1&SERVICE=WMS");
091:                int total = 0;
092:                int passedCount = 0;
093:
094:                for (int i = 0; i < servers.size(); i++) {
095:                    URL server = (URL) servers.get(i);
096:                    total++;
097:                    Random random = new Random();
098:                    String dir = "tests";
099:                    String filename = URLEncoder.encode(server.getHost()
100:                            + random.nextInt(10000), "UTF-8");
101:                    //            File file = new File("C:\\"+dir+"\\"+filename+".txt");
102:                    //            file.createNewFile();
103:                    //            PrintStream out = new PrintStream(new FileOutputStream(file));
104:                    PrintStream out = System.out;
105:                    boolean passed = serverTest(out, server);
106:                    out.flush();
107:                    out.close();
108:
109:                    if (passed) {
110:                        //System.out.println(server.toExternalForm() + " passed.");
111:                        passedCount++;
112:                        //                file.delete();
113:                    } else {
114:                        //System.out.println(server.toExternalForm() + " failed.");
115:                    }
116:                    //    		    WebMapServer wms = new WebMapServer(servers[i]);
117:                    //    			assertNotNull("Missing Capabilities",wms.getCapabilities());
118:                    //    		    WMSCapabilities capabilities = wms.getCapabilities();
119:                    //    		    assertNotNull(capabilities.getRequest());
120:                }
121:
122:                //        System.out.println("Total tested: "+total);
123:                //        System.out.println("Total passed: "+passedCount);
124:            }
125:
126:            public boolean serverTest(PrintStream out, URL url) {
127:                WebMapServer wms = null;
128:
129:                boolean passed = true;
130:                out.println("Beginning tests for server:");
131:                out.println(url);
132:                out.print("Parsing Capabilities...");
133:                try {
134:                    wms = new WebMapServer(url);
135:                    out.println("passed.");
136:                } catch (ServiceException e) {
137:                    out.println("failed.");
138:                    passed = false;
139:                    while (e != null) {
140:                        if (e.getLocator() != null
141:                                && e.getLocator().length() != 0) {
142:                            out.println("ServiceException at " + e.getLocator()
143:                                    + ": " + e.getMessage() + "(" + e.getCode()
144:                                    + ")");
145:                        }
146:                        out.println("ServiceException: " + e.getMessage() + "("
147:                                + e.getCode() + ")");
148:                        e = e.getNext();
149:                    }
150:                    return passed;
151:                } catch (IOException e) {
152:                    out.println("failed.");
153:                    passed = false;
154:                    out.println("IOException: " + e.getMessage());
155:                    e.printStackTrace(out);
156:                    return passed;
157:                } catch (SAXException e) {
158:                    out.println("failed.");
159:                    passed = false;
160:                    out.println("SAXException: " + e.getMessage());
161:                    e.printStackTrace(out);
162:                    return passed;
163:                }
164:
165:                WMSCapabilities caps = wms.getCapabilities();
166:                assertNotNull(caps);
167:
168:                out.println("Validating layer LatLonBoundingBoxes...");
169:                Iterator iter = caps.getLayerList().iterator();
170:                while (iter.hasNext()) {
171:                    Layer layer = (Layer) iter.next();
172:                    if (layer.getLatLonBoundingBox() == null) {
173:                        if (layer.getName() != null) {
174:                            out.println("WARNING: Layer '" + layer.getName()
175:                                    + "' contains no LatLonBoundingBox.");
176:                            passed = false;
177:                        }
178:                    }
179:                }
180:
181:                Layer layer = null;
182:                out.print("Looking for a named layer...");
183:                iter = caps.getLayerList().iterator();
184:                while (iter.hasNext()) {
185:                    Layer tempLayer = (Layer) iter.next();
186:                    if (tempLayer.getName() != null) {
187:                        layer = tempLayer;
188:                        out.println("found one. Using layer '"
189:                                + layer.getName() + "'");
190:                        break;
191:                    }
192:                }
193:                String format = null;
194:                if (layer == null) {
195:                    out
196:                            .println("server contains no named layers. Cannot perform GetMap requests on it");
197:                    passed = false;
198:                } else {
199:                    out.print("Checking for GetMap operation...");
200:                    if (caps.getRequest().getGetMap() == null) {
201:                        out
202:                                .println("NOT FOUND. Will attempt a request using 'image/gif' anyway.");
203:                        passed = false;
204:                        format = "image/gif";
205:                    } else {
206:                        out.println("found.");
207:                        out.print("Searching for a suitable format...");
208:                        List formats = caps.getRequest().getGetMap()
209:                                .getFormats();
210:                        if (formats.contains("image/png")) {
211:                            format = "image/png";
212:                            out.println("using 'image/png'.");
213:                        }
214:
215:                        if (format == null && formats.contains("image/gif")) {
216:                            format = "image/gif";
217:                            out.println("using 'image/gif'.");
218:                        }
219:
220:                        if (format == null && formats.contains("image/jpeg")) {
221:                            format = "image/jpeg";
222:                            out.println("using 'image/jpeg'.");
223:                        }
224:
225:                        if (format == null) {
226:                            format = (String) formats.get(0);
227:                            out
228:                                    .println("server does not support GIF, PNG or JPEG. Using '"
229:                                            + format + "'");
230:                            passed = false;
231:                        }
232:                    }
233:                }
234:
235:                out.print("Performing GetMap operation...");
236:                GetMapRequest request = wms.createGetMapRequest();
237:
238:                request.addLayer(layer);
239:                CRSEnvelope bbox = layer.getLatLonBoundingBox();
240:                request.setBBox(bbox);
241:                request.setFormat(format);
242:                request.setSRS("EPSG:4326");
243:                request.setDimensions("100", "100");
244:
245:                try {
246:                    GetMapResponse response = wms.issueRequest(request);
247:                    out.println("received a response.");
248:
249:                    out.print("Checking returned format...");
250:                    if (response.getContentType().indexOf(format) == -1) {
251:                        out.println("server returned bad format. Expected "
252:                                + format + ", got " + response.getContentType()
253:                                + ".");
254:                        passed = false;
255:                    } else {
256:                        out.println("passed.");
257:                    }
258:
259:                    out.print("Checking dimensions...");
260:                    BufferedImage image = ImageIO.read(response
261:                            .getInputStream());
262:                    if (image == null) {
263:                        out.println("returned a bad image. ContentType is "
264:                                + response.getContentType());
265:                        passed = false;
266:                    } else if (image.getWidth() != 100
267:                            || image.getHeight() != 100) {
268:                        out
269:                                .println("server returned bad dimensions. Expect 100, 100. Returned "
270:                                        + image.getWidth()
271:                                        + ","
272:                                        + image.getHeight());
273:                        passed = false;
274:                    } else {
275:                        out.println("passed.");
276:                    }
277:                } catch (ServiceException e) {
278:                    out.println("failed.");
279:                    passed = false;
280:                    while (e != null) {
281:                        if (e.getLocator() != null
282:                                && e.getLocator().length() != 0) {
283:                            out.println("ServiceException at " + e.getLocator()
284:                                    + ": " + e.getMessage() + "(" + e.getCode()
285:                                    + ")");
286:                        }
287:                        out.println("ServiceException: " + e.getMessage() + "("
288:                                + e.getCode() + ")");
289:                        e = e.getNext();
290:                    }
291:                } catch (IOException e) {
292:                    out.println("failed.");
293:                    passed = false;
294:                    out.println("IOException: " + e.getMessage());
295:                    e.printStackTrace(out);
296:                } catch (SAXException e) {
297:                    out.println("failed.");
298:                    passed = false;
299:                    out.println("SAXException: " + e.getMessage());
300:                    e.printStackTrace(out);
301:                } finally {
302:                    out.println(request.getFinalURL());
303:                }
304:
305:                //        if (caps.getRequest().getGetFeatureInfo() != null) {
306:                //            out.println("");
307:                //            out.println("Server supports GetFeatureInfo requests. Beginning tests.");
308:                //
309:                //            Layer qLayer = null;
310:                //            out.print("Locating a queryable layer...");
311:                //            Set qLayers = WMSUtils.getQueryableLayers(caps);
312:                //            if (qLayers != null && qLayers.size() != 0) {
313:                //                qLayer = (Layer) qLayers.iterator().next();
314:                //                out.println("found layer '"+qLayer.getName()+"'.");
315:                //            } else {
316:                //                out.println("NOT FOUND");
317:                //                passed = false;
318:                //            }
319:                //
320:                //            if (qLayer != null) {
321:                //                GetFeatureInfoRequest gfiRequest = wms.createGetFeatureInfoRequest(request);
322:                //                gfiRequest.addQueryLayer(qLayer);
323:                //                gfiRequest.setFeatureCount(5);
324:                //                gfiRequest.setQueryPoint(50,50);
325:                //
326:                //                String gfiFormat = caps.getRequest().getGetFeatureInfo().getFormatStrings()[0];
327:                //                out.println("Using "+gfiFormat+" as format during GetFeatureInfo request.");
328:                //
329:                //                gfiRequest.setInfoFormat(gfiFormat);
330:                //
331:                //                try {
332:                //                    out.print("Performing GetFeatureInfo request...");
333:                //                    GetFeatureInfoResponse response = wms.issueRequest(gfiRequest);
334:                //                    out.println("response received.");
335:                //
336:                //                    out.print("Checking returned format...");
337:                //                    if (response.getContentType().indexOf(gfiFormat) == -1) {
338:                //                        out.println("server returned bad format. Expected "+gfiFormat+", got "+response.getContentType()+".");
339:                //                        passed = false;
340:                //                    } else {
341:                //                        out.println("passed.");
342:                //                    }
343:                //                } catch (ServiceException e) {
344:                //                    out.println("failed.");
345:                //                    passed = false;
346:                //                    while (e != null) {
347:                //                        if (e.getLocator() != null && e.getLocator().length() != 0) {
348:                //                            out.println("ServiceException at "+e.getLocator()+": "+e.getMessage()+"("+e.getCode()+")");
349:                //                        }
350:                //                        out.println("ServiceException: "+e.getMessage()+"("+e.getCode()+")");
351:                //                        e = e.getNext();
352:                //                    }
353:                //                } catch (IOException e) {
354:                //                    out.println("failed.");
355:                //                    passed = false;
356:                //                    out.println("IOException: "+e.getMessage());
357:                //                    e.printStackTrace(out);
358:                //                } catch (SAXException e) {
359:                //                    out.println("failed.");
360:                //                    passed = false;
361:                //                    out.println("SAXException: "+e.getMessage());
362:                //                    e.printStackTrace(out);
363:                //                } finally {
364:                //                    out.println(gfiRequest.getFinalURL());
365:                //                }
366:                //            }
367:                //        }
368:                return passed;
369:            }
370:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.