Skip to content

Commit

Permalink
use Apache HttpClient 5.x ClassicRequestBuilder (#19)
Browse files Browse the repository at this point in the history
* use Apache HttpClient 5.x ClassicRequestBuilder

* simplify yaml
  • Loading branch information
sullis authored Jun 10, 2024
1 parent 0ccea84 commit 78d8e8a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/rewrite/apache-httpclient-5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.RedirectStrategy
newFullyQualifiedTypeName: org.apache.hc.client5.http.protocol.RedirectStrategy
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.hc.client5.http.classic.methods.RequestBuilder
newFullyQualifiedTypeName: org.apache.hc.core5.http.io.support.ClassicRequestBuilder

- org.openrewrite.java.ChangePackage:
oldPackageName: org.apache.http.config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void importReplacementsInGroupsWithSomeSpecificMappings() {
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.util.EntityUtils;
class A {
void method(HttpEntity entity, String urlStr) throws Exception {
HttpUriRequest getRequest = new HttpGet(urlStr);
Expand All @@ -107,7 +107,7 @@ void method(HttpEntity entity, String urlStr) throws Exception {
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
class A {
void method(HttpEntity entity, String urlStr) throws Exception {
HttpUriRequest getRequest = new HttpGet(urlStr);
Expand Down Expand Up @@ -220,4 +220,47 @@ void method() throws IOException {
);
}

@Test
void convertRequestBuilderToClassicRequestBuilder() {
rewriteRun(
//language=java
java(
"""
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.client.methods.RequestBuilder;
import java.io.IOException;
class A {
void method() throws IOException {
RequestBuilder requestBuilder = RequestBuilder.get("https://moderne.io");
HttpUriRequest request = requestBuilder.build();
CloseableHttpClient instance = HttpClientBuilder.create().build();
CloseableHttpResponse response = instance.execute(request);
}
}
""",
"""
import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import java.io.IOException;
class A {
void method() throws IOException {
ClassicRequestBuilder requestBuilder = ClassicRequestBuilder.get("https://moderne.io");
HttpUriRequest request = requestBuilder.build();
CloseableHttpClient instance = HttpClientBuilder.create().build();
CloseableHttpResponse response = instance.execute(request);
}
}
""")
);
}
}

0 comments on commit 78d8e8a

Please sign in to comment.