Skip to content

Commit 61f14e8

Browse files
committed
Resolved the deprecated issues
1 parent 28950c8 commit 61f14e8

File tree

8 files changed

+38
-40
lines changed

8 files changed

+38
-40
lines changed

core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.springframework.http.HttpHeaders;
77
import org.springframework.http.HttpStatusCode;
88
import org.springframework.http.client.ClientHttpResponse;
9-
import org.springframework.util.StreamUtils;
109

1110
public class ErrorResponseClientHttpResponse implements ClientHttpResponse {
1211
private final Exception exception;
@@ -28,10 +27,11 @@ public HttpHeaders getHeaders() {
2827
@Override
2928
@Nonnull
3029
public InputStream getBody() {
31-
return StreamUtils.emptyInput();
30+
return InputStream.nullInputStream();
3231
}
3332

3433
@Override
34+
@Nonnull
3535
public HttpStatusCode getStatusCode() throws IOException {
3636
return FAKE_HTTP_ERROR_CODE;
3737
}

core/src/main/java/org/mapfish/print/http/HttpCredential.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.net.UnknownHostException;
77
import java.util.List;
88
import org.apache.hc.client5.http.auth.AuthScope;
9-
import org.apache.hc.client5.http.auth.Credentials;
109
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
1110
import org.mapfish.print.config.Configuration;
1211
import org.mapfish.print.config.ConfigurationObject;
@@ -94,7 +93,7 @@ public boolean matches(final MatchInfo matchInfo)
9493
* @param authscope the scope to test against.
9594
*/
9695
@Nullable
97-
public final Credentials toCredentials(final AuthScope authscope) {
96+
public final UsernamePasswordCredentials toCredentials(final AuthScope authscope) {
9897
try {
9998

10099
if (!matches(MatchInfo.fromAuthScope(authscope))) {

core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.hc.client5.http.SystemDefaultDnsResolver;
2121
import org.apache.hc.client5.http.classic.HttpClient;
2222
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
23+
import org.apache.hc.client5.http.config.ConnectionConfig;
2324
import org.apache.hc.client5.http.config.RequestConfig;
2425
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
2526
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
@@ -97,7 +98,6 @@ private static CloseableHttpClient createHttpClient(
9798
final RequestConfig requestConfig =
9899
RequestConfig.custom()
99100
.setConnectionRequestTimeout(connectionRequestTimeout, TimeUnit.MILLISECONDS)
100-
.setConnectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
101101
.setResponseTimeout(socketTimeout, TimeUnit.MILLISECONDS)
102102
.build();
103103

@@ -106,6 +106,10 @@ private static CloseableHttpClient createHttpClient(
106106
.disableCookieManagement()
107107
.setConnectionManager(
108108
PoolingHttpClientConnectionManagerBuilder.create()
109+
.setDefaultConnectionConfig(
110+
ConnectionConfig.custom()
111+
.setConnectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
112+
.build())
109113
.setTlsSocketStrategy(new MfTLSSocketStrategy())
110114
.setDnsResolver(new RandomizingDnsResolver())
111115
.setMaxConnPerRoute(maxConnTotal)
@@ -238,9 +242,7 @@ protected Response executeInternal(@Nonnull final HttpHeaders headers) throws IO
238242
new ByteArrayEntity(bytes, ContentType.APPLICATION_OCTET_STREAM);
239243
entityEnclosingRequest.setEntity(requestEntity);
240244
}
241-
242-
ClassicHttpResponse response =
243-
(ClassicHttpResponse) this.client.execute(this.request, this.context);
245+
ClassicHttpResponse response = this.client.executeOpen(null, this.request, this.context);
244246
LOGGER.debug("Response: {} -- {}", response.getCode(), this.getURI());
245247

246248
return new Response(response);
@@ -274,16 +276,16 @@ public String getStatusText() {
274276
@Override
275277
public void close() {
276278
try {
277-
getBody();
278279
if (inputStream != null) {
279280
inputStream.close();
280-
inputStream = null;
281281
}
282+
this.response.close();
282283
} catch (IOException e) {
283284
LOGGER.error(
284285
"Error occurred while trying to retrieve Http Response {} in order to close it.",
285286
this.id,
286287
e);
288+
} finally {
287289
inputStream = null;
288290
}
289291
LOGGER.trace("Closed Http Response object: {}", this.id);

core/src/main/java/org/mapfish/print/map/image/wms/WmsUtilities.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import java.util.Collections;
1515
import java.util.List;
1616
import org.apache.commons.lang3.StringUtils;
17-
import org.apache.hc.core5.net.URLEncodedUtils;
1817
import org.apache.hc.core5.http.NameValuePair;
18+
import org.apache.hc.core5.net.URIBuilder;
1919
import org.geotools.api.referencing.FactoryException;
2020
import org.geotools.geometry.jts.ReferencedEnvelope;
2121
import org.geotools.ows.wms.request.GetMapRequest;
@@ -73,7 +73,7 @@ public static URI makeWmsGetLayerRequest(
7373

7474
Multimap<String, String> extraParams = HashMultimap.create();
7575
if (commonURI.getQuery() != null) {
76-
for (NameValuePair pair : URLEncodedUtils.parse(commonURI, StandardCharsets.UTF_8)) {
76+
for (NameValuePair pair : new URIBuilder(commonURI).getQueryParams()) {
7777
extraParams.put(pair.getName(), pair.getValue());
7878
}
7979
}
@@ -201,14 +201,14 @@ public static ClientHttpRequest createWmsRequest(
201201
final URI paramlessUri;
202202
try {
203203
paramlessUri =
204-
new URI(
205-
uri.getScheme(),
206-
uri.getUserInfo(),
207-
uri.getHost(),
208-
uri.getPort(),
209-
uri.getPath(),
210-
null,
211-
null);
204+
new URI(
205+
uri.getScheme(),
206+
uri.getUserInfo(),
207+
uri.getHost(),
208+
uri.getPort(),
209+
uri.getPath(),
210+
null,
211+
null);
212212
} catch (URISyntaxException e) {
213213
throw new RuntimeException(e);
214214
}

core/src/main/java/org/mapfish/print/servlet/job/HibernateAccounting.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.mapfish.print.servlet.job;
22

3-
import jakarta.annotation.Nonnull;
43
import org.hibernate.HibernateException;
54
import org.hibernate.Session;
65
import org.hibernate.SessionFactory;
@@ -10,8 +9,6 @@
109
import org.slf4j.LoggerFactory;
1110
import org.springframework.beans.factory.annotation.Autowired;
1211
import org.springframework.transaction.PlatformTransactionManager;
13-
import org.springframework.transaction.TransactionStatus;
14-
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
1512
import org.springframework.transaction.support.TransactionTemplate;
1613

1714
/** Store accounting info in the DB. */
@@ -73,15 +70,12 @@ private void insertRecord(final HibernateAccountingEntry tuple) {
7370
try {
7471
final TransactionTemplate tmpl =
7572
new TransactionTemplate(HibernateAccounting.this.txManager);
76-
tmpl.execute(
77-
new TransactionCallbackWithoutResult() {
78-
@Override
79-
protected void doInTransactionWithoutResult(@Nonnull final TransactionStatus status) {
80-
final Session currentSession = HibernateAccounting.this.sf.getCurrentSession();
81-
currentSession.merge(tuple);
82-
currentSession.flush();
83-
currentSession.evict(tuple);
84-
}
73+
tmpl.executeWithoutResult(
74+
(status) -> {
75+
final Session currentSession = HibernateAccounting.this.sf.getCurrentSession();
76+
currentSession.merge(tuple);
77+
currentSession.flush();
78+
currentSession.evict(tuple);
8579
});
8680
} catch (HibernateException ex) {
8781
unhealthyCountersHealthCheck.recordUnhealthyProblem(

core/src/main/java/org/mapfish/print/servlet/job/impl/hibernate/PrintJobDao.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public final void cancelOld(
164164
builder.lessThan(root.get("lastCheckTime"), checkTimeThreshold)))));
165165
update.set(root.get("status"), PrintJobStatus.Status.CANCELED);
166166
update.set(root.get("error"), message);
167-
getSession().createQuery(update).executeUpdate();
167+
getSession().createMutationQuery(update).executeUpdate();
168168
}
169169

170170
/**
@@ -180,7 +180,7 @@ public final void updateLastCheckTime(final String id, final long lastCheckTime)
180180
final Root<PrintJobStatusExtImpl> root = update.from(PrintJobStatusExtImpl.class);
181181
update.where(builder.equal(root.get("referenceId"), id));
182182
update.set(root.get("lastCheckTime"), lastCheckTime);
183-
getSession().createQuery(update).executeUpdate();
183+
getSession().createMutationQuery(update).executeUpdate();
184184
}
185185

186186
/**
@@ -198,7 +198,7 @@ public final int deleteOld(final long checkTimeThreshold) {
198198
builder.and(
199199
builder.isNotNull(root.get("lastCheckTime")),
200200
builder.lessThan(root.get("lastCheckTime"), checkTimeThreshold)));
201-
return getSession().createQuery(delete).executeUpdate();
201+
return getSession().createMutationQuery(delete).executeUpdate();
202202
}
203203

204204
/**
@@ -255,6 +255,6 @@ public void delete(final String referenceId) {
255255
builder.createCriteriaDelete(PrintJobStatusExtImpl.class);
256256
final Root<PrintJobStatusExtImpl> root = delete.from(PrintJobStatusExtImpl.class);
257257
delete.where(builder.equal(root.get("referenceId"), referenceId));
258-
getSession().createQuery(delete).executeUpdate();
258+
getSession().createMutationQuery(delete).executeUpdate();
259259
}
260260
}

core/src/test/java/org/mapfish/print/http/HttpCredentialTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.Collections;
88
import java.util.List;
99
import org.apache.hc.client5.http.auth.AuthScope;
10-
import org.apache.hc.client5.http.auth.Credentials;
10+
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
1111
import org.junit.jupiter.api.AfterAll;
1212
import org.junit.jupiter.api.BeforeAll;
1313
import org.junit.jupiter.api.Test;
@@ -77,10 +77,10 @@ public void testToCredentials() throws Exception {
7777
credential.setMatchers(Collections.singletonList(matcher));
7878

7979
AuthScope authscope = new AuthScope(null, -1);
80-
final Credentials object = credential.toCredentials(authscope);
80+
final UsernamePasswordCredentials object = credential.toCredentials(authscope);
8181
assertNotNull(object);
8282
assertEquals(USERNAME, object.getUserPrincipal().getName());
83-
assertEquals(PASSWORD, new String(object.getPassword()));
83+
assertEquals(PASSWORD, new String(object.getUserPassword()));
8484

8585
authscope =
8686
new AuthScope(

core/src/test/java/org/mapfish/print/http/HttpProxyTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.io.File;
1313
import java.io.FileInputStream;
1414
import java.io.IOException;
15+
import java.io.OutputStream;
1516
import java.net.InetSocketAddress;
1617
import java.net.URI;
1718
import java.security.KeyManagementException;
@@ -160,7 +161,9 @@ public static void respond(HttpExchange httpExchange, String errorMessage, int r
160161
throws IOException {
161162
final byte[] bytes = errorMessage.getBytes(Constants.DEFAULT_CHARSET);
162163
httpExchange.sendResponseHeaders(responseCode, bytes.length);
163-
httpExchange.getResponseBody().write(bytes);
164+
try (OutputStream os = httpExchange.getResponseBody()) {
165+
os.write(bytes);
166+
}
164167
httpExchange.close();
165168
}
166169

0 commit comments

Comments
 (0)