Skip to content

Commit

Permalink
[GWC-1101] Upgrade Spring Core to 5.3.23
Browse files Browse the repository at this point in the history
[GWC-1101] Upgrade Spring Core to 5.3.23

restored tests

cleanup

more test fixes

mimetype is binary check for content type

Update geowebcache/core/src/main/java/org/geowebcache/mime/ApplicationMime.java

Co-authored-by: Andrea Aime <[email protected]>

constant renaming

further spring upgrade
  • Loading branch information
aaime committed Feb 21, 2023
1 parent 30e258e commit ccf39ab
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 10 deletions.
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
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));
}
}
}
4 changes: 2 additions & 2 deletions geowebcache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<gt.version>29-SNAPSHOT</gt.version>
<jts.version>1.19.0</jts.version>
<jaiext.version>1.1.24</jaiext.version>
<spring.version>5.2.20.RELEASE</spring.version>
<spring.security.version>5.1.13.RELEASE</spring.security.version>
<spring.version>5.3.25</spring.version>
<spring.security.version>5.7.6</spring.security.version>
<xstream.version>1.4.11.1</xstream.version>
<commons-io.version>2.6</commons-io.version>
<commons-dbcp.version>1.4</commons-dbcp.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class MemoryCacheControllerTest {
MemoryCacheController mcc;

@Before
@SuppressWarnings(
"deprecation") // setUseSuffixPatternMatch is deprecated because Spring wants to
// discourage extensions in paths
public void setup() throws GeoWebCacheException {
GridSetBroker gridSetBroker =
new GridSetBroker(Collections.singletonList(new DefaultGridsets(false, false)));
Expand All @@ -57,7 +60,7 @@ public void setup() throws GeoWebCacheException {
xmlConfig.afterPropertiesSet();

mcc = new MemoryCacheController(null);
this.mockMvc = MockMvcBuilders.standaloneSetup(mcc).build();
this.mockMvc = MockMvcBuilders.standaloneSetup(mcc).setUseSuffixPatternMatch(true).build();
}

@Test
Expand All @@ -73,7 +76,7 @@ public void testStatisticsXml() throws Exception {
mbs.setCacheProvider(cache);

this.mockMvc
.perform(get("/rest/statistics.xml").contextPath(""))
.perform(get("/rest/statistics").accept("application/xml").contextPath(""))
.andExpect(status().is2xxSuccessful());
}

Expand All @@ -90,7 +93,7 @@ public void testStatisticsJson() throws Exception {
mbs.setCacheProvider(cache);

this.mockMvc
.perform(get("/rest/statistics.json").contextPath(""))
.perform(get("/rest/statistics").accept("application/json").contextPath(""))
.andExpect(status().is2xxSuccessful());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

<mvc:annotation-driven>
<bean id="antPathMatcher" class="org.springframework.util.AntPathMatcher" />
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="true" />
<property name="favorParameter" value="false"/>
<property name="ignoreAcceptHeader" value="true" />
</bean>
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:path-matching suffix-pattern="true" path-matcher="antPathMatcher"/>
<mvc:message-converters>
<bean id="gwcConverter" class="org.geowebcache.rest.converter.GWCConverter">
<constructor-arg ref="gwcAppCtx" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,6 @@ protected void writeResponse(HttpServletResponse response, RuntimeStats stats)

response.setStatus(HttpServletResponse.SC_OK);
response.setContentType(this.outputFormat.getMimeType());
response.setCharacterEncoding("UTF-8");

@SuppressWarnings("PMD.CloseResource") // managed by servlet container
ServletOutputStream os = response.getOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testGetCap() throws Exception {
MockHttpServletResponse resp = dispatch(req);

assertEquals(200, resp.getStatus());
assertEquals("text/xml", resp.getContentType());
assertEquals("text/xml;charset=UTF-8", resp.getContentType());
final Document doc = XMLUnit.buildTestDocument(resp.getContentAsString());
assertXpathExists("//wmts:Contents/wmts:Layer", doc);
assertXpathExists("//wmts:Contents/wmts:Layer[ows:Identifier='mockLayer']", doc);
Expand Down

0 comments on commit ccf39ab

Please sign in to comment.