Add resttemplate-to-restclient module: RestTemplate deprecation on Spring Framework 7.1 / Boot 4.2.0 vs 4.1.3, method mapping, exchange() trap, bridge URI encoding, RestTestClient, OpenRewrite recipe run, with real transcripts

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7M7FEdeEm3APj16Bu
This commit is contained in:
Claude
2026-11-21 21:26:48 +05:30
parent 5f85ec8d53
commit cbcfb05e35
77 changed files with 2187 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Compiles each file in src/broken/ with -Xlint:deprecation against the module classpath of the
# given pom (default pom.xml = 4.2.0; pass pom-41.xml for the 4.1.3 baseline) and stores the
# compiler's own messages in output/NN-... (suffix -on-4.1.3 for the baseline).
set -u
cd "$(dirname "$0")/.."
POM="${1:-pom.xml}"
LABEL=$(grep -m1 '<boot.label>' "$POM" | sed -E 's/.*<boot.label>(.*)<\/boot.label>.*/\1/')
SUFFIX=""; [[ "$LABEL" == 4.2* ]] || SUFFIX="-on-$LABEL"
mvn -B -q -f "$POM" dependency:build-classpath -Dmdep.outputFile=target/cp.txt >/dev/null 2>&1
CP="$(cat target/cp.txt):target/classes"
compile_one() { # <source> <outfile-base>
local src="$1" base="$2" out="output/$2$SUFFIX.txt"
rm -rf target/broken && mkdir -p target/broken
{
echo "# $base (Spring Boot $LABEL, JDK $(javac -version 2>&1 | grep -v Picked | awk '{print $2}'))"
echo "\$ javac -Xlint:deprecation -cp <module classpath> -d target/broken $src"
javac -Xlint:deprecation -cp "$CP" -d target/broken "$src" 2>&1 | grep -v '^Picked up' | sed -e "s#^$(pwd)/##"
echo "exit: ${PIPESTATUS[0]}"
} > "$out"
cat "$out"
}
compile_one src/broken/UsesRestTemplate.java 13-resttemplate-compiler-warnings
compile_one src/broken/UsesTestRestTemplate.java 14-testresttemplate-compiler-warnings
compile_one src/broken/OldTimeoutSettings.java 15-old-timeout-settings-compiler-error
compile_one src/broken/NewTimeoutSettings.java 16-new-timeout-settings-compiler
# The migrated client must compile with no [removal] warning at all.
compile_one src/main/java/com/ankurm/rtmigration/StudentClient.java 17-migrated-client-compiler
# The legacy client carries @SuppressWarnings("removal"); without it the warnings come back.
sed 's/^@SuppressWarnings("removal")//' src/main/java/com/ankurm/rtmigration/LegacyStudentClient.java > target/LegacyStudentClient.java
compile_one target/LegacyStudentClient.java 18-legacy-client-without-suppression
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Runs the Moderne recipe io.moderne.java.spring.boot3.MigrateRestTemplateToRestClient
# (io.moderne.recipe:rewrite-spring 0.40.1, plugin rewrite-maven-plugin 6.46.1) on
# src/recipe/before/RemoteClient.java in a scratch project OUTSIDE this checkout (OpenRewrite
# silently skips git-ignored sources), stores the diff in output/20-openrewrite-diff.txt and
# copies the generated class to src/test/.../recipe/RemoteClient.java, where RecipeOutputTest runs it.
set -euo pipefail
cd "$(dirname "$0")/.."
HERE=$(pwd)
W=$(mktemp -d)
mkdir -p "$W/src/main/java/com/ankurm/rtmigration/recipe"
cat > "$W/pom.xml" <<'P'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>4.2.0</version><relativePath/></parent>
<groupId>demo</groupId><artifactId>orw</artifactId><version>1.0.0</version>
<properties><java.version>25</java.version></properties>
<dependencies>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webmvc</artifactId></dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-restclient</artifactId></dependency>
</dependencies>
</project>
P
cp src/main/java/com/ankurm/rtmigration/Student.java "$W/src/main/java/com/ankurm/rtmigration/" 2>/dev/null || { mkdir -p "$W/src/main/java/com/ankurm/rtmigration"; cp src/main/java/com/ankurm/rtmigration/Student.java "$W/src/main/java/com/ankurm/rtmigration/"; }
cp src/recipe/before/RemoteClient.java "$W/src/main/java/com/ankurm/rtmigration/recipe/"
( cd "$W" && git init -q . && git add -A && git -c user.email=a@b -c user.name=n commit -qm before
mvn -B -q org.openrewrite.maven:rewrite-maven-plugin:6.46.1:run \
-Drewrite.recipeArtifactCoordinates=io.moderne.recipe:rewrite-spring:0.40.1 \
-Drewrite.activeRecipes=io.moderne.java.spring.boot3.MigrateRestTemplateToRestClient 2>&1 | { grep -v -E '^Picked|^WARNING' || true; } | tail -5
{ echo "# 20-openrewrite-diff (io.moderne.recipe:rewrite-spring 0.40.1, rewrite-maven-plugin 6.46.1, Spring Boot 4.2.0)"
echo "\$ mvn rewrite:run -Drewrite.activeRecipes=io.moderne.java.spring.boot3.MigrateRestTemplateToRestClient"
git diff -U0 | grep -v -E '^(diff|index|---|\+\+\+)'; } > "$HERE/output/20-openrewrite-diff.txt" )
cp "$W/src/main/java/com/ankurm/rtmigration/recipe/RemoteClient.java" src/test/java/com/ankurm/rtmigration/recipe/RemoteClient.java
rm -rf "$W"
cat output/20-openrewrite-diff.txt
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Reads the deprecation annotations straight out of the published jars: which types carry
# @Deprecated(since, forRemoval) in Spring Framework 7.0.x vs 7.1.0 and Spring Boot 4.1.3 vs 4.2.0.
# Needs the jars in ~/.m2 (run `mvn test` and `mvn -f pom-41.xml test` once first).
set -u
cd "$(dirname "$0")/.."
M="$HOME/.m2/repository/org/springframework"
OUT=output/19-deprecation-annotations.txt
FW41=$(ls "$M/spring-web" | grep -E '^7\.0\.' | sort -V | tail -1)
annot() { # <jar> <class> -> "since=X forRemoval=true" or "not deprecated"
local out
out=$(javap -v -cp "$1" "$2" 2>/dev/null | awk '/^RuntimeVisibleAnnotations:/{f=1} f&&/java.lang.Deprecated\(/{d=1} d&&/since=/{s=$0} d&&/forRemoval=/{r=$0} /^[A-Za-z]/&&!/^RuntimeVisibleAnnotations/&&f&&!/^ /{} END{ if(d) print s " " r }' | tr -s " " | sed "s/^ //")
[ -n "$out" ] && echo "$out" || echo "not deprecated"
}
{
echo "# 19-deprecation-annotations (javap -v on the published jars, JDK $(javac -version 2>&1 | grep -v Picked | awk '{print $2}'))"
echo
for fw in "$FW41" 7.1.0; do
jar="$M/spring-web/$fw/spring-web-$fw.jar"
echo "spring-web $fw org.springframework.web.client.RestTemplate : $(annot "$jar" org.springframework.web.client.RestTemplate)"
echo "spring-web $fw org.springframework.web.client.RestClient : $(annot "$jar" org.springframework.web.client.RestClient)"
done
echo
for b in 4.1.3 4.2.0; do
rj="$HOME/.m2/repository/org/springframework/boot/spring-boot-restclient/$b/spring-boot-restclient-$b.jar"
tj="$HOME/.m2/repository/org/springframework/boot/spring-boot-resttestclient/$b/spring-boot-resttestclient-$b.jar"
for c in org.springframework.boot.restclient.RestTemplateBuilder org.springframework.boot.restclient.RestTemplateCustomizer \
org.springframework.boot.restclient.RestClientCustomizer org.springframework.boot.restclient.autoconfigure.RestTemplateAutoConfiguration \
org.springframework.boot.restclient.autoconfigure.RestClientAutoConfiguration; do
echo "spring-boot-restclient $b ${c#org.springframework.boot.restclient.} : $(annot "$rj" "$c")"
done
for c in org.springframework.boot.resttestclient.TestRestTemplate org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate \
org.springframework.boot.resttestclient.autoconfigure.AutoConfigureRestTestClient; do
echo "spring-boot-resttestclient $b ${c#org.springframework.boot.resttestclient.} : $(annot "$tj" "$c")"
done
echo
done
} | sed "s#$HOME#~#g" > "$OUT"
cat "$OUT"
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Reads the HTTP-client properties from spring-configuration-metadata.json inside the published
# spring-boot-http-client jars: the plural spring.http.clients.* keys and the deprecated singular ones.
set -u
cd "$(dirname "$0")/.."
OUT=output/23-http-client-properties.txt
{
echo "# 23-http-client-properties (spring-configuration-metadata.json, spring-boot-http-client jars)"
for v in 4.1.3 4.2.0; do
echo
echo "Spring Boot $v"
unzip -p "$HOME/.m2/repository/org/springframework/boot/spring-boot-http-client/$v/spring-boot-http-client-$v.jar" META-INF/spring-configuration-metadata.json \
| python3 -c "
import json,sys
for p in json.load(sys.stdin)['properties']:
n=p['name']
if n in ('spring.http.clients.connect-timeout','spring.http.clients.read-timeout','spring.http.client.connect-timeout','spring.http.client.read-timeout'):
d=p.get('deprecation')
print(' %-40s %s' % (n, 'DEPRECATED' + (' -> ' + d['replacement'] if d and 'replacement' in d else '') if d else 'current'))
"
done
} > "$OUT"
cat "$OUT"
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Regenerates every file in output/ on Spring Boot 4.2.0 (GA) and on the 4.1.3 baseline.
# Needs JDK 25 and Maven 3.9 on PATH, plus network access to Maven Central.
# scripts/openrewrite.sh downloads the Moderne recipe artifact; it is the only step that
# needs more than the jars the module already depends on.
set -euo pipefail
cd "$(dirname "$0")/.."
scripts/openrewrite.sh >/dev/null
mvn -B -q test
mvn -B -q -f pom-41.xml test
scripts/compile-broken.sh pom.xml >/dev/null
scripts/compile-broken.sh pom-41.xml >/dev/null
scripts/probe-jars.sh >/dev/null
scripts/probe-properties.sh >/dev/null
echo "done: $(ls output | wc -l) files in output/"