Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
----------------------------------------------------------------------------*/
package org.deegree.layer;

import org.deegree.commons.ows.exception.OWSException;
import org.deegree.feature.FeatureCollection;
import org.deegree.rendering.r2d.context.RenderContext;

Expand All @@ -42,7 +43,7 @@
*/
public interface LayerData {

void render(RenderContext context) throws InterruptedException;
void render(RenderContext context) throws InterruptedException, OWSException;

// think about using a infocontext or something here
FeatureCollection info();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import org.deegree.protocol.ows.http.OwsHttpClientImpl;
import org.deegree.protocol.ows.http.OwsHttpResponse;
import org.deegree.protocol.wms.WMSConstants.WMSRequestType;
import org.deegree.protocol.wms.ops.EXCEPTIONS_FORMAT;
import org.deegree.protocol.wms.ops.GetFeatureInfo;
import org.deegree.protocol.wms.ops.GetMap;
import org.deegree.rendering.r2d.RenderHelper;
Expand Down Expand Up @@ -286,7 +287,8 @@ public Envelope getBoundingBox(String srs, List<String> layers) {
*/
public Pair<BufferedImage, String> getMap(GetMap getMap, Map<String, String> hardParameters, int timeout)
throws IOException {
return getMap(getMap, hardParameters, timeout, false);
boolean errorsInImage = EXCEPTIONS_FORMAT.INIMAGE.equals(getMap.getExceptionsFormat());
return getMap(getMap, hardParameters, timeout, errorsInImage);
}

/**
Expand Down Expand Up @@ -609,7 +611,12 @@ private Pair<BufferedImage, String> getMap(List<LayerRef> layers, List<StyleRef>
catch (Throwable e) {
LOG.info("Error performing GetMap request: {}", e.getMessage());
LOG.trace("Stack trace:", e);
res.second = e.getMessage();
if (e instanceof IOException) {
res.second = "Error retrieving remote map.";
}
else {
res.second = e.getMessage();
}
}

if (errorsInImage && res.first == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------
This file is part of deegree
Copyright (C) 2001-2026 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -
and others

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Contact information:

e-mail: info@deegree.org
website: http://www.deegree.org/
----------------------------------------------------------------------------*/
package org.deegree.protocol.wms.ops;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
public enum EXCEPTIONS_FORMAT {

XML("XML", "application/vnd.ogc.se_xml"), INIMAGE("INIMAGE", "application/vnd.ogc.se_inimage"),
BLANK("BLANK", "application/vnd.ogc.se_blank");

private final List<String> paramValues;

EXCEPTIONS_FORMAT(String... paramValues) {
this.paramValues = Arrays.asList(paramValues);
}

public static EXCEPTIONS_FORMAT findByParamValue(String paramValue) {
Optional<EXCEPTIONS_FORMAT> exceptionsFormatStream = Arrays.stream(EXCEPTIONS_FORMAT.values())
.filter(pv -> pv.paramValues.contains(paramValue))
.findFirst();
return exceptionsFormatStream.orElse(XML);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@
import static org.deegree.layer.dims.Dimension.parseTyped;
import static org.deegree.protocol.wms.WMSConstants.VERSION_111;
import static org.deegree.protocol.wms.WMSConstants.VERSION_130;
import static org.deegree.protocol.wms.ops.EXCEPTIONS_FORMAT.XML;
import static org.deegree.rendering.r2d.context.MapOptions.Antialias.BOTH;
import static org.deegree.rendering.r2d.context.MapOptions.Interpolation.NEARESTNEIGHBOR;
import static org.deegree.rendering.r2d.context.MapOptions.Quality.NORMAL;
import static org.deegree.rendering.r2d.context.MapOptions.getAntialiasGetter;
import static org.deegree.rendering.r2d.context.MapOptions.getAntialiasSetter;
import static org.deegree.rendering.r2d.context.MapOptions.getInterpolationGetter;
import static org.deegree.rendering.r2d.context.MapOptions.getInterpolationSetter;
import static org.deegree.rendering.r2d.context.MapOptions.getQualityGetter;
import static org.deegree.rendering.r2d.context.MapOptions.getQualitySetter;
import static org.deegree.rendering.r2d.context.MapOptions.Antialias.BOTH;
import static org.deegree.rendering.r2d.context.MapOptions.Interpolation.NEARESTNEIGHBOR;
import static org.deegree.rendering.r2d.context.MapOptions.Quality.NORMAL;
import static org.slf4j.LoggerFactory.getLogger;

import java.awt.Color;
import java.awt.*;
import java.text.ParseException;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -130,6 +131,8 @@ public class GetMap extends RequestBase {

private Map<String, String> overriddenParameters;

private EXCEPTIONS_FORMAT exceptionsFormat = XML;

/**
* @param map
* @param version
Expand All @@ -144,6 +147,7 @@ public GetMap(Map<String, String> map, Version version, MapOptionsMaps exts, boo
if (version.equals(VERSION_130)) {
parse130(map, exts, parseStrict);
}
exceptionsFormat = EXCEPTIONS_FORMAT.findByParamValue(map.get("EXCEPTIONS"));
parameterMap.putAll(map);
try {
scale = RenderHelper.calcScaleWMS130(width, height, bbox, crs, pixelSize);
Expand Down Expand Up @@ -194,6 +198,11 @@ public GetMap(Collection<LayerRef> layers, Collection<StyleRef> styles, int widt

public GetMap(List<String> layers, int width, int height, Envelope envelope, ICRS crs, String format,
boolean transparent) {
this(layers, width, height, envelope, crs, format, transparent, XML);
}

public GetMap(List<String> layers, int width, int height, Envelope envelope, ICRS crs, String format,
boolean transparent, EXCEPTIONS_FORMAT exceptionsFormat) {
this.layers = map(layers, FROM_NAMES);
this.width = width;
this.height = height;
Expand All @@ -202,6 +211,7 @@ public GetMap(List<String> layers, int width, int height, Envelope envelope, ICR
this.crs = crs;
this.format = format;
this.transparent = transparent;
this.exceptionsFormat = exceptionsFormat;
}

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

/**
* @return the requested format for EXCEPTIONS, defaults to XML if missing in request
*/
public EXCEPTIONS_FORMAT getExceptionsFormat() {
return exceptionsFormat;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -47,6 +48,30 @@ public void testTransparent_Invalid_ParseLax() throws Exception {
assertFalse(getMap.getTransparent());
}

@Test
public void testExceptions_missing_wfs130() throws Exception {
Map<String, String> kvp = createRequest(
"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");
GetMap getMap = new GetMap(kvp, Version.parseVersion("1.3.0"), null, false);
assertEquals(EXCEPTIONS_FORMAT.XML, getMap.getExceptionsFormat());
}

@Test
public void testExceptions_inimage_wfs130() throws Exception {
Map<String, String> kvp = createRequest(
"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");
GetMap getMap = new GetMap(kvp, Version.parseVersion("1.3.0"), null, false);
assertEquals(EXCEPTIONS_FORMAT.INIMAGE, getMap.getExceptionsFormat());
}

@Test
public void testExceptions_inimage_wfs111() throws Exception {
Map<String, String> kvp = createRequest(
"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");
GetMap getMap = new GetMap(kvp, Version.parseVersion("1.1.1"), null, false);
assertEquals(EXCEPTIONS_FORMAT.INIMAGE, getMap.getExceptionsFormat());
}

private Map<String, String> createRequest(String queryParams) throws IOException {
return KVPUtils.getNormalizedKVPMap(queryParams, "UTF-8");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Collections.singletonList;
import static org.deegree.commons.utils.RequestUtils.replaceParameters;
import static org.deegree.protocol.oldwms.WMSConstants.WMSRequestType.map;
import static org.deegree.protocol.wms.WMSConstants.WMSRequestType.GetMap;
import static org.slf4j.LoggerFactory.getLogger;

Expand All @@ -26,6 +27,7 @@
import org.deegree.layer.persistence.remotewms.jaxb.RequestOptionsType.DefaultCRS;
import org.deegree.layer.persistence.remotewms.jaxb.RequestOptionsType.Parameter;
import org.deegree.protocol.wms.client.WMSClient;
import org.deegree.protocol.wms.ops.EXCEPTIONS_FORMAT;
import org.deegree.protocol.wms.ops.GetFeatureInfo;
import org.deegree.protocol.wms.ops.GetMap;
import org.deegree.style.StyleRef;
Expand Down Expand Up @@ -146,6 +148,8 @@ private void extractParameters(List<Parameter> params) {
public RemoteWMSLayerData mapQuery(LayerQuery query, List<String> headers) {
Map<String, String> extraParams = new HashMap<String, String>();
replaceParameters(extraParams, query.getParameters(), defaultParametersGetMap, hardParametersGetMap);
EXCEPTIONS_FORMAT exceptionsFormat = EXCEPTIONS_FORMAT
.findByParamValue(query.getParameters().get("EXCEPTIONS"));
ICRS crs = this.crs;
if (!alwaysUseDefaultCrs) {
ICRS envCrs = query.getEnvelope().getCoordinateSystem();
Expand All @@ -155,7 +159,7 @@ public RemoteWMSLayerData mapQuery(LayerQuery query, List<String> headers) {
}

GetMap gm = new GetMap(singletonList(originalName), query.getWidth(), query.getHeight(), query.getEnvelope(),
crs, format, transparent);
crs, format, transparent, exceptionsFormat);
return new RemoteWMSLayerData(client, gm, extraParams);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.awt.image.BufferedImage;
import java.util.Map;

import org.deegree.commons.ows.exception.OWSException;
import org.deegree.commons.utils.Pair;
import org.deegree.feature.FeatureCollection;
import org.deegree.feature.GenericFeatureCollection;
Expand Down Expand Up @@ -82,18 +83,24 @@ public RemoteWMSLayerData(WMSClient client, GetFeatureInfo gfi, Map<String, Stri
}

@Override
public void render(RenderContext context) {
public void render(RenderContext context) throws OWSException {
String exception = null;
try {
Pair<BufferedImage, String> map = client.getMap(gm, extraParams, 30);
if (map.first != null) {
context.paintImage(map.first);
}
else if (map.second != null) {
exception = map.second;
}
}
catch (Throwable e) {
e.printStackTrace();
LOG.warn("Error when retrieving remote map: {}", e.getLocalizedMessage());
LOG.trace("Stack trace:", e);
}
if (exception != null) {
throw new OWSException(exception, OWSException.NO_APPLICABLE_CODE);
}
}

@Override
Expand Down