Skip to content

Commit f7c5f2e

Browse files
authored
Merge pull request #1931 from lat-lon/fix/exceptionHandlingRemotWms-1926
Fixed WMS response if remote layer cannot be retrieved
2 parents 03ac2c1 + ee4dea6 commit f7c5f2e

7 files changed

Lines changed: 124 additions & 10 deletions

File tree

deegree-core/deegree-core-layer/src/main/java/org/deegree/layer/LayerData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
----------------------------------------------------------------------------*/
3535
package org.deegree.layer;
3636

37+
import org.deegree.commons.ows.exception.OWSException;
3738
import org.deegree.feature.FeatureCollection;
3839
import org.deegree.rendering.r2d.context.RenderContext;
3940

@@ -42,7 +43,7 @@
4243
*/
4344
public interface LayerData {
4445

45-
void render(RenderContext context) throws InterruptedException;
46+
void render(RenderContext context) throws InterruptedException, OWSException;
4647

4748
// think about using a infocontext or something here
4849
FeatureCollection info();

deegree-core/deegree-core-protocol/deegree-protocol-wms/src/main/java/org/deegree/protocol/wms/client/WMSClient.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
import org.deegree.protocol.ows.http.OwsHttpClientImpl;
111111
import org.deegree.protocol.ows.http.OwsHttpResponse;
112112
import org.deegree.protocol.wms.WMSConstants.WMSRequestType;
113+
import org.deegree.protocol.wms.ops.EXCEPTIONS_FORMAT;
113114
import org.deegree.protocol.wms.ops.GetFeatureInfo;
114115
import org.deegree.protocol.wms.ops.GetMap;
115116
import org.deegree.rendering.r2d.RenderHelper;
@@ -286,7 +287,8 @@ public Envelope getBoundingBox(String srs, List<String> layers) {
286287
*/
287288
public Pair<BufferedImage, String> getMap(GetMap getMap, Map<String, String> hardParameters, int timeout)
288289
throws IOException {
289-
return getMap(getMap, hardParameters, timeout, false);
290+
boolean errorsInImage = EXCEPTIONS_FORMAT.INIMAGE.equals(getMap.getExceptionsFormat());
291+
return getMap(getMap, hardParameters, timeout, errorsInImage);
290292
}
291293

292294
/**
@@ -609,7 +611,12 @@ private Pair<BufferedImage, String> getMap(List<LayerRef> layers, List<StyleRef>
609611
catch (Throwable e) {
610612
LOG.info("Error performing GetMap request: {}", e.getMessage());
611613
LOG.trace("Stack trace:", e);
612-
res.second = e.getMessage();
614+
if (e instanceof IOException) {
615+
res.second = "Error retrieving remote map.";
616+
}
617+
else {
618+
res.second = e.getMessage();
619+
}
613620
}
614621

615622
if (errorsInImage && res.first == null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*----------------------------------------------------------------------------
2+
This file is part of deegree
3+
Copyright (C) 2001-2026 by:
4+
- Department of Geography, University of Bonn -
5+
and
6+
- lat/lon GmbH -
7+
and others
8+
9+
This library is free software; you can redistribute it and/or modify it under
10+
the terms of the GNU Lesser General Public License as published by the Free
11+
Software Foundation; either version 2.1 of the License, or (at your option)
12+
any later version.
13+
This library is distributed in the hope that it will be useful, but WITHOUT
14+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15+
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16+
details.
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with this library; if not, write to the Free Software Foundation, Inc.,
19+
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20+
21+
Contact information:
22+
23+
e-mail: info@deegree.org
24+
website: http://www.deegree.org/
25+
----------------------------------------------------------------------------*/
26+
package org.deegree.protocol.wms.ops;
27+
28+
import java.util.Arrays;
29+
import java.util.List;
30+
import java.util.Optional;
31+
32+
/**
33+
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
34+
*/
35+
public enum EXCEPTIONS_FORMAT {
36+
37+
XML("XML", "application/vnd.ogc.se_xml"), INIMAGE("INIMAGE", "application/vnd.ogc.se_inimage"),
38+
BLANK("BLANK", "application/vnd.ogc.se_blank");
39+
40+
private final List<String> paramValues;
41+
42+
EXCEPTIONS_FORMAT(String... paramValues) {
43+
this.paramValues = Arrays.asList(paramValues);
44+
}
45+
46+
public static EXCEPTIONS_FORMAT findByParamValue(String paramValue) {
47+
Optional<EXCEPTIONS_FORMAT> exceptionsFormatStream = Arrays.stream(EXCEPTIONS_FORMAT.values())
48+
.filter(pv -> pv.paramValues.contains(paramValue))
49+
.findFirst();
50+
return exceptionsFormatStream.orElse(XML);
51+
}
52+
53+
}

deegree-core/deegree-core-protocol/deegree-protocol-wms/src/main/java/org/deegree/protocol/wms/ops/GetMap.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,19 @@
4646
import static org.deegree.layer.dims.Dimension.parseTyped;
4747
import static org.deegree.protocol.wms.WMSConstants.VERSION_111;
4848
import static org.deegree.protocol.wms.WMSConstants.VERSION_130;
49+
import static org.deegree.protocol.wms.ops.EXCEPTIONS_FORMAT.XML;
50+
import static org.deegree.rendering.r2d.context.MapOptions.Antialias.BOTH;
51+
import static org.deegree.rendering.r2d.context.MapOptions.Interpolation.NEARESTNEIGHBOR;
52+
import static org.deegree.rendering.r2d.context.MapOptions.Quality.NORMAL;
4953
import static org.deegree.rendering.r2d.context.MapOptions.getAntialiasGetter;
5054
import static org.deegree.rendering.r2d.context.MapOptions.getAntialiasSetter;
5155
import static org.deegree.rendering.r2d.context.MapOptions.getInterpolationGetter;
5256
import static org.deegree.rendering.r2d.context.MapOptions.getInterpolationSetter;
5357
import static org.deegree.rendering.r2d.context.MapOptions.getQualityGetter;
5458
import static org.deegree.rendering.r2d.context.MapOptions.getQualitySetter;
55-
import static org.deegree.rendering.r2d.context.MapOptions.Antialias.BOTH;
56-
import static org.deegree.rendering.r2d.context.MapOptions.Interpolation.NEARESTNEIGHBOR;
57-
import static org.deegree.rendering.r2d.context.MapOptions.Quality.NORMAL;
5859
import static org.slf4j.LoggerFactory.getLogger;
5960

60-
import java.awt.Color;
61+
import java.awt.*;
6162
import java.text.ParseException;
6263
import java.util.Collection;
6364
import java.util.HashMap;
@@ -130,6 +131,8 @@ public class GetMap extends RequestBase {
130131

131132
private Map<String, String> overriddenParameters;
132133

134+
private EXCEPTIONS_FORMAT exceptionsFormat = XML;
135+
133136
/**
134137
* @param map
135138
* @param version
@@ -144,6 +147,7 @@ public GetMap(Map<String, String> map, Version version, MapOptionsMaps exts, boo
144147
if (version.equals(VERSION_130)) {
145148
parse130(map, exts, parseStrict);
146149
}
150+
exceptionsFormat = EXCEPTIONS_FORMAT.findByParamValue(map.get("EXCEPTIONS"));
147151
parameterMap.putAll(map);
148152
try {
149153
scale = RenderHelper.calcScaleWMS130(width, height, bbox, crs, pixelSize);
@@ -194,6 +198,11 @@ public GetMap(Collection<LayerRef> layers, Collection<StyleRef> styles, int widt
194198

195199
public GetMap(List<String> layers, int width, int height, Envelope envelope, ICRS crs, String format,
196200
boolean transparent) {
201+
this(layers, width, height, envelope, crs, format, transparent, XML);
202+
}
203+
204+
public GetMap(List<String> layers, int width, int height, Envelope envelope, ICRS crs, String format,
205+
boolean transparent, EXCEPTIONS_FORMAT exceptionsFormat) {
197206
this.layers = map(layers, FROM_NAMES);
198207
this.width = width;
199208
this.height = height;
@@ -202,6 +211,7 @@ public GetMap(List<String> layers, int width, int height, Envelope envelope, ICR
202211
this.crs = crs;
203212
this.format = format;
204213
this.transparent = transparent;
214+
this.exceptionsFormat = exceptionsFormat;
205215
}
206216

207217
public GetMap(List<LayerRef> layers, List<StyleRef> styles, int width, int height, Envelope envelope, ICRS crs,
@@ -811,4 +821,11 @@ public Map<String, String> getOverriddenParameters() {
811821
return overriddenParameters;
812822
}
813823

824+
/**
825+
* @return the requested format for EXCEPTIONS, defaults to XML if missing in request
826+
*/
827+
public EXCEPTIONS_FORMAT getExceptionsFormat() {
828+
return exceptionsFormat;
829+
}
830+
814831
}

deegree-core/deegree-core-protocol/deegree-protocol-wms/src/test/java/org/deegree/protocol/wms/ops/GetMapTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.IOException;
99
import java.util.Map;
1010

11+
import static org.junit.Assert.assertEquals;
1112
import static org.junit.Assert.assertFalse;
1213
import static org.junit.Assert.assertTrue;
1314

@@ -47,6 +48,30 @@ public void testTransparent_Invalid_ParseLax() throws Exception {
4748
assertFalse(getMap.getTransparent());
4849
}
4950

51+
@Test
52+
public void testExceptions_missing_wfs130() throws Exception {
53+
Map<String, String> kvp = createRequest(
54+
"BBOX=228152.00000000%2C5690412.00000000%2C493382.00000000%2C5939023.00000000&CRS=EPSG%3A25833&FORMAT=image%2Fpng&HEIGHT=500&LAYERS=EF.EnvironmentalMonitoringProgrammes&REQUEST=GetMap&SERVICE=WMS&STYLES=EF.EnvironmentalMonitoringProgrammes.Default.Point&TRANSPARENT=zzzz&VERSION=1.3.0&WIDTH=500");
55+
GetMap getMap = new GetMap(kvp, Version.parseVersion("1.3.0"), null, false);
56+
assertEquals(EXCEPTIONS_FORMAT.XML, getMap.getExceptionsFormat());
57+
}
58+
59+
@Test
60+
public void testExceptions_inimage_wfs130() throws Exception {
61+
Map<String, String> kvp = createRequest(
62+
"BBOX=228152.00000000%2C5690412.00000000%2C493382.00000000%2C5939023.00000000&CRS=EPSG%3A25833&FORMAT=image%2Fpng&HEIGHT=500&LAYERS=EF.EnvironmentalMonitoringProgrammes&REQUEST=GetMap&SERVICE=WMS&STYLES=EF.EnvironmentalMonitoringProgrammes.Default.Point&TRANSPARENT=zzzz&VERSION=1.3.0&WIDTH=500&EXCEPTIONS=INIMAGE");
63+
GetMap getMap = new GetMap(kvp, Version.parseVersion("1.3.0"), null, false);
64+
assertEquals(EXCEPTIONS_FORMAT.INIMAGE, getMap.getExceptionsFormat());
65+
}
66+
67+
@Test
68+
public void testExceptions_inimage_wfs111() throws Exception {
69+
Map<String, String> kvp = createRequest(
70+
"BBOX=228152.00000000%2C5690412.00000000%2C493382.00000000%2C5939023.00000000&SRS=EPSG%3A25833&FORMAT=image%2Fpng&HEIGHT=500&LAYERS=EF.EnvironmentalMonitoringProgrammes&REQUEST=GetMap&SERVICE=WMS&STYLES=EF.EnvironmentalMonitoringProgrammes.Default.Point&TRANSPARENT=zzzz&VERSION=1.3.0&WIDTH=500&EXCEPTIONS=application/vnd.ogc.se_inimage");
71+
GetMap getMap = new GetMap(kvp, Version.parseVersion("1.1.1"), null, false);
72+
assertEquals(EXCEPTIONS_FORMAT.INIMAGE, getMap.getExceptionsFormat());
73+
}
74+
5075
private Map<String, String> createRequest(String queryParams) throws IOException {
5176
return KVPUtils.getNormalizedKVPMap(queryParams, "UTF-8");
5277
}

deegree-layers/deegree-layers-remotewms/src/main/java/org/deegree/layer/persistence/remotewms/RemoteWMSLayer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static java.util.Collections.singletonList;
44
import static org.deegree.commons.utils.RequestUtils.replaceParameters;
5+
import static org.deegree.protocol.oldwms.WMSConstants.WMSRequestType.map;
56
import static org.deegree.protocol.wms.WMSConstants.WMSRequestType.GetMap;
67
import static org.slf4j.LoggerFactory.getLogger;
78

@@ -26,6 +27,7 @@
2627
import org.deegree.layer.persistence.remotewms.jaxb.RequestOptionsType.DefaultCRS;
2728
import org.deegree.layer.persistence.remotewms.jaxb.RequestOptionsType.Parameter;
2829
import org.deegree.protocol.wms.client.WMSClient;
30+
import org.deegree.protocol.wms.ops.EXCEPTIONS_FORMAT;
2931
import org.deegree.protocol.wms.ops.GetFeatureInfo;
3032
import org.deegree.protocol.wms.ops.GetMap;
3133
import org.deegree.style.StyleRef;
@@ -146,6 +148,8 @@ private void extractParameters(List<Parameter> params) {
146148
public RemoteWMSLayerData mapQuery(LayerQuery query, List<String> headers) {
147149
Map<String, String> extraParams = new HashMap<String, String>();
148150
replaceParameters(extraParams, query.getParameters(), defaultParametersGetMap, hardParametersGetMap);
151+
EXCEPTIONS_FORMAT exceptionsFormat = EXCEPTIONS_FORMAT
152+
.findByParamValue(query.getParameters().get("EXCEPTIONS"));
149153
ICRS crs = this.crs;
150154
if (!alwaysUseDefaultCrs) {
151155
ICRS envCrs = query.getEnvelope().getCoordinateSystem();
@@ -155,7 +159,7 @@ public RemoteWMSLayerData mapQuery(LayerQuery query, List<String> headers) {
155159
}
156160

157161
GetMap gm = new GetMap(singletonList(originalName), query.getWidth(), query.getHeight(), query.getEnvelope(),
158-
crs, format, transparent);
162+
crs, format, transparent, exceptionsFormat);
159163
return new RemoteWMSLayerData(client, gm, extraParams);
160164
}
161165

deegree-layers/deegree-layers-remotewms/src/main/java/org/deegree/layer/persistence/remotewms/RemoteWMSLayerData.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.awt.image.BufferedImage;
4040
import java.util.Map;
4141

42+
import org.deegree.commons.ows.exception.OWSException;
4243
import org.deegree.commons.utils.Pair;
4344
import org.deegree.feature.FeatureCollection;
4445
import org.deegree.feature.GenericFeatureCollection;
@@ -82,18 +83,24 @@ public RemoteWMSLayerData(WMSClient client, GetFeatureInfo gfi, Map<String, Stri
8283
}
8384

8485
@Override
85-
public void render(RenderContext context) {
86+
public void render(RenderContext context) throws OWSException {
87+
String exception = null;
8688
try {
8789
Pair<BufferedImage, String> map = client.getMap(gm, extraParams, 30);
8890
if (map.first != null) {
8991
context.paintImage(map.first);
9092
}
93+
else if (map.second != null) {
94+
exception = map.second;
95+
}
9196
}
9297
catch (Throwable e) {
93-
e.printStackTrace();
9498
LOG.warn("Error when retrieving remote map: {}", e.getLocalizedMessage());
9599
LOG.trace("Stack trace:", e);
96100
}
101+
if (exception != null) {
102+
throw new OWSException(exception, OWSException.NO_APPLICABLE_CODE);
103+
}
97104
}
98105

99106
@Override

0 commit comments

Comments
 (0)