Commit c369e43e authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-4762] WCS should force usage of imageread

parent 206fa3c2
...@@ -8,6 +8,7 @@ package org.geoserver.test; ...@@ -8,6 +8,7 @@ package org.geoserver.test;
import static junit.framework.Assert.*; import static junit.framework.Assert.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -49,9 +50,6 @@ import javax.xml.validation.Schema; ...@@ -49,9 +50,6 @@ import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory; import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator; import javax.xml.validation.Validator;
import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.geoserver.catalog.CascadeDeleteVisitor; import org.geoserver.catalog.CascadeDeleteVisitor;
import org.geoserver.catalog.Catalog; import org.geoserver.catalog.Catalog;
...@@ -121,6 +119,9 @@ import com.mockrunner.mock.web.MockServletConfig; ...@@ -121,6 +119,9 @@ import com.mockrunner.mock.web.MockServletConfig;
import com.mockrunner.mock.web.MockServletContext; import com.mockrunner.mock.web.MockServletContext;
import com.mockrunner.mock.web.MockServletOutputStream; import com.mockrunner.mock.web.MockServletOutputStream;
import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
/** /**
* Base test class for GeoServer system tests that require a fully configured spring context and * Base test class for GeoServer system tests that require a fully configured spring context and
* work off a real data directory provided by {@link SystemTestData}. * work off a real data directory provided by {@link SystemTestData}.
...@@ -1847,6 +1848,19 @@ public class GeoServerSystemTestSupport extends GeoServerBaseTestSupport<SystemT ...@@ -1847,6 +1848,19 @@ public class GeoServerSystemTestSupport extends GeoServerBaseTestSupport<SystemT
} }
/**
* Checks the image and its sources are all deferred loaded, that is, there is no BufferedImage in the chain
* @param image
*/
protected void assertDeferredLoading(RenderedImage image) {
if(image instanceof BufferedImage) {
fail("Found a buffered image in the chain, the original image is not fully deferred loaded");
} else {
for (RenderedImage ri : image.getSources()) {
assertDeferredLoading(ri);
}
}
}
public static class GeoServerMockHttpServletRequest extends MockHttpServletRequest { public static class GeoServerMockHttpServletRequest extends MockHttpServletRequest {
private byte[] myBody; private byte[] myBody;
......
...@@ -475,7 +475,7 @@ public class DefaultWebCoverageService100 implements WebCoverageService100 { ...@@ -475,7 +475,7 @@ public class DefaultWebCoverageService100 implements WebCoverageService100 {
// make sure we work in streaming mode // make sure we work in streaming mode
// //
// work in streaming fashion when JAI is involved // work in streaming fashion when JAI is involved
readParameters = WCSUtils.replaceParameter(readParameters, Boolean.FALSE, readParameters = WCSUtils.replaceParameter(readParameters, Boolean.TRUE,
AbstractGridFormat.USE_JAI_IMAGEREAD); AbstractGridFormat.USE_JAI_IMAGEREAD);
// //
......
...@@ -77,6 +77,8 @@ public class GetCoverageTest extends WCSTestSupport { ...@@ -77,6 +77,8 @@ public class GetCoverageTest extends WCSTestSupport {
private Catalog catalog; private Catalog catalog;
private static final QName MOSAIC = new QName(MockData.SF_URI, "rasterFilter", MockData.SF_PREFIX); private static final QName MOSAIC = new QName(MockData.SF_URI, "rasterFilter", MockData.SF_PREFIX);
private static final QName SPATIO_TEMPORAL = new QName(MockData.SF_URI, "spatio-temporal", MockData.SF_PREFIX);
@Before @Before
public void setUp() { public void setUp() {
...@@ -92,6 +94,7 @@ public class GetCoverageTest extends WCSTestSupport { ...@@ -92,6 +94,7 @@ public class GetCoverageTest extends WCSTestSupport {
protected void onSetUp(SystemTestData testData) throws Exception { protected void onSetUp(SystemTestData testData) throws Exception {
super.onSetUp(testData); super.onSetUp(testData);
testData.addRasterLayer(MOSAIC, "raster-filter-test.zip", null, getCatalog()); testData.addRasterLayer(MOSAIC, "raster-filter-test.zip", null, getCatalog());
testData.addRasterLayer(SPATIO_TEMPORAL, "spatio-temporal.zip", null, null, SystemTestData.class, getCatalog());
// enable dimensions on the water temperature layer // enable dimensions on the water temperature layer
setupRasterDimension(WATTEMP, ResourceInfo.TIME, DimensionPresentation.LIST, null); setupRasterDimension(WATTEMP, ResourceInfo.TIME, DimensionPresentation.LIST, null);
setupRasterDimension(WATTEMP, ResourceInfo.ELEVATION, DimensionPresentation.LIST, null); setupRasterDimension(WATTEMP, ResourceInfo.ELEVATION, DimensionPresentation.LIST, null);
...@@ -154,6 +157,23 @@ public class GetCoverageTest extends WCSTestSupport { ...@@ -154,6 +157,23 @@ public class GetCoverageTest extends WCSTestSupport {
CoverageCleanerCallback.disposeCoverage(coverages[0]); CoverageCleanerCallback.disposeCoverage(coverages[0]);
} }
@Test
public void testDeferredLoading() throws Exception {
Map<String, Object> raw = baseMap();
final String getLayerId = getLayerId(SPATIO_TEMPORAL);
raw.put("sourcecoverage", getLayerId);
raw.put("format", "image/tiff");
raw.put("BBox", "-90,-180,90,180");
raw.put("crs", "EPSG:4326");
raw.put("resx", "0.001");
raw.put("resy", "0.001");
GridCoverage[] coverages = executeGetCoverageKvp(raw);
assertEquals(1, coverages.length);
assertDeferredLoading(coverages[0].getRenderedImage());
}
@Test @Test
public void testWorkspaceQualified() throws Exception { public void testWorkspaceQualified() throws Exception {
String queryString ="&request=getcoverage&service=wcs&version=1.0.0&format=image/geotiff&bbox=146,-45,147,-42"+ String queryString ="&request=getcoverage&service=wcs&version=1.0.0&format=image/geotiff&bbox=146,-45,147,-42"+
......
...@@ -349,7 +349,7 @@ public class DefaultWebCoverageService111 implements WebCoverageService111 { ...@@ -349,7 +349,7 @@ public class DefaultWebCoverageService111 implements WebCoverageService111 {
// make sure we work in streaming mode // make sure we work in streaming mode
// //
// work in streaming fashion when JAI is involved // work in streaming fashion when JAI is involved
readParameters = WCSUtils.replaceParameter(readParameters, Boolean.FALSE, readParameters = WCSUtils.replaceParameter(readParameters, Boolean.TRUE,
AbstractGridFormat.USE_JAI_IMAGEREAD); AbstractGridFormat.USE_JAI_IMAGEREAD);
// //
......
...@@ -53,13 +53,15 @@ public class GetCoverageTest extends AbstractGetCoverageTest { ...@@ -53,13 +53,15 @@ public class GetCoverageTest extends AbstractGetCoverageTest {
MockData.SF_PREFIX); MockData.SF_PREFIX);
private static final QName RAIN = new QName(MockData.SF_URI, "rain", MockData.SF_PREFIX); private static final QName RAIN = new QName(MockData.SF_URI, "rain", MockData.SF_PREFIX);
private static final QName SPATIO_TEMPORAL = new QName(MockData.SF_URI, "spatio-temporal", MockData.SF_PREFIX);
@Override @Override
protected void onSetUp(SystemTestData testData) throws Exception { protected void onSetUp(SystemTestData testData) throws Exception {
super.onSetUp(testData); super.onSetUp(testData);
testData.addRasterLayer(MOSAIC, "raster-filter-test.zip", null, getCatalog()); testData.addRasterLayer(MOSAIC, "raster-filter-test.zip", null, getCatalog());
testData.addRasterLayer(RAIN, "rain.zip", "asc", getCatalog()); testData.addRasterLayer(RAIN, "rain.zip", "asc", getCatalog());
testData.addRasterLayer(SPATIO_TEMPORAL, "spatio-temporal.zip", null, null, SystemTestData.class, getCatalog());
} }
@Test @Test
...@@ -607,6 +609,21 @@ public class GetCoverageTest extends AbstractGetCoverageTest { ...@@ -607,6 +609,21 @@ public class GetCoverageTest extends AbstractGetCoverageTest {
public void testEmptyInterpolation() throws Exception { public void testEmptyInterpolation() throws Exception {
this.testInterpolationMethods(""); this.testInterpolationMethods("");
} }
@Test
public void testDeferredLoading() throws Exception {
Map<String, Object> raw = baseMap();
final String getLayerId = getLayerId(SPATIO_TEMPORAL);
raw.put("identifier", getLayerId);
raw.put("format", "image/tiff");
raw.put("BoundingBox", "-90,-180,90,180,urn:ogc:def:crs:EPSG:6.6:4326");
raw.put("store", "false");
raw.put("GridBaseCRS", "urn:ogc:def:crs:EPSG:6.6:4326");
GridCoverage[] coverages = executeGetCoverageKvp(raw);
assertEquals(1, coverages.length);
assertDeferredLoading(coverages[0].getRenderedImage());
}
private void testInterpolationMethods(String method) throws Exception { private void testInterpolationMethods(String method) throws Exception {
String queryString = "wcs?identifier=" + getLayerId(MOSAIC) + "&request=getcoverage" String queryString = "wcs?identifier=" + getLayerId(MOSAIC) + "&request=getcoverage"
......
...@@ -838,9 +838,7 @@ public class GetCoverage { ...@@ -838,9 +838,7 @@ public class GetCoverage {
GeneralParameterValue[] readParameters = CoverageUtils.getParameters(readParametersDescriptor, cinfo.getParameters()); GeneralParameterValue[] readParameters = CoverageUtils.getParameters(readParametersDescriptor, cinfo.getParameters());
readParameters = (readParameters != null ? readParameters : new GeneralParameterValue[0]); readParameters = (readParameters != null ? readParameters : new GeneralParameterValue[0]);
// work in streaming fashion when JAI is involved // work in streaming fashion when JAI is involved
readParameters = WCSUtils.replaceParameter( readParameters = WCSUtils.replaceParameter(readParameters, Boolean.TRUE,
readParameters,
Boolean.FALSE,
AbstractGridFormat.USE_JAI_IMAGEREAD); AbstractGridFormat.USE_JAI_IMAGEREAD);
// handle "time" // handle "time"
......
...@@ -20,7 +20,9 @@ import org.geoserver.catalog.ResourceInfo; ...@@ -20,7 +20,9 @@ import org.geoserver.catalog.ResourceInfo;
import org.geoserver.config.GeoServerDataDirectory; import org.geoserver.config.GeoServerDataDirectory;
import org.geoserver.data.test.MockData; import org.geoserver.data.test.MockData;
import org.geoserver.data.test.SystemTestData; import org.geoserver.data.test.SystemTestData;
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.platform.resource.Resource; import org.geoserver.platform.resource.Resource;
import org.geoserver.wcs2_0.DefaultWebCoverageService20;
import org.geoserver.wcs2_0.GetCoverage; import org.geoserver.wcs2_0.GetCoverage;
import org.geoserver.wcs2_0.WCSTestSupport; import org.geoserver.wcs2_0.WCSTestSupport;
import org.geoserver.wcs2_0.exception.WCS20Exception; import org.geoserver.wcs2_0.exception.WCS20Exception;
...@@ -35,12 +37,16 @@ import org.geotools.referencing.CRS; ...@@ -35,12 +37,16 @@ import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS; import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.opengis.coverage.grid.GridCoverage;
import org.opengis.coverage.grid.GridEnvelope; import org.opengis.coverage.grid.GridEnvelope;
import org.opengis.referencing.FactoryException; import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException; import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import com.mockrunner.mock.web.MockHttpServletResponse; import com.mockrunner.mock.web.MockHttpServletResponse;
import net.opengis.wcs20.GetCoverageType;
import net.opengis.wcs20.Wcs20Factory;
/** /**
* Testing WCS 2.0 Core {@link GetCoverage} * Testing WCS 2.0 Core {@link GetCoverage}
* *
...@@ -55,6 +61,8 @@ public class GetCoverageTest extends WCSTestSupport { ...@@ -55,6 +61,8 @@ public class GetCoverageTest extends WCSTestSupport {
protected static QName TIMERANGES = new QName(MockData.SF_URI, "timeranges", MockData.SF_PREFIX); protected static QName TIMERANGES = new QName(MockData.SF_URI, "timeranges", MockData.SF_PREFIX);
private static final QName RAIN = new QName(MockData.SF_URI, "rain", MockData.SF_PREFIX); private static final QName RAIN = new QName(MockData.SF_URI, "rain", MockData.SF_PREFIX);
private static final QName SPATIO_TEMPORAL = new QName(MockData.SF_URI, "spatio-temporal", MockData.SF_PREFIX);
@Before @Before
public void clearDimensions() { public void clearDimensions() {
...@@ -82,6 +90,7 @@ public class GetCoverageTest extends WCSTestSupport { ...@@ -82,6 +90,7 @@ public class GetCoverageTest extends WCSTestSupport {
testData.addRasterLayer(RAIN, "rain.zip", "asc", getCatalog()); testData.addRasterLayer(RAIN, "rain.zip", "asc", getCatalog());
testData.addRasterLayer(TIMERANGES, "timeranges.zip", null, null, SystemTestData.class, getCatalog()); testData.addRasterLayer(TIMERANGES, "timeranges.zip", null, null, SystemTestData.class, getCatalog());
testData.addRasterLayer(SPATIO_TEMPORAL, "spatio-temporal.zip", null, null, SystemTestData.class, getCatalog());
sortByElevation(TIMERANGES); sortByElevation(TIMERANGES);
} }
...@@ -827,4 +836,22 @@ public class GetCoverageTest extends WCSTestSupport { ...@@ -827,4 +836,22 @@ public class GetCoverageTest extends WCSTestSupport {
scheduleForCleaning(targetCoverage); scheduleForCleaning(targetCoverage);
} }
} }
@Test
public void testDeferredLoading() throws Exception {
DefaultWebCoverageService20 wcs = GeoServerExtensions.bean(DefaultWebCoverageService20.class);
GetCoverageType getCoverage = Wcs20Factory.eINSTANCE.createGetCoverageType();
getCoverage.setCoverageId(getLayerId(SPATIO_TEMPORAL));
getCoverage.setVersion("2.0.0");
getCoverage.setService("WCS");
GridCoverage coverage = null;
try {
coverage = wcs.getCoverage(getCoverage);
assertNotNull(coverage);
assertDeferredLoading(coverage.getRenderedImage());
} finally {
scheduleForCleaning(coverage);
}
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment