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 @@ -21,7 +21,6 @@
import org.geotools.util.logging.Logging;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.PlaceholderConfigurerSupport;
import org.springframework.core.Constants;
import org.springframework.util.PropertyPlaceholderHelper;

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

private static final Constants constants = new Constants(PlaceholderConfigurerSupport.class);

/**
* Constant set via System Environment in order to instruct GeoWebCache to make use or not of the config
* placeholders translation.
Expand All @@ -65,9 +62,10 @@ public class GeoWebCacheEnvironment {
private static final String nullValue = "null";

private final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
constants.asString("DEFAULT_PLACEHOLDER_PREFIX"),
constants.asString("DEFAULT_PLACEHOLDER_SUFFIX"),
constants.asString("DEFAULT_VALUE_SEPARATOR"),
PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX,
PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX,
PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR,
null,
true);

private Properties props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,44 +117,45 @@ protected BufferedImage loadMatrix(TileLayer tlayer, String gridSetId, int z)
backendTimeout = 120;
}

ClassicHttpResponse httpResponse = null;
BufferedImage img = null;

httpResponse = srcHelper.executeRequest(wmsUrl, requestParams, backendTimeout, WMSLayer.HttpRequestMode.Get);
try (ClassicHttpResponse httpResponse =
srcHelper.executeRequest(wmsUrl, requestParams, backendTimeout, WMSLayer.HttpRequestMode.Get)) {

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

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

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

InputStream is = new ByteArrayInputStream(ret);
InputStream is = new ByteArrayInputStream(ret);

img = ImageIO.read(is);
img = ImageIO.read(is);

if (img.getWidth() != widthHeight[0] || img.getHeight() != widthHeight[1]) {
String msg = "WMS raster filter has dimensions "
+ img.getWidth()
+ ","
+ img.getHeight()
+ ", expected "
+ widthHeight[0]
+ ","
+ widthHeight[1]
+ "\n";
throw new GeoWebCacheException(msg);
}
if (img.getWidth() != widthHeight[0] || img.getHeight() != widthHeight[1]) {
String msg = "WMS raster filter has dimensions "
+ img.getWidth()
+ ","
+ img.getHeight()
+ ", expected "
+ widthHeight[0]
+ ","
+ widthHeight[1]
+ "\n";
throw new GeoWebCacheException(msg);
}

return img;
return img;
}
}

/** Generates the URL used to create the lookup raster */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.io.entity.StringEntity;
Expand Down Expand Up @@ -378,7 +377,8 @@ public ClassicHttpResponse executeRequest(
if (httpRequestMode == WMSLayer.HttpRequestMode.FormPost) {
HttpPost pm = new HttpPost(urlString);
if (queryParams != null && !queryParams.isEmpty()) {
HttpEntity requestEntity = new StringEntity(processRequestParameters(queryParams));
@SuppressWarnings("PMD.CloseResource")
StringEntity requestEntity = new StringEntity(processRequestParameters(queryParams));
pm.setEntity(requestEntity);
}
method = pm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ public void proxyRequest(ConveyorTile tile) throws GeoWebCacheException {
String queryStr = tile.servletReq.getQueryString();
String serverStr = getWMSurl()[0];

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

httpResponse =
((WMSHttpHelper) helper).executeRequest(url, null, getBackendTimeout(), getHttpRequestMode());
HttpEntity entity = httpResponse.getEntity();
try (InputStream is = entity.getContent()) {
HttpServletResponse response = tile.servletResp;
org.apache.hc.core5.http.Header contentType = httpResponse.getFirstHeader("Content-Type");
if (contentType != null) {
response.setContentType(contentType.getValue());
String contentEncoding = entity.getContentEncoding();
if (!MimeType.isBinary(contentType.getValue())) {
response.setCharacterEncoding(contentEncoding);
try (ClassicHttpResponse httpResponse =
((WMSHttpHelper) helper).executeRequest(url, null, getBackendTimeout(), getHttpRequestMode())) {
HttpEntity entity = httpResponse.getEntity();
try (InputStream is = entity.getContent()) {
HttpServletResponse response = tile.servletResp;
org.apache.hc.core5.http.Header contentType = httpResponse.getFirstHeader("Content-Type");
if (contentType != null) {
response.setContentType(contentType.getValue());
String contentEncoding = entity.getContentEncoding();
if (!MimeType.isBinary(contentType.getValue())) {
response.setCharacterEncoding(contentEncoding);
}
}
}

int read = 0;
byte[] data = new byte[1024];
int read = 0;
byte[] data = new byte[1024];

while (read > -1) {
read = is.read(data);
if (read > -1) {
response.getOutputStream().write(data, 0, read);
while (read > -1) {
read = is.read(data);
if (read > -1) {
response.getOutputStream().write(data, 0, read);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public MetastoreRemover(DefaultStorageFinder finder) throws Exception {
try (Connection conn = getMetaStoreConnection(root)) {
if (conn != null) {
log.info("Migrating the old metastore to filesystem storage");
@SuppressWarnings("PMD.CloseResource")
SingleConnectionDataSource ds = new SingleConnectionDataSource(conn, false);
JdbcTemplate template = new JdbcTemplate(ds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.logging.Logger;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.StandardCookieSpec;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
Expand Down Expand Up @@ -66,16 +67,22 @@ public HttpClientBuilder(
.setCookieSpec(StandardCookieSpec.RELAXED)
.setExpectContinueEnabled(true)
.setResponseTimeout(backendTimeoutMillis, TimeUnit.MILLISECONDS)
.setConnectTimeout(backendTimeoutMillis, TimeUnit.MILLISECONDS)
.setRedirectsEnabled(true)
.build());

ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setConnectTimeout(backendTimeoutMillis, TimeUnit.MILLISECONDS)
.build();

@SuppressWarnings("PMD.CloseResource")
PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setMaxConnTotal(concurrency)
.setDefaultConnectionConfig(connectionConfig)
.build();

clientBuilder = HttpClients.custom();
clientBuilder.useSystemProperties();
clientBuilder.setDefaultRequestConfig(this.connectionConfig);
clientBuilder.setConnectionManager(connectionManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ private static void writeData(ConveyorTile tile, RuntimeStats runtimeStats) thro
// (e.g. 'Sun, 06 Nov 1994 08:49:37 GMT'). See
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1

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

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

ifModifiedSince = DateUtils.parseDate(ifModSinceHeader);
ifModifiedSince = Date.from(DateUtils.parseStandardDate(ifModSinceHeader));
// the HTTP header has second precision
long ifModSinceSeconds = 1000 * (ifModifiedSince.getTime() / 1000);
long tileTimeStampSeconds = 1000 * (tileTimeStamp / 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
* @author Gabriel Roldan (OpenGeo)
* @version $Id$
*/
@SuppressWarnings("PMD.CloseResource")
public class WMSLayerTest extends TileLayerTest {

private final GridSetBroker gridSetBroker =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.geowebcache.util.SuppressFBWarnings;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DeadlockLoserDataAccessException;
import org.springframework.dao.PessimisticLockingFailureException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionStatus;
Expand Down Expand Up @@ -506,7 +506,7 @@ private void upsertTilePageFillFactor(PageStatsPayload payload) {

modified = createNewPageStats(stats, page);
}
} catch (DeadlockLoserDataAccessException e) {
} catch (PessimisticLockingFailureException e) {
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Deadlock while updating page stats, will retry", e);
}
Expand Down Expand Up @@ -871,7 +871,7 @@ private PageStats upsertTilePageHitAccessTime(PageStatsPayload payload) {
updatePageStats(payload, page, stats);
modified = createNewPageStats(stats, page);
}
} catch (DeadlockLoserDataAccessException e) {
} catch (PessimisticLockingFailureException e) {
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "Deadlock while updating page stats, will retry", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ public GeoRSSReader createReader(final URL url, final String username, final Str
builder.setHttpCredentials(username, password, url);
builder.setBackendTimeout(120);

CloseableHttpClient httpClient = builder.buildClient();
try (CloseableHttpClient httpClient = builder.buildClient()) {

HttpGet getMethod = new HttpGet(url.toString());

if (log.isLoggable(Level.FINE)) {
log.fine("Executing HTTP GET requesr for feed URL " + url.toExternalForm());
}

try {
ClassicHttpResponse response = httpClient.executeOpen(determineHost(getMethod), getMethod, null);
HttpGet getMethod = new HttpGet(url.toString());

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

Reader reader = new BufferedReader(
new InputStreamReader(response.getEntity().getContent(), contentEncoding));
if (log.isLoggable(Level.FINE)) {
log.fine("GeoRSS reader created, returning.");
try (ClassicHttpResponse response = httpClient.executeOpen(determineHost(getMethod), getMethod, null)) {

if (log.isLoggable(Level.FINE)) {
log.fine("Building GeoRSS reader out of URL response");
}
String contentEncoding = response.getEntity().getContentEncoding();
if (contentEncoding == null) {
contentEncoding = "UTF-8";
}

Reader reader = new BufferedReader(
new InputStreamReader(response.getEntity().getContent(), contentEncoding));
if (log.isLoggable(Level.FINE)) {
log.fine("GeoRSS reader created, returning.");
}
return createReader(reader);
}
return createReader(reader);
} catch (HttpException e) {
throw new IOException(e);
}
Expand Down
Loading
Loading