Skip to content

Commit 145d718

Browse files
authored
GEODE-10534: Fix Deprecated APIs in Support Modules (geode-management, geode-serialization, geode-deployment-legacy, geode-web-api) (#7983)
* GEODE-10534: Module 1: geode-management RestTemplateClusterManagementServiceTransport.java ○ Update RestTemplateClusterManagementServiceTransport to remove deprecated API usage ○ Replaced deprecated SSLConnectionSocketFactory with DefaultClientTlsStrategy and setSSLSocketFactory with setTlsSocketStrategy Issue 1.2: Apache Commons Lang StringUtils Index.java Updated removeStart with string manipulation code Module 2: geode-serialization DSFIDSerializerImpl.java Updated deprecated getProxyClass with newProxyInstance with a no-op handler Module 3: geode-deployment-legacy LegacyClasspathServiceImpl.java Refactor proxy class creation to avoid deprecated Proxy.getProxyClass usage Replaced usage of deprecated Proxy.getProxyClass with Proxy.newProxyInstance to obtain proxy class Module 4: geode-web-api SwaggerConfig.java No changes, can be updated when we move to Spring Framework 6.2+ with UrlHandlerFilter * Update DSFIDSerializerImpl.java fixed space format issue
1 parent ec974dd commit 145d718

5 files changed

Lines changed: 28 additions & 9 deletions

File tree

geode-deployment/geode-deployment-legacy/src/main/java/org/apache/geode/classloader/internal/LegacyClasspathServiceImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.io.InputStream;
24+
import java.lang.reflect.InvocationHandler;
25+
import java.lang.reflect.Method;
2426
import java.lang.reflect.Proxy;
2527
import java.net.MalformedURLException;
2628
import java.net.URL;
@@ -232,7 +234,17 @@ public Class<?> getProxyClass(final Class<?>... classObjs) {
232234

233235
for (ClassLoader classLoader : getClassLoaders()) {
234236
try {
235-
return Proxy.getProxyClass(classLoader, classObjs);
237+
// Proxy.getProxyClass is deprecated, so use the recommended way to create a proxy class.
238+
// Only used to get the proxy class, so the handler can be a no-op.
239+
InvocationHandler invocationHandler = new InvocationHandler() {
240+
@Override
241+
public Object invoke(Object proxy, Method method, Object[] methodArgs) {
242+
return null;
243+
}
244+
};
245+
// create a new Proxy instance to get the proxy class
246+
Object proxy = Proxy.newProxyInstance(classLoader, classObjs, invocationHandler);
247+
return proxy.getClass();
236248
} catch (SecurityException sex) {
237249
// Continue to next classloader
238250
} catch (IllegalArgumentException iaex) {

geode-management/src/main/java/org/apache/geode/management/api/RestTemplateClusterManagementServiceTransport.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
3131
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
3232
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
33-
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
33+
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
3434
import org.springframework.core.io.FileSystemResource;
3535
import org.springframework.http.HttpEntity;
3636
import org.springframework.http.HttpHeaders;
@@ -164,27 +164,27 @@ public void configureConnection(ConnectionConfig connectionConfig) {
164164
// Configure SSL context and hostname verifier (HttpClient 5.x approach)
165165
// Only configure SSL if we have a non-null SSL context
166166
if (connectionConfig.getSslContext() != null) {
167-
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
167+
DefaultClientTlsStrategy sslSocketFactory = new DefaultClientTlsStrategy(
168168
connectionConfig.getSslContext(),
169169
connectionConfig.getHostnameVerifier());
170170

171171
HttpClientConnectionManager connectionManager =
172172
PoolingHttpClientConnectionManagerBuilder.create()
173-
.setSSLSocketFactory(sslSocketFactory)
173+
.setTlsSocketStrategy(sslSocketFactory)
174174
.build();
175175

176176
clientBuilder.setConnectionManager(connectionManager);
177177
} else if (connectionConfig.getHostnameVerifier() != null) {
178178
// If only hostname verifier is set without SSL context, we need to use the default SSL
179179
// context
180180
try {
181-
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
181+
DefaultClientTlsStrategy sslSocketFactory = new DefaultClientTlsStrategy(
182182
SSLContext.getDefault(),
183183
connectionConfig.getHostnameVerifier());
184184

185185
HttpClientConnectionManager connectionManager =
186186
PoolingHttpClientConnectionManagerBuilder.create()
187-
.setSSLSocketFactory(sslSocketFactory)
187+
.setTlsSocketStrategy(sslSocketFactory)
188188
.build();
189189

190190
clientBuilder.setConnectionManager(connectionManager);

geode-management/src/main/java/org/apache/geode/management/configuration/Index.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public String getRegionName() {
8888
}
8989

9090
String regionName = regionPath.trim().split(" ")[0];
91-
regionName = StringUtils.removeStart(regionName, SEPARATOR);
91+
regionName =
92+
regionName.startsWith(SEPARATOR) ? regionName.substring(SEPARATOR.length()) : regionName;
9293
if (regionName.contains(".")) {
9394
regionName = regionName.substring(0, regionName.indexOf('.'));
9495
}

geode-serialization/src/main/java/org/apache/geode/internal/serialization/internal/DSFIDSerializerImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,11 @@ public void register(int fixedId, Class<? extends DataSerializableFixedID> fixed
340340
try {
341341
Constructor<?> cons = fixedIdClass.getConstructor((Class<Object>[]) null);
342342
cons.setAccessible(true);
343-
if (!cons.isAccessible()) {
343+
// Based on canAccess doc - since this is constructor, the obj must be null
344+
if (!cons.canAccess(null)) {
344345
throw new IllegalArgumentException(
345-
"default constructor not accessible " + "for DSFID=" + fixedId + ": " + fixedIdClass);
346+
"default constructor failed reflective access check (canAccess) for DSFID="
347+
+ fixedId + ": " + fixedIdClass);
346348
}
347349
if (fixedId >= Byte.MIN_VALUE && fixedId <= Byte.MAX_VALUE) {
348350
int index = fixedId + Byte.MAX_VALUE + 1;

geode-web-api/src/main/java/org/apache/geode/rest/internal/web/swagger/config/SwaggerConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public class SwaggerConfig implements WebApplicationInitializer, WebMvcConfigure
5959
@Override
6060
public void configurePathMatch(PathMatchConfigurer configurer) {
6161
PathPatternParser parser = new PathPatternParser();
62+
// When Geode requires Spring Framework 6.2+ as a minimum, this explicit PathPatternParser
63+
// configuration for optional trailing slashes can be replaced by configuring UrlHandlerFilter
64+
// (e.g., via a filter registration or equivalent configuration) to handle trailing-slash
65+
// matching instead of customize it here in configurePathMatch.
6266
parser.setMatchOptionalTrailingSeparator(true);
6367
configurer.setPatternParser(parser);
6468
}

0 commit comments

Comments
 (0)