Skip to content

Commit 925daac

Browse files
committed
HSEARCH-5464 Remove the apache host from ElasticsearchResponse
1 parent 66038c3 commit 925daac

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/client/impl/ElasticsearchClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private ElasticsearchResponse convertResponse(Response response) {
199199
try {
200200
JsonObject body = parseBody( response );
201201
return new ElasticsearchResponse(
202-
response.getHost(),
202+
response.getHost().toHostString(),
203203
response.getStatusLine().getStatusCode(),
204204
response.getStatusLine().getReasonPhrase(),
205205
body );

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/client/spi/ElasticsearchResponse.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,24 @@
44
*/
55
package org.hibernate.search.backend.elasticsearch.client.spi;
66

7-
import com.google.gson.JsonObject;
7+
import java.util.Objects;
88

9-
import org.apache.http.HttpHost;
9+
import com.google.gson.JsonObject;
1010

1111
public final class ElasticsearchResponse {
12-
13-
private final HttpHost host;
12+
private final String host;
1413
private final int statusCode;
15-
1614
private final String statusMessage;
17-
1815
private final JsonObject body;
1916

20-
public ElasticsearchResponse(HttpHost host, int statusCode, String statusMessage, JsonObject body) {
17+
public ElasticsearchResponse(String host, int statusCode, String statusMessage, JsonObject body) {
2118
this.host = host;
2219
this.statusCode = statusCode;
2320
this.statusMessage = statusMessage;
2421
this.body = body;
2522
}
2623

27-
public HttpHost host() {
24+
public String host() {
2825
return host;
2926
}
3027

@@ -39,5 +36,4 @@ public String statusMessage() {
3936
public JsonObject body() {
4037
return body;
4138
}
42-
4339
}

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/logging/impl/ElasticsearchRequestLog.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.jboss.logging.annotations.Message;
2020
import org.jboss.logging.annotations.MessageLogger;
2121

22-
import org.apache.http.HttpHost;
23-
2422
@CategorizedLogger(
2523
category = ElasticsearchRequestLog.CATEGORY_NAME,
2624
description = """
@@ -51,7 +49,7 @@ public interface ElasticsearchRequestLog extends BasicLogger {
5149
value = "Executed Elasticsearch HTTP %s request to '%s' with path '%s',"
5250
+ " query parameters %s and %d objects in payload in %dms."
5351
+ " Response had status %d '%s'. Request body: <%s>. Response body: <%s>")
54-
void executedRequestWithFailure(String method, HttpHost host, String path, Map<String, String> getParameters,
52+
void executedRequestWithFailure(String method, String host, String path, Map<String, String> getParameters,
5553
int bodyParts, long timeInMs,
5654
int responseStatusCode, String responseStatusMessage,
5755
String requestBodyParts, String responseBody);
@@ -61,7 +59,7 @@ void executedRequestWithFailure(String method, HttpHost host, String path, Map<S
6159
value = "Executed Elasticsearch HTTP %s request to '%s' with path '%s',"
6260
+ " query parameters %s and %d objects in payload in %dms."
6361
+ " Response had status %d '%s'. Request body: <%s>. Response body: <%s>")
64-
void executedRequest(String method, HttpHost host, String path, Map<String, String> getParameters, int bodyParts,
62+
void executedRequest(String method, String host, String path, Map<String, String> getParameters, int bodyParts,
6563
long timeInMs,
6664
int responseStatusCode, String responseStatusMessage,
6765
String requestBodyParts, String responseBody);

backend/elasticsearch/src/test/java/org/hibernate/search/backend/elasticsearch/client/impl/ElasticsearchClientUtilsTryGetElasticsearchVersionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void testHttpStatus404(String distributionString, String versionString,
116116
// which doesn't allow retrieving the version.
117117
when( clientMock.submit( any() ) )
118118
.thenReturn( CompletableFuture.completedFuture( new ElasticsearchResponse(
119-
new HttpHost( "mockHost:9200" ), 404, "", null ) ) );
119+
"mockHost:9200", 404, "", null ) ) );
120120
ElasticsearchVersion version = ElasticsearchClientUtils.tryGetElasticsearchVersion( clientMock );
121121
assertThat( version ).isNull();
122122
}
@@ -131,6 +131,6 @@ private void doMock(String theDistributionString, String theVersionString) {
131131
responseBody.add( "version", versionObject );
132132
when( clientMock.submit( any() ) )
133133
.thenReturn( CompletableFuture.completedFuture( new ElasticsearchResponse(
134-
new HttpHost( "mockHost:9200" ), 200, "", responseBody ) ) );
134+
"mockHost:9200", 200, "", responseBody ) ) );
135135
}
136136
}

backend/elasticsearch/src/test/java/org/hibernate/search/backend/elasticsearch/work/impl/BulkWorkTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void execute_success() {
7676
responseBody.add( "items", items );
7777
items.add( new JsonObject() );
7878
items.add( new JsonObject() );
79-
ElasticsearchResponse response = new ElasticsearchResponse( new HttpHost( "mockHost:9200" ),
79+
ElasticsearchResponse response = new ElasticsearchResponse( "mockHost:9200",
8080
200, "OK", responseBody );
8181
futureFromClient.complete( response );
8282
verifyNoOtherClientInteractionsAndReset();
@@ -120,7 +120,7 @@ void execute_http500() {
120120

121121
JsonObject responseBody = new JsonObject();
122122
responseBody.addProperty( "someProperty", "someValue" );
123-
ElasticsearchResponse response = new ElasticsearchResponse( new HttpHost( "mockHost:9200" ),
123+
ElasticsearchResponse response = new ElasticsearchResponse( "mockHost:9200",
124124
500, "SomeStatus", responseBody );
125125
futureFromClient.complete( response );
126126
verifyNoOtherClientInteractionsAndReset();

0 commit comments

Comments
 (0)