Skip to content

Commit 73f6e9d

Browse files
committed
Pass QA on GWC Spring/Jakarta migration
1 parent 0ab8f4e commit 73f6e9d

File tree

11 files changed

+188
-183
lines changed

11 files changed

+188
-183
lines changed

geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheEnvironment.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.geotools.util.logging.Logging;
2222
import org.springframework.beans.BeansException;
2323
import org.springframework.beans.factory.config.PlaceholderConfigurerSupport;
24-
import org.springframework.core.Constants;
2524
import org.springframework.util.PropertyPlaceholderHelper;
2625

2726
/**
@@ -47,8 +46,6 @@ public class GeoWebCacheEnvironment {
4746
/** logger */
4847
public static final Logger LOGGER = Logging.getLogger(GeoWebCacheEnvironment.class.getName());
4948

50-
private static final Constants constants = new Constants(PlaceholderConfigurerSupport.class);
51-
5249
/**
5350
* Constant set via System Environment in order to instruct GeoWebCache to make use or not of the config
5451
* placeholders translation.
@@ -65,9 +62,10 @@ public class GeoWebCacheEnvironment {
6562
private static final String nullValue = "null";
6663

6764
private final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
68-
constants.asString("DEFAULT_PLACEHOLDER_PREFIX"),
69-
constants.asString("DEFAULT_PLACEHOLDER_SUFFIX"),
70-
constants.asString("DEFAULT_VALUE_SEPARATOR"),
65+
PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX,
66+
PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX,
67+
PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR,
68+
null,
7169
true);
7270

7371
private Properties props;

geowebcache/core/src/main/java/org/geowebcache/filter/request/WMSRasterFilter.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,44 +117,45 @@ protected BufferedImage loadMatrix(TileLayer tlayer, String gridSetId, int z)
117117
backendTimeout = 120;
118118
}
119119

120-
ClassicHttpResponse httpResponse = null;
121120
BufferedImage img = null;
122121

123-
httpResponse = srcHelper.executeRequest(wmsUrl, requestParams, backendTimeout, WMSLayer.HttpRequestMode.Get);
122+
try (ClassicHttpResponse httpResponse =
123+
srcHelper.executeRequest(wmsUrl, requestParams, backendTimeout, WMSLayer.HttpRequestMode.Get)) {
124124

125-
int statusCode = httpResponse.getCode();
126-
if (statusCode != 200) {
127-
throw new GeoWebCacheException("Received response code " + statusCode + "\n");
128-
}
125+
int statusCode = httpResponse.getCode();
126+
if (statusCode != 200) {
127+
throw new GeoWebCacheException("Received response code " + statusCode + "\n");
128+
}
129129

130-
if (!httpResponse.getFirstHeader("Content-Type").getValue().startsWith("image/")) {
131-
throw new GeoWebCacheException("Unexpected response content type "
132-
+ httpResponse.getFirstHeader("Content-Type").getValue()
133-
+ " , request was "
134-
+ urlStr
135-
+ "\n");
136-
}
130+
if (!httpResponse.getFirstHeader("Content-Type").getValue().startsWith("image/")) {
131+
throw new GeoWebCacheException("Unexpected response content type "
132+
+ httpResponse.getFirstHeader("Content-Type").getValue()
133+
+ " , request was "
134+
+ urlStr
135+
+ "\n");
136+
}
137137

138-
byte[] ret = ServletUtils.readStream(httpResponse.getEntity().getContent(), 16384, 2048);
138+
byte[] ret = ServletUtils.readStream(httpResponse.getEntity().getContent(), 16384, 2048);
139139

140-
InputStream is = new ByteArrayInputStream(ret);
140+
InputStream is = new ByteArrayInputStream(ret);
141141

142-
img = ImageIO.read(is);
142+
img = ImageIO.read(is);
143143

144-
if (img.getWidth() != widthHeight[0] || img.getHeight() != widthHeight[1]) {
145-
String msg = "WMS raster filter has dimensions "
146-
+ img.getWidth()
147-
+ ","
148-
+ img.getHeight()
149-
+ ", expected "
150-
+ widthHeight[0]
151-
+ ","
152-
+ widthHeight[1]
153-
+ "\n";
154-
throw new GeoWebCacheException(msg);
155-
}
144+
if (img.getWidth() != widthHeight[0] || img.getHeight() != widthHeight[1]) {
145+
String msg = "WMS raster filter has dimensions "
146+
+ img.getWidth()
147+
+ ","
148+
+ img.getHeight()
149+
+ ", expected "
150+
+ widthHeight[0]
151+
+ ","
152+
+ widthHeight[1]
153+
+ "\n";
154+
throw new GeoWebCacheException(msg);
155+
}
156156

157-
return img;
157+
return img;
158+
}
158159
}
159160

160161
/** Generates the URL used to create the lookup raster */

geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSHttpHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
3535
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
3636
import org.apache.hc.core5.http.ClassicHttpResponse;
37-
import org.apache.hc.core5.http.HttpEntity;
3837
import org.apache.hc.core5.http.HttpException;
3938
import org.apache.hc.core5.http.NameValuePair;
4039
import org.apache.hc.core5.http.io.entity.StringEntity;
@@ -378,7 +377,8 @@ public ClassicHttpResponse executeRequest(
378377
if (httpRequestMode == WMSLayer.HttpRequestMode.FormPost) {
379378
HttpPost pm = new HttpPost(urlString);
380379
if (queryParams != null && !queryParams.isEmpty()) {
381-
HttpEntity requestEntity = new StringEntity(processRequestParameters(queryParams));
380+
@SuppressWarnings("PMD.CloseResource")
381+
StringEntity requestEntity = new StringEntity(processRequestParameters(queryParams));
382382
pm.setEntity(requestEntity);
383383
}
384384
method = pm;

geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSLayer.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ public void proxyRequest(ConveyorTile tile) throws GeoWebCacheException {
780780
String queryStr = tile.servletReq.getQueryString();
781781
String serverStr = getWMSurl()[0];
782782

783-
ClassicHttpResponse httpResponse = null;
784783
try {
785784
URL url;
786785
if (serverStr.contains("?")) {
@@ -794,27 +793,28 @@ public void proxyRequest(ConveyorTile tile) throws GeoWebCacheException {
794793
throw new GeoWebCacheException("Can only proxy if WMS Layer is backed by an HTTP backend");
795794
}
796795

797-
httpResponse =
798-
((WMSHttpHelper) helper).executeRequest(url, null, getBackendTimeout(), getHttpRequestMode());
799-
HttpEntity entity = httpResponse.getEntity();
800-
try (InputStream is = entity.getContent()) {
801-
HttpServletResponse response = tile.servletResp;
802-
org.apache.hc.core5.http.Header contentType = httpResponse.getFirstHeader("Content-Type");
803-
if (contentType != null) {
804-
response.setContentType(contentType.getValue());
805-
String contentEncoding = entity.getContentEncoding();
806-
if (!MimeType.isBinary(contentType.getValue())) {
807-
response.setCharacterEncoding(contentEncoding);
796+
try (ClassicHttpResponse httpResponse =
797+
((WMSHttpHelper) helper).executeRequest(url, null, getBackendTimeout(), getHttpRequestMode())) {
798+
HttpEntity entity = httpResponse.getEntity();
799+
try (InputStream is = entity.getContent()) {
800+
HttpServletResponse response = tile.servletResp;
801+
org.apache.hc.core5.http.Header contentType = httpResponse.getFirstHeader("Content-Type");
802+
if (contentType != null) {
803+
response.setContentType(contentType.getValue());
804+
String contentEncoding = entity.getContentEncoding();
805+
if (!MimeType.isBinary(contentType.getValue())) {
806+
response.setCharacterEncoding(contentEncoding);
807+
}
808808
}
809-
}
810809

811-
int read = 0;
812-
byte[] data = new byte[1024];
810+
int read = 0;
811+
byte[] data = new byte[1024];
813812

814-
while (read > -1) {
815-
read = is.read(data);
816-
if (read > -1) {
817-
response.getOutputStream().write(data, 0, read);
813+
while (read > -1) {
814+
read = is.read(data);
815+
if (read > -1) {
816+
response.getOutputStream().write(data, 0, read);
817+
}
818818
}
819819
}
820820
}

geowebcache/core/src/main/java/org/geowebcache/storage/MetastoreRemover.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public MetastoreRemover(DefaultStorageFinder finder) throws Exception {
5757
try (Connection conn = getMetaStoreConnection(root)) {
5858
if (conn != null) {
5959
log.info("Migrating the old metastore to filesystem storage");
60+
@SuppressWarnings("PMD.CloseResource")
6061
SingleConnectionDataSource ds = new SingleConnectionDataSource(conn, false);
6162
JdbcTemplate template = new JdbcTemplate(ds);
6263

geowebcache/core/src/main/java/org/geowebcache/util/HttpClientBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.logging.Logger;
1919
import org.apache.hc.client5.http.auth.AuthScope;
2020
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
21+
import org.apache.hc.client5.http.config.ConnectionConfig;
2122
import org.apache.hc.client5.http.config.RequestConfig;
2223
import org.apache.hc.client5.http.cookie.StandardCookieSpec;
2324
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
@@ -66,16 +67,22 @@ public HttpClientBuilder(
6667
.setCookieSpec(StandardCookieSpec.RELAXED)
6768
.setExpectContinueEnabled(true)
6869
.setResponseTimeout(backendTimeoutMillis, TimeUnit.MILLISECONDS)
69-
.setConnectTimeout(backendTimeoutMillis, TimeUnit.MILLISECONDS)
7070
.setRedirectsEnabled(true)
7171
.build());
7272

73+
ConnectionConfig connectionConfig = ConnectionConfig.custom()
74+
.setConnectTimeout(backendTimeoutMillis, TimeUnit.MILLISECONDS)
75+
.build();
76+
77+
@SuppressWarnings("PMD.CloseResource")
7378
PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
7479
.setMaxConnTotal(concurrency)
80+
.setDefaultConnectionConfig(connectionConfig)
7581
.build();
7682

7783
clientBuilder = HttpClients.custom();
7884
clientBuilder.useSystemProperties();
85+
clientBuilder.setDefaultRequestConfig(this.connectionConfig);
7986
clientBuilder.setConnectionManager(connectionManager);
8087
}
8188

geowebcache/core/src/main/java/org/geowebcache/util/ResponseUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ private static void writeData(ConveyorTile tile, RuntimeStats runtimeStats) thro
142142
// (e.g. 'Sun, 06 Nov 1994 08:49:37 GMT'). See
143143
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
144144

145-
final String lastModified = DateUtils.formatDate(new Date(tileTimeStamp));
145+
final String lastModified = DateUtils.formatStandardDate(new Date(tileTimeStamp).toInstant());
146146
servletResp.setHeader("Last-Modified", lastModified);
147147

148148
final Date ifModifiedSince;
149149
if (ifModSinceHeader != null && ifModSinceHeader.length() > 0) {
150150

151-
ifModifiedSince = DateUtils.parseDate(ifModSinceHeader);
151+
ifModifiedSince = Date.from(DateUtils.parseStandardDate(ifModSinceHeader));
152152
// the HTTP header has second precision
153153
long ifModSinceSeconds = 1000 * (ifModifiedSince.getTime() / 1000);
154154
long tileTimeStampSeconds = 1000 * (tileTimeStamp / 1000);

geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
* @author Gabriel Roldan (OpenGeo)
109109
* @version $Id$
110110
*/
111+
@SuppressWarnings("PMD.CloseResource")
111112
public class WMSLayerTest extends TileLayerTest {
112113

113114
private final GridSetBroker gridSetBroker =

geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import org.geowebcache.util.SuppressFBWarnings;
4747
import org.springframework.dao.ConcurrencyFailureException;
4848
import org.springframework.dao.DataAccessException;
49-
import org.springframework.dao.DeadlockLoserDataAccessException;
49+
import org.springframework.dao.PessimisticLockingFailureException;
5050
import org.springframework.jdbc.core.RowMapper;
5151
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
5252
import org.springframework.transaction.TransactionStatus;
@@ -506,7 +506,7 @@ private void upsertTilePageFillFactor(PageStatsPayload payload) {
506506

507507
modified = createNewPageStats(stats, page);
508508
}
509-
} catch (DeadlockLoserDataAccessException e) {
509+
} catch (PessimisticLockingFailureException e) {
510510
if (log.isLoggable(Level.FINE)) {
511511
log.log(Level.FINE, "Deadlock while updating page stats, will retry", e);
512512
}
@@ -871,7 +871,7 @@ private PageStats upsertTilePageHitAccessTime(PageStatsPayload payload) {
871871
updatePageStats(payload, page, stats);
872872
modified = createNewPageStats(stats, page);
873873
}
874-
} catch (DeadlockLoserDataAccessException e) {
874+
} catch (PessimisticLockingFailureException e) {
875875
if (log.isLoggable(Level.FINE)) {
876876
log.log(Level.FINE, "Deadlock while updating page stats, will retry", e);
877877
}

geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSReaderFactory.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,31 @@ public GeoRSSReader createReader(final URL url, final String username, final Str
4545
builder.setHttpCredentials(username, password, url);
4646
builder.setBackendTimeout(120);
4747

48-
CloseableHttpClient httpClient = builder.buildClient();
48+
try (CloseableHttpClient httpClient = builder.buildClient()) {
4949

50-
HttpGet getMethod = new HttpGet(url.toString());
51-
52-
if (log.isLoggable(Level.FINE)) {
53-
log.fine("Executing HTTP GET requesr for feed URL " + url.toExternalForm());
54-
}
55-
56-
try {
57-
ClassicHttpResponse response = httpClient.executeOpen(determineHost(getMethod), getMethod, null);
50+
HttpGet getMethod = new HttpGet(url.toString());
5851

5952
if (log.isLoggable(Level.FINE)) {
60-
log.fine("Building GeoRSS reader out of URL response");
61-
}
62-
String contentEncoding = response.getEntity().getContentEncoding();
63-
if (contentEncoding == null) {
64-
contentEncoding = "UTF-8";
53+
log.fine("Executing HTTP GET requesr for feed URL " + url.toExternalForm());
6554
}
6655

67-
Reader reader = new BufferedReader(
68-
new InputStreamReader(response.getEntity().getContent(), contentEncoding));
69-
if (log.isLoggable(Level.FINE)) {
70-
log.fine("GeoRSS reader created, returning.");
56+
try (ClassicHttpResponse response = httpClient.executeOpen(determineHost(getMethod), getMethod, null)) {
57+
58+
if (log.isLoggable(Level.FINE)) {
59+
log.fine("Building GeoRSS reader out of URL response");
60+
}
61+
String contentEncoding = response.getEntity().getContentEncoding();
62+
if (contentEncoding == null) {
63+
contentEncoding = "UTF-8";
64+
}
65+
66+
Reader reader = new BufferedReader(
67+
new InputStreamReader(response.getEntity().getContent(), contentEncoding));
68+
if (log.isLoggable(Level.FINE)) {
69+
log.fine("GeoRSS reader created, returning.");
70+
}
71+
return createReader(reader);
7172
}
72-
return createReader(reader);
7373
} catch (HttpException e) {
7474
throw new IOException(e);
7575
}

0 commit comments

Comments
 (0)