1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.maps.tests;
14 import java.awt.geom.Rectangle2D;
16 import java.io.FileOutputStream;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.net.HttpURLConnection;
20 import java.net.MalformedURLException;
21 import java.net.URISyntaxException;
23 import org.simantics.maps.WebService;
24 import org.simantics.maps.wms.WMSGetMapQuery;
27 * @author Tuukka Lehtonen
29 public class WMSTest1 {
31 private static String serviceUrl = "http://wms.jpl.nasa.gov/wms.cgi";
33 public static void main(String[] args) throws MalformedURLException, URISyntaxException {
34 // Create a method instance.
35 WebService service = new WebService(serviceUrl);
36 WMSGetMapQuery req = new WMSGetMapQuery(600, 300, new Rectangle2D.Double(-180,-90,360,180), "image/jpeg", "global_mosaic");
38 HttpURLConnection connection = null;
40 connection = service.openConnection("", req.toString());
41 // Execute the method.
42 int statusCode = connection.getResponseCode();
44 if (statusCode != HttpURLConnection.HTTP_OK) {
45 System.err.println("Method failed: " + connection.getResponseMessage());
48 // Read the response body.
49 byte[] buf = new byte[16384];
52 InputStream response = connection.getInputStream();
53 FileOutputStream fo = new FileOutputStream(File.createTempFile("wmsresponse", ""));
55 while ((read = response.read(buf)) != -1) {
56 fo.write(buf, 0, read);
63 } catch (IOException e) {
64 System.err.println("Fatal transport error: " + e.getMessage());
67 // Release the connection.
68 connection.disconnect();