Author: aaime
Date: 2011-12-20 00:11:41 -0800 (Tue, 20 Dec 2011)
New Revision: 38435
Added:
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/ows/MockHttpClient.java
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/ows/MockHttpResponse.java
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/map/
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/map/WMSCoverageReaderTest.java
branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/
branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/caps130.xml
branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/caps130_crs84.xml
branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/world.png
Modified:
branches/2.7.x/modules/extension/wms/pom.xml
branches/2.7.x/modules/extension/wms/src/main/java/org/geotools/data/ows/Layer.java
branches/2.7.x/modules/extension/wms/src/main/java/org/geotools/map/WMSCoverageReader.java
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/WMSUtilsTest.java
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/Geot553Test.java
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/LocalGeoServerOnlineTest.java
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WMS1_0_0_OnlineTest.java
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WMS1_1_0_OnlineTest.java
branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WebMapServerOnlineTest.java
branches/2.7.x/modules/library/api/src/main/java/org/geotools/geometry/jts/ReferencedEnvelope.java
branches/2.7.x/modules/plugin/epsg-extension/src/main/resources/org/geotools/referencing/factory/epsg/esri.properties
branches/2.7.x/modules/plugin/epsg-extension/src/test/java/org/geotools/referencing/factory/epsg/EsriExtensionTest.java
Log:
[GEOT-3989] Accessing a WMS 1.3 server advertising only CRS:84 won't work with WMSLayer
Modified: branches/2.7.x/modules/extension/wms/pom.xml
===================================================================
--- branches/2.7.x/modules/extension/wms/pom.xml 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/pom.xml 2011-12-20 08:11:41 UTC (rev 38435)
@@ -128,16 +128,27 @@
</dependency>
<dependency>
<groupId>org.geotools</groupId>
- <artifactId>gt-epsg-wkt</artifactId>
+ <artifactId>gt-epsg-hsql</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
+ <artifactId>gt-epsg-extension</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.geotools</groupId>
<artifactId>gt-sample-data</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
@@ -160,7 +171,6 @@
<exclude>**/WMS1_1_1_OnlineTest.java</exclude>
<exclude>**/WMS1_3_0_OnlineTest.java</exclude>
<!-- The following tests fail -->
- <exclude>**/Geot553Test.java</exclude>
<exclude>**/WMSSchemaTest.java</exclude>
</excludes>
</configuration>
Modified: branches/2.7.x/modules/extension/wms/src/main/java/org/geotools/data/ows/Layer.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/main/java/org/geotools/data/ows/Layer.java 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/src/main/java/org/geotools/data/ows/Layer.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -213,9 +213,13 @@
if (allBoundingBoxesCache == null) {
allBoundingBoxesCache = new HashMap<String, CRSEnvelope>();
+ for( CRSEnvelope bbox : getLayerBoundingBoxes() ){
+ allBoundingBoxesCache.put( bbox.getSRSName(), bbox );
+ }
+
Layer parent = this.getParent();
- while (parent != null) {
- for( CRSEnvelope bbox : getLayerBoundingBoxes() ){
+ while (parent != null && allBoundingBoxesCache.size() == 0) {
+ for( CRSEnvelope bbox : parent.getLayerBoundingBoxes() ){
allBoundingBoxesCache.put( bbox.getSRSName(), bbox );
}
parent = parent.getParent();
Modified: branches/2.7.x/modules/extension/wms/src/main/java/org/geotools/map/WMSCoverageReader.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/main/java/org/geotools/map/WMSCoverageReader.java 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/src/main/java/org/geotools/map/WMSCoverageReader.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -34,6 +34,7 @@
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.ows.ServiceException;
import org.geotools.referencing.CRS;
+import org.geotools.referencing.CRS.AxisOrder;
import org.geotools.renderer.lite.RendererUtilities;
import org.geotools.util.Version;
import org.opengis.coverage.grid.Format;
@@ -115,11 +116,6 @@
CoordinateReferenceSystem requestCRS;
/**
- * Flag telling us if we have to flip geographic bounds before using them
- */
- boolean flipGeographic;
-
- /**
* Builds a new WMS coverage reader
*
* @param wms
@@ -128,10 +124,6 @@
public WMSCoverageReader(WebMapServer wms, Layer layer) {
this.wms = wms;
- // check if we need coordinate flipping
- Version version = new Version(wms.getCapabilities().getVersion());
- flipGeographic = version.compareTo(new Version("1.3.0")) >= 0;
-
// init the reader
addLayer(layer);
@@ -390,7 +382,7 @@
// bbox might need flipping
ReferencedEnvelope requestEnvelope = gridEnvelope;
- if(requestCRS instanceof GeographicCRS && flipGeographic) {
+ if(axisFlipped(requestSrs)) {
requestEnvelope = flipEnvelope(requestEnvelope);
}
mapRequest.setBBox(requestEnvelope);
@@ -403,6 +395,29 @@
return gridEnvelope;
}
+ private boolean axisFlipped(String srsName) {
+ Version version = new Version(wms.getCapabilities().getVersion());
+ if(version.compareTo(new Version("1.3.0")) < 0) {
+ // aah, sheer simplicity
+ return false;
+ } else {
+ // gah, hell gates breaking loose
+ if(srsName.startsWith("EPSG:")) {
+ try {
+ String epsgNative = "urn:x-ogc:def:crs:EPSG:".concat(srsName.substring(5));
+ return CRS.getAxisOrder(CRS.decode(epsgNative)) == AxisOrder.NORTH_EAST;
+ } catch(Exception e) {
+ LOGGER.log(Level.WARNING, "Failed to determine axis order for "
+ + srsName + ", assuming east/north", e);
+ return false;
+ }
+ } else {
+ // CRS or AUTO, none of them is flipped so far
+ return false;
+ }
+ }
+ }
+
private ReferencedEnvelope flipEnvelope(ReferencedEnvelope requestEnvelope) {
double minx = requestEnvelope.getMinX();
double miny = requestEnvelope.getMinY();
@@ -423,13 +438,14 @@
* @return
*/
public void updateBounds() {
+ boolean axisFlipped = axisFlipped(srsName);
ReferencedEnvelope result = reference(layers.get(0).getEnvelope(crs));
- if(result.getCoordinateReferenceSystem() instanceof GeographicCRS && flipGeographic) {
+ if(result.getCoordinateReferenceSystem() instanceof GeographicCRS && axisFlipped) {
result = flipEnvelope(result);
}
for (int i = 1; i < layers.size(); i++) {
ReferencedEnvelope layerEnvelope = reference(layers.get(i).getEnvelope(crs));
- if(layerEnvelope.getCoordinateReferenceSystem() instanceof GeographicCRS && flipGeographic) {
+ if(layerEnvelope.getCoordinateReferenceSystem() instanceof GeographicCRS && axisFlipped) {
layerEnvelope = flipEnvelope(layerEnvelope);
}
result.expandToInclude(layerEnvelope);
@@ -462,4 +478,5 @@
return new ReferencedEnvelope(ge.getMinimum(0), ge.getMaximum(0), ge.getMinimum(1), ge
.getMaximum(1), ge.getCoordinateReferenceSystem());
}
+
}
\ No newline at end of file
Added: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/ows/MockHttpClient.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/ows/MockHttpClient.java (rev 0)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/ows/MockHttpClient.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -0,0 +1,74 @@
+package org.geotools.data.ows;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.geotools.data.ows.HTTPClient;
+import org.geotools.data.ows.HTTPResponse;
+
+/**
+ * Helper class to test WMS cascading
+ *
+ * @author Andrea Aime - GeoSolutions
+ */
+public abstract class MockHttpClient implements HTTPClient {
+
+ protected String user;
+
+ protected String password;
+
+ protected int connectTimeout;
+
+ protected int readTimeout;
+
+ public HTTPResponse post(URL url, InputStream postContent, String postContentType)
+ throws IOException {
+ throw new UnsupportedOperationException(
+ "POST not supported, if needed you have to override and implement");
+ }
+
+ public HTTPResponse get(URL url) throws IOException {
+ throw new UnsupportedOperationException(
+ "GET not supported, if needed you have to override and implement");
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getPassword() {
+ return this.password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+
+ }
+
+
+ public int getConnectTimeout() {
+ return connectTimeout;
+ }
+
+
+ public void setConnectTimeout(int connectTimeout) {
+ this.connectTimeout = connectTimeout;
+
+ }
+
+
+ public int getReadTimeout() {
+ return this.readTimeout;
+ }
+
+
+ public void setReadTimeout(int readTimeout) {
+ this.readTimeout = readTimeout;
+ }
+
+}
\ No newline at end of file
Added: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/ows/MockHttpResponse.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/ows/MockHttpResponse.java (rev 0)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/ows/MockHttpResponse.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -0,0 +1,74 @@
+package org.geotools.data.ows;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.geotools.data.ows.HTTPResponse;
+
+/**
+ * Helper class to mock HTTP responses
+ *
+ * @author Andrea Aime - GeoSolutions
+ */
+public class MockHttpResponse implements HTTPResponse {
+
+ String contentType;
+
+ Map<String, String> headers;
+
+ byte[] response;
+
+ public MockHttpResponse(String response, String contentType, String... headers) {
+ this(response.getBytes(), contentType, headers);
+ }
+
+ public MockHttpResponse(URL response, String contentType, String... headers) throws IOException {
+ this(IOUtils.toByteArray(response.openStream()), contentType, headers);
+ }
+
+ public MockHttpResponse(byte[] response, String contentType, String... headers) {
+ this.response = response;
+ this.contentType = contentType;
+ this.headers = new HashMap<String, String>();
+
+ if (headers != null) {
+ if (headers.length % 2 != 0) {
+ throw new IllegalArgumentException(
+ "The headers must be a alternated sequence of keys "
+ + "and values, should have an even number of entries");
+ }
+
+ for (int i = 0; i < headers.length; i += 2) {
+ String key = headers[i];
+ String value = headers[i++];
+ this.headers.put(key, value);
+ }
+ }
+ }
+
+
+ public void dispose() {
+ // nothing to do
+ }
+
+
+ public String getContentType() {
+ return this.contentType;
+ }
+
+
+ public String getResponseHeader(String headerName) {
+ return headers.get(headerName);
+ }
+
+
+ public InputStream getResponseStream() throws IOException {
+ return new ByteArrayInputStream(response);
+ }
+
+}
Modified: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/WMSUtilsTest.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/WMSUtilsTest.java 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/WMSUtilsTest.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -76,7 +76,7 @@
public void testMatchEPSG() throws Exception {
CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326");
CoordinateReferenceSystem crs3005 = CRS.decode("EPSG:3005");
- CoordinateReferenceSystem crs42101 = CRS.decode("EPSG:42101");
+ CoordinateReferenceSystem crs3347 = CRS.decode("EPSG:3347");
Set codes = new TreeSet();
codes.add("EPSG:4326");
@@ -95,7 +95,7 @@
assertNotNull(result2);
assertEquals("EPSG:42102", result2);
- String result3 = WMSUtils.matchEPSG(crs42101, codes);
+ String result3 = WMSUtils.matchEPSG(crs3347, codes);
assertNull(result3);
}
Modified: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/Geot553Test.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/Geot553Test.java 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/Geot553Test.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -16,14 +16,22 @@
*/
package org.geotools.data.wms.test;
+import static org.junit.Assert.*;
+
import java.io.File;
+import java.io.IOException;
import java.net.URL;
+import java.util.Map;
import junit.framework.TestCase;
+import org.geotools.data.ows.HTTPResponse;
import org.geotools.data.ows.Layer;
+import org.geotools.data.ows.MockHttpClient;
+import org.geotools.data.ows.MockHttpResponse;
import org.geotools.data.wms.WebMapServer;
import org.geotools.geometry.GeneralDirectPosition;
+import org.geotools.map.WMSCoverageReaderTest;
import org.geotools.referencing.CRS;
import org.geotools.test.TestData;
import org.opengis.geometry.DirectPosition;
@@ -49,18 +57,23 @@
CoordinateReferenceSystem epsg26591 = CRS.decode("EPSG:26591");
CoordinateReferenceSystem epsg4326 = CRS.decode("EPSG:4326");
- MathTransform transform = CRS.findMathTransform(epsg26591, epsg4326, true);
- DirectPosition min = transform.transform(new GeneralDirectPosition(minx, miny), null);
- DirectPosition max = transform.transform(new GeneralDirectPosition(maxx, maxy), null);
- System.out.println(min);
- System.out.println(max);
-
-
- File getCaps = TestData.file(this, "geot553capabilities.xml");
-
- URL getCapsURL = TestData.getResource(this, "geot553capabilities.xml");
+ // prepare the responses
+ MockHttpClient client = new MockHttpClient() {
+
+ public HTTPResponse get(URL url) throws IOException {
+ if (url.getQuery().contains("GetCapabilities")) {
+ URL caps = TestData.getResource(this, "geot553capabilities.xml");
+ return new MockHttpResponse(caps, "text/xml");
+ } else {
+ throw new IllegalArgumentException(
+ "Don't know how to handle a get request over " + url.toExternalForm());
+ }
+ }
+
+ };
- WebMapServer wms = new WebMapServer(getCapsURL);
+
+ WebMapServer wms = new WebMapServer(new URL("http://test.org"), client);
Layer layer = wms.getCapabilities().getLayer().getChildren()[2];
Envelope env = wms.getEnvelope(layer, CRS.decode("EPSG:3005"));
Modified: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/LocalGeoServerOnlineTest.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/LocalGeoServerOnlineTest.java 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/LocalGeoServerOnlineTest.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -43,7 +43,7 @@
static private URL serverURL;
static {
try {
- serverURL = new URL("http://127.0.0.1:8080/geoserver/wms?SERVICE=WMS&");
+ serverURL = new URL("http://127.0.0.1:8080/geoserver/ows?SERVICE=WMS&");
} catch (MalformedURLException e) {
serverURL = null;
};
@@ -101,7 +101,7 @@
assertNotNull( info );
assertEquals( serverURL, wms.getCapabilities().getRequest().getGetCapabilities().getGet() );
- assertEquals( "My GeoServer WMS", info.getTitle() );
+ assertEquals( "GeoServer Web Map Service", info.getTitle() );
assertNotNull( info.getDescription() );
}
Modified: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WMS1_0_0_OnlineTest.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WMS1_0_0_OnlineTest.java 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WMS1_0_0_OnlineTest.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -161,7 +161,7 @@
request.setFormat("image/jpeg");
System.out.println(request.getFinalURL().toExternalForm());
- assertTrue(request.getFinalURL().toExternalForm().indexOf("JPEG") >= 0);
+ assertTrue(request.getFinalURL().toExternalForm().indexOf("jpeg") >= 0);
} catch(java.net.ConnectException ce){
if(ce.getMessage().indexOf("timed out")>0){
System.err.println("Unable to test - timed out: "+ce);
Modified: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WMS1_1_0_OnlineTest.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WMS1_1_0_OnlineTest.java 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WMS1_1_0_OnlineTest.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -262,7 +262,8 @@
request.setFormat("image/jpeg");
//System.out.println(request.getFinalURL().toExternalForm());
- assertTrue(request.getFinalURL().toExternalForm().indexOf("image/jpeg") >= 0);
+ String externalForm = request.getFinalURL().toExternalForm();
+ assertTrue(externalForm.indexOf("image%2Fjpeg") >= 0);
} catch(java.net.ConnectException ce){
if(ce.getMessage().indexOf("timed out")>0){
System.err.println("Unable to test - timed out: "+ce);
Modified: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WebMapServerOnlineTest.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WebMapServerOnlineTest.java 2011-12-19 17:30:08 UTC (rev 38434)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/data/wms/test/WebMapServerOnlineTest.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -203,7 +203,7 @@
WMSCapabilities caps = wms.getCapabilities();
- Layer layer = (Layer) caps.getLayerList().get(1);
+ Layer layer = (Layer) caps.getLayerList().get(0);
CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
GeneralEnvelope envelope = wms.getEnvelope(layer, crs);
Added: branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/map/WMSCoverageReaderTest.java
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/map/WMSCoverageReaderTest.java (rev 0)
+++ branches/2.7.x/modules/extension/wms/src/test/java/org/geotools/map/WMSCoverageReaderTest.java 2011-12-20 08:11:41 UTC (rev 38435)
@@ -0,0 +1,132 @@
+package org.geotools.map;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.util.ParameterParser;
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.coverage.grid.GridEnvelope2D;
+import org.geotools.coverage.grid.GridGeometry2D;
+import org.geotools.coverage.grid.io.AbstractGridFormat;
+import org.geotools.data.ows.HTTPResponse;
+import org.geotools.data.ows.Layer;
+import org.geotools.data.ows.MockHttpClient;
+import org.geotools.data.ows.MockHttpResponse;
+import org.geotools.data.wms.WebMapServer;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.parameter.Parameter;
+import org.geotools.referencing.CRS;
+import org.junit.Test;
+import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+public class WMSCoverageReaderTest {
+
+ Map<String, String> parseParams(String query) {
+ ParameterParser pp = new ParameterParser();
+ List params = pp.parse(query, '&');
+ Map<String, String> result = new HashMap<String, String>();
+ for (Iterator it = params.iterator(); it.hasNext();) {
+ NameValuePair pair = (NameValuePair) it.next();
+ result.put(pair.getName().toUpperCase(), pair.getValue());
+ }
+ return result;
+ };
+
+ @Test
+ public void test4326wms13() throws Exception {
+ // prepare the responses
+ MockHttpClient client = new MockHttpClient() {
+
+ public HTTPResponse get(URL url) throws IOException {
+ if (url.getQuery().contains("GetCapabilities")) {
+ URL caps130 = WMSCoverageReaderTest.class.getResource("caps130.xml");
+ return new MockHttpResponse(caps130, "text/xml");
+ } else if (url.getQuery().contains("GetMap")
+ && url.getQuery().contains("world4326")) {
+ Map<String, String> params = parseParams(url.getQuery());
+ assertEquals("1.3.0", params.get("VERSION"));
+ assertEquals("-90.0,-180.0,90.0,180.0", params.get("BBOX"));
+ assertEquals("EPSG:4326", params.get("CRS"));
+ URL world = WMSCoverageReaderTest.class.getResource("world.png");
+ return new MockHttpResponse(world, "image/png");
+ } else {
+ throw new IllegalArgumentException(
+ "Don't know how to handle a get request over " + url.toExternalForm());
+ }
+ }
+
+ };
+ // setup the reader
+ WebMapServer server = new WebMapServer(new URL("http://geoserver.org/geoserver/wms"),
+ client);
+ WMSCoverageReader reader = new WMSCoverageReader(server, getLayer(server, "world4326"));
+
+ // build a getmap request and check it
+ CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true);
+ ReferencedEnvelope worldEnvelope = new ReferencedEnvelope(-180, 180, -90, 90, wgs84);
+ GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 180, 90), worldEnvelope);
+ final Parameter<GridGeometry2D> ggParam = (Parameter<GridGeometry2D>) AbstractGridFormat.READ_GRIDGEOMETRY2D
+ .createValue();
+ ggParam.setValue(gg);
+ GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggParam });
+ assertTrue(CRS.equalsIgnoreMetadata(wgs84, coverage.getCoordinateReferenceSystem()));
+ assertEquals(worldEnvelope, new ReferencedEnvelope(coverage.getEnvelope()));
+ }
+
+ @Test
+ public void testCrs84wms13() throws Exception {
+ // prepare the responses
+ MockHttpClient client = new MockHttpClient() {
+
+ public HTTPResponse get(URL url) throws IOException {
+ if (url.getQuery().contains("GetCapabilities")) {
+ URL caps130 = WMSCoverageReaderTest.class.getResource("caps130_crs84.xml");
+ return new MockHttpResponse(caps130, "text/xml");
+ } else if (url.getQuery().contains("GetMap") && url.getQuery().contains("world84")) {
+ Map<String, String> params = parseParams(url.getQuery());
+ assertEquals("1.3.0", params.get("VERSION"));
+ assertEquals("CRS:84", params.get("CRS"));
+ assertEquals("-180.0,-90.0,180.0,90.0", params.get("BBOX"));
+ URL world = WMSCoverageReaderTest.class.getResource("world.png");
+ return new MockHttpResponse(world, "image/png");
+ } else {
+ throw new IllegalArgumentException(
+ "Don't know how to handle a get request over " + url.toExternalForm());
+ }
+ }
+
+ };
+ WebMapServer server = new WebMapServer(new URL("http://geoserver.org/geoserver/wms"),
+ client);
+ WMSCoverageReader reader = new WMSCoverageReader(server, getLayer(server, "world84"));
+
+ // setup the request and check it
+ CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true);
+ ReferencedEnvelope worldEnvelope = new ReferencedEnvelope(-180, 180, -90, 90, wgs84);
+ GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 180, 90), worldEnvelope);
+ final Parameter<GridGeometry2D> ggParam = (Parameter<GridGeometry2D>) AbstractGridFormat.READ_GRIDGEOMETRY2D
+ .createValue();
+ ggParam.setValue(gg);
+
+ GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggParam });
+ assertTrue(CRS.equalsIgnoreMetadata(wgs84, coverage.getCoordinateReferenceSystem()));
+ assertEquals(worldEnvelope, new ReferencedEnvelope(coverage.getEnvelope()));
+ }
+
+ private Layer getLayer(WebMapServer server, String layerName) {
+ for (Layer layer : server.getCapabilities().getLayerList()) {
+ if (layerName.equals(layer.getName())) {
+ return layer;
+ }
+ }
+ throw new IllegalArgumentException("Could not find layer " + layerName);
+ }
+}
Added: branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/caps130.xml
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/caps130.xml (rev 0)
+++ branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/caps130.xml 2011-12-20 08:11:41 UTC (rev 38435)
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<WMS_Capabilities version="1.3.0" updateSequence="1159"
+ xmlns="http://www.opengis.net/wms" xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd">
+ <Service>
+ <Name>WMS</Name>
+ <Title>WMS</Title>
+ <Abstract>Minimal test caps document for a WMS 1.3 server</Abstract>
+ <KeywordList>
+ <Keyword>GEOSERVER</Keyword>
+ </KeywordList>
+ <OnlineResource xlink:type="simple" xlink:href="http://www.geoserver.org" />
+ </Service>
+ <Capability>
+ <Request>
+ <GetCapabilities>
+ <Format>text/xml</Format>
+ <DCPType>
+ <HTTP>
+ <Get>
+ <OnlineResource xlink:type="simple"
+ xlink:href="http://geoserver.org/geoserver/ows?SERVICE=WMS&" />
+ </Get>
+ </HTTP>
+ </DCPType>
+ </GetCapabilities>
+ <GetMap>
+ <Format>image/png</Format>
+ <DCPType>
+ <HTTP>
+ <Get>
+ <OnlineResource xlink:type="simple"
+ xlink:href="http://geoserver.org/geoserver/ows?SERVICE=WMS&" />
+ </Get>
+ </HTTP>
+ </DCPType>
+ </GetMap>
+ <GetFeatureInfo>
+ <Format>text/plain</Format>
+ <Format>application/vnd.ogc.gml</Format>
+ <Format>application/vnd.ogc.gml/3.1.1</Format>
+ <Format>text/html</Format>
+ <DCPType>
+ <HTTP>
+ <Get>
+ <OnlineResource xlink:type="simple"
+ xlink:href="http://geoserver.org/geoserver/ows?SERVICE=WMS&" />
+ </Get>
+ </HTTP>
+ </DCPType>
+ </GetFeatureInfo>
+ </Request>
+ <Exception>
+ <Format>XML</Format>
+ <Format>INIMAGE</Format>
+ <Format>BLANK</Format>
+ </Exception>
+ <Layer>
+ <Title>Root</Title>
+ <!--Limited list of EPSG projections: -->
+ <CRS>EPSG:4326</CRS>
+ <CRS>CRS:84</CRS>
+ <EX_GeographicBoundingBox>
+ <westBoundLongitude>-180</westBoundLongitude>
+ <eastBoundLongitude>180</eastBoundLongitude>
+ <southBoundLatitude>-90</southBoundLatitude>
+ <northBoundLatitude>90</northBoundLatitude>
+ </EX_GeographicBoundingBox>
+ <Layer queryable="1">
+ <Name>world4326</Name>
+ <Title>world4326</Title>
+ <CRS>EPSG:4326</CRS>
+ <CRS>CRS:84</CRS>
+ <EX_GeographicBoundingBox>
+ <westBoundLongitude>-180</westBoundLongitude>
+ <eastBoundLongitude>180</eastBoundLongitude>
+ <southBoundLatitude>-90</southBoundLatitude>
+ <northBoundLatitude>90</northBoundLatitude>
+ </EX_GeographicBoundingBox>
+ <BoundingBox CRS="EPSG:4326" minx="-90" miny="-180"
+ maxx="90" maxy="180" />
+ </Layer>
+ </Layer>
+ </Capability>
+</WMS_Capabilities>
Added: branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/caps130_crs84.xml
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/caps130_crs84.xml (rev 0)
+++ branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/caps130_crs84.xml 2011-12-20 08:11:41 UTC (rev 38435)
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<WMS_Capabilities version="1.3.0" updateSequence="1159"
+ xmlns="http://www.opengis.net/wms" xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd">
+ <Service>
+ <Name>WMS</Name>
+ <Title>WMS</Title>
+ <Abstract>Minimal test caps document for a WMS 1.3 server</Abstract>
+ <KeywordList>
+ <Keyword>GEOSERVER</Keyword>
+ </KeywordList>
+ <OnlineResource xlink:type="simple" xlink:href="http://www.geoserver.org" />
+ </Service>
+ <Capability>
+ <Request>
+ <GetCapabilities>
+ <Format>text/xml</Format>
+ <DCPType>
+ <HTTP>
+ <Get>
+ <OnlineResource xlink:type="simple"
+ xlink:href="http://geoserver.org/geoserver/ows?SERVICE=WMS&" />
+ </Get>
+ </HTTP>
+ </DCPType>
+ </GetCapabilities>
+ <GetMap>
+ <Format>image/png</Format>
+ <DCPType>
+ <HTTP>
+ <Get>
+ <OnlineResource xlink:type="simple"
+ xlink:href="http://geoserver.org/geoserver/ows?SERVICE=WMS&" />
+ </Get>
+ </HTTP>
+ </DCPType>
+ </GetMap>
+ <GetFeatureInfo>
+ <Format>text/plain</Format>
+ <Format>application/vnd.ogc.gml</Format>
+ <Format>application/vnd.ogc.gml/3.1.1</Format>
+ <Format>text/html</Format>
+ <DCPType>
+ <HTTP>
+ <Get>
+ <OnlineResource xlink:type="simple"
+ xlink:href="http://geoserver.org/geoserver/ows?SERVICE=WMS&" />
+ </Get>
+ </HTTP>
+ </DCPType>
+ </GetFeatureInfo>
+ </Request>
+ <Exception>
+ <Format>XML</Format>
+ <Format>INIMAGE</Format>
+ <Format>BLANK</Format>
+ </Exception>
+ <Layer>
+ <Title>Root</Title>
+ <CRS>CRS:84</CRS>
+ <EX_GeographicBoundingBox>
+ <westBoundLongitude>-180</westBoundLongitude>
+ <eastBoundLongitude>180</eastBoundLongitude>
+ <southBoundLatitude>-90</southBoundLatitude>
+ <northBoundLatitude>90</northBoundLatitude>
+ </EX_GeographicBoundingBox>
+ <Layer queryable="1">
+ <Name>world84</Name>
+ <Title>world84</Title>
+ <CRS>CRS:84</CRS>
+ <EX_GeographicBoundingBox>
+ <westBoundLongitude>-180</westBoundLongitude>
+ <eastBoundLongitude>180</eastBoundLongitude>
+ <southBoundLatitude>-90</southBoundLatitude>
+ <northBoundLatitude>90</northBoundLatitude>
+ </EX_GeographicBoundingBox>
+ <BoundingBox CRS="CRS:84" minx="-180" miny="-90"
+ maxx="180" maxy="90" />
+ </Layer>
+ </Layer>
+ </Capability>
+</WMS_Capabilities>
Added: branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/world.png
===================================================================
--- branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/world.png (rev 0)
+++ branches/2.7.x/modules/extension/wms/src/test/resources/org/geotools/map/world.png 2011-12-20 08:11:41 UTC (rev 38435)
@@ -0,0 +1,52 @@
+PNG
+
+ |