]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.maps/src/org/simantics/maps/tests/WMSTest1.java
Share some projects for Simantics District
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / tests / WMSTest1.java
diff --git a/org.simantics.district.maps/src/org/simantics/maps/tests/WMSTest1.java b/org.simantics.district.maps/src/org/simantics/maps/tests/WMSTest1.java
new file mode 100644 (file)
index 0000000..cec0f78
--- /dev/null
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.maps.tests;
+
+import java.awt.geom.Rectangle2D;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+
+import org.simantics.maps.WebService;
+import org.simantics.maps.wms.WMSGetMapQuery;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class WMSTest1 {
+
+    private static String serviceUrl = "http://wms.jpl.nasa.gov/wms.cgi";
+    
+    public static void main(String[] args) throws MalformedURLException, URISyntaxException {
+        // Create a method instance.
+        WebService service = new WebService(serviceUrl);
+        WMSGetMapQuery req = new WMSGetMapQuery(600, 300, new Rectangle2D.Double(-180,-90,360,180), "image/jpeg", "global_mosaic");
+
+        HttpURLConnection connection = null;
+        try {
+               connection = service.openConnection("", req.toString());
+            // Execute the method.
+            int statusCode = connection.getResponseCode();
+
+            if (statusCode != HttpURLConnection.HTTP_OK) {
+                System.err.println("Method failed: " + connection.getResponseMessage());
+            }
+
+            // Read the response body.
+            byte[] buf = new byte[16384];
+            int read = 0;
+            
+            InputStream response = connection.getInputStream();
+            FileOutputStream fo = new FileOutputStream(File.createTempFile("wmsresponse", ""));
+            try {
+                while ((read = response.read(buf)) != -1) {
+                    fo.write(buf, 0, read);
+                }
+            } finally {
+                fo.close();
+                response.close();
+            }
+
+        } catch (IOException e) {
+            System.err.println("Fatal transport error: " + e.getMessage());
+            e.printStackTrace();
+        } finally {
+            // Release the connection.
+            connection.disconnect();
+        }  
+    }
+}
\ No newline at end of file