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

[GWC-1101] Upgrade Spring Core to 5.3.23 #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -245,7 +245,7 @@ private HashMap<String, GridSubset> createGridSubsets(final GridSetBroker gridSe
final GridSetBuilder gsBuilder = new GridSetBuilder();
GridSet gridSet = gsBuilder.buildGridset(layerName, info, layerBounds);

getGridsetConfiguration(gridSetBroker).addInternal(gridSet);
gridSetBroker.put(gridSet);

final List<LODInfo> lodInfos = tileCacheInfo.getLodInfos();
Integer zoomStart = lodInfos.get(0).getLevelID();
Expand All @@ -259,20 +259,6 @@ private HashMap<String, GridSubset> createGridSubsets(final GridSetBroker gridSe
return subsets;
}

private ArcGISCacheGridsetConfiguration getGridsetConfiguration(
final GridSetBroker gridSetBroker) {
List<? extends ArcGISCacheGridsetConfiguration> configs =
gridSetBroker.getConfigurations(ArcGISCacheGridsetConfiguration.class);
if (configs.isEmpty()) {
throw new IllegalStateException("No ArcGISCacheGridsetConfiguration could be found");
} else {
if (configs.size() > 1) {
log.warning("Multiple instances of ArcGISCacheGridsetConfiguration, using first");
}
return configs.iterator().next();
}
}

/** @see org.geowebcache.layer.TileLayer#getTile(org.geowebcache.conveyor.ConveyorTile) */
@Override
public ConveyorTile getTile(final ConveyorTile tile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* This program 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 3
* of the License, or (at your option) any later version.
*
* <p>This program 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 General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* <p>Copyright 2022
*/
package org.geowebcache.arcgis.layer;

import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import org.geowebcache.config.DefaultGridsets;
import org.geowebcache.config.GridSetConfiguration;
import org.geowebcache.config.XMLConfiguration;
import org.geowebcache.grid.GridSetBroker;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.context.ApplicationContext;

public class ArcGISCacheLayerTest {
@Rule public TemporaryFolder temp = new TemporaryFolder();

@Test
public void testArcGISCacheLayerInitialization() throws Exception {

// The ArcGISCacheLayer GridSetBroker is instantiated with two configurations:
// org.geowebcache.config.XMLConfiguration & org.geowebcache.config.DefaultGridsets
// PLEASE DO NOT update the ArcGISCacheLayer GridSetBroker mocking below without first
// confirming any new ArcGISCacheLayer GridSet configuration logic is build tested to work
// with an actual ArcGISCacheLayer configuration test using the GWC tiling scheme steps:
// https://www.geowebcache.org/docs/latest/configuration/layers/arcgistilingschemes.html

final File configDir = temp.getRoot();
ArcGISCacheLayer layer = new ArcGISCacheLayer("fakeLayerId");
ApplicationContext appContext = createMock(ApplicationContext.class);
final DefaultGridsets defaultGridSets = new DefaultGridsets(true, true);
GridSetBroker gridSetBroker = new GridSetBroker(Arrays.asList(defaultGridSets));
XMLConfiguration config = new XMLConfiguration(null, configDir.getAbsolutePath());
config.setGridSetBroker(gridSetBroker);
gridSetBroker.setApplicationContext(appContext);
final HashMap<String, GridSetConfiguration> beans = new HashMap<>(2);
beans.put("defaultGridSets", defaultGridSets);
beans.put("xmlConfig", config);
expect(appContext.getBeansOfType(GridSetConfiguration.class)).andReturn(beans);
expect(appContext.getBean("defaultGridSets")).andReturn(defaultGridSets);
expect(appContext.getBean("xmlConfig")).andReturn(config);
replay(appContext);

File tileConfig = new File("./src/test/resources/compactcacheV2/Conf.xml");
layer.setTilingScheme(tileConfig);
// ArcGISCacheLayer should initialize with gridSetBroker without throwing exceptions
layer.initialize(gridSetBroker);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* This program 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 3
* of the License, or (at your option) any later version.
*
* <p>This program 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 General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* <p>Copyright 2022
*/
package org.geowebcache.layer;

import org.geowebcache.GeoWebCacheException;
import org.geowebcache.io.ByteArrayResource;
import org.geowebcache.mime.MimeType;

/**
* Exception used to indicate no contents was found, but the tile was inside the bounds of the
* layer. The tile is considered empty, depending on the format that might need a 204, no content,
* or a 200 with a valid empty tile for the chosen mime type.
*/
public class EmptyTileException extends GeoWebCacheException {

private final MimeType mime;
private ByteArrayResource contents;

/**
* An empty tile was found, the result contents are provided (e..g., a valid empty tile in the
* specified format). Should return a 200.
*/
public EmptyTileException(MimeType mime, ByteArrayResource contents) {
this(mime);
this.contents = contents;
}

/**
* An empty tile was found, but no contents are provided. The caller should return a 204, no
* content.
*/
public EmptyTileException(MimeType mime) {
super("No tile data available for this location");
this.mime = mime;
}

public MimeType getMime() {
return mime;
}

public ByteArrayResource getContents() {
return contents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,13 @@ public void proxyRequest(ConveyorTile tile) throws GeoWebCacheException {
HttpEntity entity = httpResponse.getEntity();
try (InputStream is = entity.getContent()) {
HttpServletResponse response = tile.servletResp;
Header contentEncoding = entity.getContentEncoding();
response.setCharacterEncoding(contentEncoding.getValue());
org.apache.http.Header contentType = httpResponse.getFirstHeader("Content-Type");
if (contentType != null) {
response.setContentType(contentType.getValue());
Header contentEncoding = entity.getContentEncoding();
if (!MimeType.isBinary(contentType.getValue())) {
response.setCharacterEncoding(contentEncoding.getValue());
}
}

int read = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -70,6 +72,9 @@ public class ApplicationMime extends MimeType {
static Set<ApplicationMime> ALL =
ImmutableSet.of(bil16, bil32, json, topojson, geojson, utfgrid, mapboxVector);

private static final List<String> BINARY_FORMATS =
Arrays.asList(bil16.mimeType, bil32.mimeType, mapboxVector.mimeType, utfgrid.mimeType);

private static Map<String, ApplicationMime> BY_FORMAT =
Maps.uniqueIndex(ALL, mimeType -> mimeType.getFormat());

Expand Down Expand Up @@ -109,4 +114,9 @@ protected static ApplicationMime checkForExtension(String fileExtension) throws
public boolean isVector() {
return vector;
}

@Override
protected boolean isBinary() {
return BINARY_FORMATS.contains(this.getMimeType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ public boolean supportsAlphaChannel() {
return supportsAlphaChannel;
}

@Override
protected boolean isBinary() {
return true;
}

public ImageWriter getImageWriter(RenderedImage image) {
Iterator<ImageWriter> it = javax.imageio.ImageIO.getImageWritersByFormatName(internalName);
ImageWriter writer = it.next();
Expand Down
16 changes: 16 additions & 0 deletions geowebcache/core/src/main/java/org/geowebcache/mime/MimeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ protected MimeType(
this.supportsTiling = supportsTiling;
}

/**
* Checks if mime type is a binary type
*
* @param value mime type
* @return true if mime type is binary
* @throws MimeException if mime type is not supported
*/
public static boolean isBinary(String value) throws MimeException {
MimeType mt = MimeType.createFromFormat(value);
return mt.isBinary();
}

protected boolean isBinary() {
return false;
}

/** The MIME identifier string for this format. */
public String getMimeType() {
return mimeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.geowebcache.grid.OutsideCoverageException;
import org.geowebcache.io.ByteArrayResource;
import org.geowebcache.io.Resource;
import org.geowebcache.layer.EmptyTileException;
import org.geowebcache.layer.TileLayer;
import org.geowebcache.layer.TileLayerDispatcher;
import org.geowebcache.mime.ImageMime;
Expand Down Expand Up @@ -103,6 +104,14 @@ public static void writeTile(
writeData(convTile, runtimeStats);

// Alternatively:
} catch (EmptyTileException e) {
writeEmpty(
defaultStorageFinder,
convTile,
e.getMessage(),
runtimeStats,
e.getMime().getMimeType(),
e.getContents());
} catch (OutsideCoverageException e) {
writeEmpty(defaultStorageFinder, convTile, e.getMessage(), runtimeStats);
}
Expand Down Expand Up @@ -171,15 +180,13 @@ private static void writeData(ConveyorTile tile, RuntimeStats runtimeStats) thro
servletResp, httpCode, mimeType, blob, cacheResult, contentLength, runtimeStats);
}

/**
* Writes a transparent, 8 bit PNG to avoid having clients like OpenLayers showing lots of pink
* tiles
*/
private static void writeEmpty(
DefaultStorageFinder defaultStorageFinder,
ConveyorTile tile,
String message,
RuntimeStats runtimeStats) {
RuntimeStats runtimeStats,
String mimeType,
ByteArrayResource emptyTileContents) {
tile.servletResp.setHeader("geowebcache-message", message);
TileLayer layer = tile.getLayer();
if (layer != null) {
Expand All @@ -196,15 +203,36 @@ private static void writeEmpty(
}
}

// handle no-content in case we have to return no result at all (e.g., expected for pbf)
int status = emptyTileContents == null ? 204 : 200;

writeFixedResponse(
tile.servletResp,
200,
ImageMime.png.getMimeType(),
loadBlankTile(defaultStorageFinder),
status,
mimeType,
emptyTileContents,
CacheResult.OTHER,
runtimeStats);
}

/**
* Writes a transparent, 8 bit PNG to avoid having clients like OpenLayers showing lots of pink
* tiles
*/
private static void writeEmpty(
DefaultStorageFinder defaultStorageFinder,
ConveyorTile tile,
String message,
RuntimeStats runtimeStats) {
writeEmpty(
defaultStorageFinder,
tile,
message,
runtimeStats,
ImageMime.png.getMimeType(),
loadBlankTile(defaultStorageFinder));
}

/**
* Helper method that writes an HTTP response setting the provided HTTP code.
*
Expand Down
19 changes: 19 additions & 0 deletions geowebcache/core/src/test/java/org/geowebcache/mime/MimeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.geowebcache.mime;

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

import org.junit.Test;

public class MimeTest {
// Test that static binary check matches the instance method
@Test
public void testIsBinary() throws Exception {
assertTrue(MimeType.isBinary(ImageMime.png.mimeType));
assertFalse(MimeType.isBinary(XMLMime.gml.mimeType));
for (MimeType mt : ApplicationMime.ALL) {
assertEquals(mt.isBinary(), MimeType.isBinary(mt.mimeType));
}
}
}
Loading