Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade GeoServer, decrease max distance from 1 to 0 #3136

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@

**/actual*.png
**/diff*.png

/examples/geoserver-data/logs/
/examples/geoserver-data/gwc-gs.xml
/examples/geoserver-data/gwc-layers/
/examples/geoserver-data/security/geoserver.jceks
/examples/geoserver-data/security/version.properties
/examples/geoserver-data/workspaces/default.xml
13 changes: 4 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
GIT_HEAD_ARG = --build-arg=GIT_HEAD=$(shell git rev-parse HEAD)
export DOCKER_BUILDKIT = 1

.PHONY: clean
clean:
rm -rf .env examples/geoserver-data/logs/

.PHONY: build
build: build-builder
docker build $(GIT_HEAD_ARG) --target=runner --tag=camptocamp/mapfish_print core
Expand Down Expand Up @@ -44,15 +48,6 @@ tests: build-builder

.PHONY: acceptance-tests-up
acceptance-tests-up: build .env
docker-compose down --remove-orphan

mkdir /tmp/geoserver-data || true
docker run --rm --volume=/tmp/geoserver-data:/mnt/geoserver_datadir camptocamp/geoserver \
bash -c 'rm -rf /mnt/geoserver_datadir/*'
mkdir /tmp/geoserver-data/www
cp -r examples/geoserver-data/* /tmp/geoserver-data/
cp -r core/src/test/resources/map-data/* /tmp/geoserver-data/www/

# Required to avoid root ownership of reports folder
mkdir -p examples/build/reports/ || true
docker-compose up --detach
Expand Down
55 changes: 39 additions & 16 deletions core/src/main/java/org/mapfish/print/map/image/ImageLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.mapfish.print.map.geotools.StyleSupplier;
import org.mapfish.print.parser.HasDefaultValue;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
Expand All @@ -50,11 +52,14 @@
*/
public final class ImageLayer extends AbstractSingleImageLayer {
private final ImageParam params;
private final boolean failOnError;
private final StyleSupplier<GridCoverage2D> styleSupplier;
private final ExecutorService executorService;
private final RenderType renderType;
private double imageBufferScaling;
private BufferedImage image;
private boolean imageLoadError = false;
private static final Logger LOGGER = LoggerFactory.getLogger(ImageLayer.class);

/**
* Constructor.
Expand All @@ -73,6 +78,8 @@ protected ImageLayer(
@Nonnull final MetricRegistry registry) {
super(executorService, styleSupplier, params, registry, configuration);
this.params = params;
this.failOnError = params.failOnError;
params.failOnError = true;
this.styleSupplier = styleSupplier;
this.executorService = executorService;
this.renderType = RenderType.fromMimeType(params.imageFormat);
Expand All @@ -83,7 +90,12 @@ protected BufferedImage loadImage(
final MfClientHttpRequestFactory requestFactory, final MapfishMapContext transformer) {
final ReferencedEnvelope envelopeOrig =
transformer.getBounds().toReferencedEnvelope(transformer.getPaintArea());
final Rectangle paintArea = calculateNewBounds(image, envelopeOrig);
final Rectangle paintArea;
if (imageLoadError) {
paintArea = transformer.getPaintArea();
} else {
paintArea = calculateNewBounds(image, envelopeOrig);
}
final ReferencedEnvelope envelope = transformer.getBounds().toReferencedEnvelope(paintArea);
final BufferedImage bufferedImage =
new BufferedImage(paintArea.width, paintArea.height, TYPE_INT_ARGB_PRE);
Expand Down Expand Up @@ -157,30 +169,41 @@ public double getImageBufferScaling() {
public void prepareRender(
final MapfishMapContext transformer,
final MfClientHttpRequestFactory clientHttpRequestFactory) {
image = fetchImage(transformer, clientHttpRequestFactory);
try {
image = fetchLayerImage(transformer, clientHttpRequestFactory);
} catch (URISyntaxException | IOException | RuntimeException e) {
if (failOnError) {
throw new RuntimeException(e);
} else {
LOGGER.error("Error while fetching image", e);
image = createErrorImage(new Rectangle(1, 1));
imageLoadError = true;
imageBufferScaling = 1;
return;
}
}
imageLoadError = false;

final ReferencedEnvelope envelopeOrig =
transformer.getBounds().toReferencedEnvelope(transformer.getPaintArea());
final Rectangle paintArea = calculateNewBounds(image, envelopeOrig);

double widthImageBufferScaling = paintArea.getWidth() / transformer.getMapSize().getWidth();
double heightImageBufferScaling = paintArea.getHeight() / transformer.getMapSize().getHeight();
imageBufferScaling =
((paintArea.getWidth() / transformer.getMapSize().getWidth())
+ (paintArea.getHeight() / transformer.getMapSize().getHeight()))
/ 2;
Math.sqrt(
(Math.pow(widthImageBufferScaling, 2) + Math.pow(heightImageBufferScaling, 2)) / 2);
}

private BufferedImage fetchImage(
private BufferedImage fetchLayerImage(
final MapfishMapContext transformer,
final MfClientHttpRequestFactory clientHttpRequestFactory) {
final MfClientHttpRequestFactory clientHttpRequestFactory)
throws URISyntaxException, IOException {
BufferedImage image;
try {
final URI commonUri = new URI(this.params.getBaseUrl());
final ClientHttpRequest request =
clientHttpRequestFactory.createRequest(commonUri, HttpMethod.GET);
image = fetchImage(request, transformer);
} catch (URISyntaxException | IOException e) {
throw new RuntimeException(e);
}
return image;
final URI commonUri = new URI(this.params.getBaseUrl());
final ClientHttpRequest request =
clientHttpRequestFactory.createRequest(commonUri, HttpMethod.GET);
return fetchImage(request, transformer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public final class ImageSimilarity {
/** The constructor, which creates the GUI and start the image processing task. */
public ImageSimilarity(final File expectedFile) throws IOException {
this.expectedImage = expectedFile.exists() ? ImageIO.read(expectedFile) : null;
if (REGENERATE_EXPECTED_IMAGES) {
if (REGENERATE_EXPECTED_IMAGES || !expectedFile.exists()) {
this.expectedPath =
new File(
expectedFile
.toString()
.replace("/out/", "/src/")
.replace("/build/classes/test/", "/src/test/resources/")
.replace("/src/core/build/resources/test/", "/src/core/src/test/resources/"));
.replace("/build/resources/test/", "/src/test/resources/"));
} else {
this.expectedPath = expectedFile;
}
Expand Down Expand Up @@ -257,12 +257,18 @@ private File getRelatedFile(final String name) {
actualIterator.getPixel(x, y, actualPixel);
maskIterator.getPixel(x, y, maskPixel);
double squareDist = 0.0;
for (int i = 0; i < this.expectedImage.getSampleModel().getNumBands(); i++) {
double colorDist = (expectedPixel[i] - actualPixel[i]) * (maskPixel[0] / 255.0);
squareDist += colorDist * colorDist;
if (maskPixel[0] == 255) {
for (int i = 0; i < this.expectedImage.getSampleModel().getNumBands(); i++) {
double colorDist = expectedPixel[i] - actualPixel[i];
squareDist += colorDist * colorDist;
}
} else if (maskPixel[0] != 0) {
throw new RuntimeException(
String.format(
"Mask image must be only black and white (0 and 255), got %s at %s,%s in:\n%s",
maskPixel[0], x, y, this.maskImage));
}
double pxDiff =
Math.sqrt(squareDist) / Math.sqrt(this.expectedImage.getSampleModel().getNumBands());
double pxDiff = Math.sqrt(squareDist / this.expectedImage.getSampleModel().getNumBands());
dist += pxDiff / 255;
diffGraphics.setColor(new Color((int) Math.round(pxDiff), 0, 0));
diffGraphics.drawRect(x, y, 1, 1);
Expand Down Expand Up @@ -360,7 +366,7 @@ public void assertSimilarity(final File actualFile, final double maxDistance) th
* @throws IOException if the image could not be written.
*/
public void assertSimilarity(final BufferedImage actualImage) throws IOException {
assertSimilarity(actualImage, 1);
assertSimilarity(actualImage, 0);
}

/**
Expand All @@ -375,6 +381,7 @@ public void assertSimilarity(final BufferedImage actualImage, final double maxDi
throws IOException {
if (REGENERATE_EXPECTED_IMAGES || !this.expectedPath.exists()) {
ImageIO.write(actualImage, "png", expectedPath);
System.out.println("The expected file has been generated: " + expectedPath.getAbsolutePath());
if (REGENERATE_EXPECTED_IMAGES) {
return;
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/resources/map-data/ol-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
// create WMS layer
var wms = new OpenLayers.Layer.WMS(
'TOPP States',
'http://geoserver:8080/wms?',
'http://geoserver:8080/geoserver/wms?',
{
layers: 'topp:states',
styles: '',
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ version: '2.1'

services:
geoserver:
image: camptocamp/geoserver:2.17
image: camptocamp/geoserver:2.22.2
volumes:
- /tmp/geoserver-data:/mnt/geoserver_datadir
- ./examples/geoserver-data/:/mnt/geoserver_datadir
- ./core/src/test/resources/map-data/:/mnt/geoserver_datadir/www/map-data

print:
image: mapfish_print_tester
Expand All @@ -25,6 +26,7 @@ services:
command: tail --follow /dev/null
volumes:
- ./examples/src:/src/examples/src:ro
- ./examples/src/test/resources/examples:/src/examples/src/test/resources/examples
- ./examples/build/reports:/src/examples/build/reports
- ./examples/build/resources:/src/examples/build/resources
environment:
Expand Down
21 changes: 17 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Summary
## Summary

This repository is a submodule of mapfish-print and contains e2e tests for the pdf and image generation. It
contains the code to start a Geoserver instance and run junit integration tests against the server to test as
Expand All @@ -13,16 +13,16 @@ understood by referring to:

> <http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_test>

# Test client
## Test client

The test server includes a client which can be used for testing. To start the server, run:

docker-compose up -d

In the docker-comose context GeoServer can be accessed at <http://geoserver:8080/> and
In the docker-comose context GeoServer can be accessed at <http://geoserver:8080/geoserver/> and
MapFish Print can be accessed at <http://print:8080/>

# Writing Tests
## Writing Tests

By default the test server is in daemon mode, which mean that the servers will be run in a background thread
and be shutdown when the build completes. In order to be able to run the tests in a IDE one can run:
Expand All @@ -31,3 +31,16 @@ and be shutdown when the build completes. In order to be able to run the tests i

This will start the test servers in non-daemon mode allowing one to start the server and then run tests in
your IDE against that server for development.

## Test images used by acceptance tests

The application config will be loaded from the `src/test/resources/examples/<tested_application>/config.yaml` file.

The spec files will be loaded from the `src/test/resources/examples/<tested_application>/requestData<postfix>.json` file.

The expected images will be loaded from the `src/test/resources/examples/<tested_application>/expected_output/requestData<postfix>.png` file.

We can optionally have a mask image that will be used to mask the tested image.
This mask image will be loaded from the `src/test/resources/examples/<tested_application>/expected_output/mask-requestData<postfix>.png` file.
This image should be grayscale with only full black and full white pixel values.
If we create the mask image with Gimp, we can't create indexed image with tow colors because in the Java code we get the values 1 instead of 0 for the black pixel.
2 changes: 1 addition & 1 deletion examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ configurations {

tasks.register('geoserver' , Exec) {
description 'Run and wait for GeoServer with test data'
commandLine 'curl', 'http://geoserver:8080/web/', '--output', '/dev/null'
commandLine 'curl', 'http://geoserver:8080/geoserver/web/', '--output', '/dev/null'
}

// prevent that the tests target can be directly called. the integration tests
Expand Down
3 changes: 3 additions & 0 deletions examples/geoserver-data/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Project used to run the examples

Originally the project comes from the example project provided by GeoServer.
3 changes: 3 additions & 0 deletions examples/geoserver-data/data/shapefiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Shapefiles

`state.shp` contains the US states, simplified with `ogr2ogr examples/geoserver-data/data/shapefiles/states.shp -update -simplify 0.01`
Binary file modified examples/geoserver-data/data/shapefiles/states.dbf
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/geoserver-data/data/shapefiles/states.prj
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file modified examples/geoserver-data/data/shapefiles/states.qix
Binary file not shown.
Binary file modified examples/geoserver-data/data/shapefiles/states.shp
Binary file not shown.
Binary file modified examples/geoserver-data/data/shapefiles/states.shx
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/geoserver-data/demo/WFS_transactionInsert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
xmlns:topp="http://www.openplans.org/topp"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd http://www.openplans.org/topp http://geoserver:8080/wfs/DescribeFeatureType?typename=topp:tasmania_roads">
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd http://www.openplans.org/topp http://geoserver:8080/geoserver/wfs/DescribeFeatureType?typename=topp:tasmania_roads">
<wfs:Insert>
<topp:tasmania_roads>
<topp:the_geom>
Expand Down
2 changes: 1 addition & 1 deletion examples/geoserver-data/demo/WMS_GetLegendGraphic-SLD.url
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states&SLD=http://geoserver:8080/www/styles/green.sld
wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states&SLD=http://geoserver:8080/geoserver/www/styles/green.sld
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<id>52857278:13c7ffd66a8:-7ff7</id>
<name>anonymous</name>
<className>org.geoserver.security.filter.GeoServerAnonymousAuthenticationFilter</className>
</anonymousAuthentication>
</anonymousAuthentication>
2 changes: 1 addition & 1 deletion examples/geoserver-data/security/filter/basic/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<name>basic</name>
<className>org.geoserver.security.filter.GeoServerBasicAuthenticationFilter</className>
<useRememberMe>true</useRememberMe>
</basicAuthentication>
</basicAuthentication>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<name>contextAsc</name>
<className>org.geoserver.security.filter.GeoServerSecurityContextPersistenceFilter</className>
<allowSessionCreation>true</allowSessionCreation>
</contextPersistence>
</contextPersistence>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<name>contextNoAsc</name>
<className>org.geoserver.security.filter.GeoServerSecurityContextPersistenceFilter</className>
<allowSessionCreation>false</allowSessionCreation>
</contextPersistence>
</contextPersistence>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<id>52857278:13c7ffd66a8:-7ff2</id>
<name>exception</name>
<className>org.geoserver.security.filter.GeoServerExceptionTranslationFilter</className>
</exceptionTranslation>
</exceptionTranslation>
2 changes: 1 addition & 1 deletion examples/geoserver-data/security/filter/form/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<className>org.geoserver.security.filter.GeoServerUserNamePasswordAuthenticationFilter</className>
<passwordParameterName>password</passwordParameterName>
<usernameParameterName>username</usernameParameterName>
</usernamePasswordFilter>
</usernamePasswordFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<name>formLogout</name>
<className>org.geoserver.security.filter.GeoServerLogoutFilter</className>
<redirectURL>/web/</redirectURL>
</logoutFilter>
</logoutFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<className>org.geoserver.security.filter.GeoServerSecurityInterceptorFilter</className>
<allowIfAllAbstainDecisions>false</allowIfAllAbstainDecisions>
<securityMetadataSource>geoserverMetadataSource</securityMetadataSource>
</securityInterceptor>
</securityInterceptor>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<id>52857278:13c7ffd66a8:-7ff6</id>
<name>rememberme</name>
<className>org.geoserver.security.filter.GeoServerRememberMeAuthenticationFilter</className>
</rememberMeAuthentication>
</rememberMeAuthentication>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<className>org.geoserver.security.filter.GeoServerSecurityInterceptorFilter</className>
<allowIfAllAbstainDecisions>false</allowIfAllAbstainDecisions>
<securityMetadataSource>restFilterDefinitionMap</securityMetadataSource>
</securityInterceptor>
</securityInterceptor>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<className>org.geoserver.security.filter.GeoServerRoleFilter</className>
<httpResponseHeaderAttrForIncludedRoles>roles</httpResponseHeaderAttrForIncludedRoles>
<roleConverterName>roleConverter</roleConverterName>
</roleFilter>
</roleFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<name>sslFilter</name>
<className>org.geoserver.security.filter.GeoServerSSLFilter</className>
<sslPort>443</sslPort>
</sslFilter>
</sslFilter>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scale": 25000,
"layers": [
{
"baseURL": "http://geoserver:8080/wms",
"baseURL": "http://geoserver:8080/geoserver/wms",
"opacity": 1,
"type": "WMS",
"layers": ["tiger:tiger_roads"],
Expand Down
Loading
Loading