Skip to content

Commit a97d508

Browse files
committed
Add Apache HttpClient5 implementation for HTTP client (#4410)
1 parent f368ec0 commit a97d508

5 files changed

Lines changed: 21 additions & 14 deletions

File tree

http-clients/langchain4j-http-client-apache/src/main/java/dev/langchain4j/http/client/apache/MultipartBodyPublisher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.apache.hc.core5.http.message.BasicNameValuePair;
1515

1616
@Experimental
17-
public class MultipartBodyPublisher {
17+
class MultipartBodyPublisher {
1818

1919
private static final String BOUNDARY = "----LangChain4j";
2020
private static final String CRLF = "\r\n";

http-clients/langchain4j-http-client-apache/src/test/java/dev/langchain4j/http/client/apache/ApacheHttpClientIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class ApacheHttpClientIT extends HttpClientIT {
1212
protected List<HttpClient> clients() {
1313
return List.of(ApacheHttpClient.builder().build());
1414
}
15+
16+
@Override
17+
protected String incorrectUrl() {
18+
return "https://example.com";
19+
}
1520
}

http-clients/langchain4j-http-client-apache/src/test/java/dev/langchain4j/http/client/apache/ApacheHttpClientTimeoutIT.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
class ApacheHttpClientTimeoutIT extends HttpClientTimeoutIT {
1010

11-
@Override
12-
protected int readTimeoutMillis() {
13-
return 1000;
14-
}
15-
1611
@Override
1712
protected List<HttpClient> clients(Duration readTimeout) {
1813
return List.of(ApacheHttpClient.builder().readTimeout(readTimeout).build());
@@ -23,6 +18,11 @@ protected Class<? extends Exception> expectedReadTimeoutRootCauseExceptionType()
2318
return SocketTimeoutException.class;
2419
}
2520

21+
@Override
22+
protected int readTimeoutMillis() {
23+
return 1000;
24+
}
25+
2626
@Override
2727
protected String[] readAsyncMessageKeywords() {
2828
return new String[] {"1000", "MILLISECONDS"};

langchain4j-http-client/src/test/java/dev/langchain4j/http/client/HttpClientIT.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.TimeUnit;
3030
import java.util.concurrent.atomic.AtomicInteger;
3131
import java.util.concurrent.atomic.AtomicReference;
32+
3233
import org.junit.jupiter.api.Test;
3334
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
3435
import org.mockito.InOrder;
@@ -756,10 +757,7 @@ void should_call_listener_onError_when_fails_to_connect() throws Exception {
756757
for (HttpClient client : clients()) {
757758

758759
// given
759-
// if the URL of the ip cannot be found or there is other verification logic that cannot pass the initial
760-
// verification.(The request has not been submitted to the I/O thread yet.) (e.g., https://banana)
761-
// Apache HttpClient will execute `callback.failed(ex)` in main thread.
762-
String incorrectUrl = "https://example.com";
760+
String incorrectUrl = incorrectUrl();
763761

764762
HttpRequest request = HttpRequest.builder()
765763
.method(POST)
@@ -829,6 +827,10 @@ public void onClose() {
829827
}
830828
}
831829

830+
protected String incorrectUrl() {
831+
return "http://banana";
832+
}
833+
832834
@Test
833835
protected void should_return_successful_http_response_sync_form_data() throws Exception {
834836
Path audioPath =

langchain4j-http-client/src/test/java/dev/langchain4j/http/client/HttpClientTimeoutIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public abstract class HttpClientTimeoutIT {
3636

3737
private WireMockServer wireMockServer;
3838

39+
protected int readTimeoutMillis() {
40+
return 250;
41+
}
42+
3943
protected String[] readAsyncMessageKeywords() {
4044
return new String[] {"time", "out"};
4145
}
@@ -44,10 +48,6 @@ protected String[] readSyncMessageKeywords() {
4448
return readAsyncMessageKeywords();
4549
}
4650

47-
protected int readTimeoutMillis() {
48-
return 250;
49-
}
50-
5151
@BeforeEach
5252
void beforeEach() {
5353
wireMockServer = new WireMockServer(WireMockConfiguration.options().port(WIREMOCK_PORT));

0 commit comments

Comments
 (0)