diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/ElasticsearchCatAsyncClient.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/ElasticsearchCatAsyncClient.java index 3057e2c41d..bcd49c592c 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/ElasticsearchCatAsyncClient.java +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/ElasticsearchCatAsyncClient.java @@ -22,10 +22,9 @@ import co.elastic.clients.ApiClient; import co.elastic.clients.elasticsearch._types.ErrorResponse; import co.elastic.clients.transport.ElasticsearchTransport; -import co.elastic.clients.transport.Endpoint; import co.elastic.clients.transport.JsonEndpoint; -import co.elastic.clients.transport.Transport; import co.elastic.clients.transport.TransportOptions; +import co.elastic.clients.transport.endpoints.TextResponse; import co.elastic.clients.util.ObjectBuilder; import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -495,7 +494,7 @@ public CompletableFuture health() { * "https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-cat">Documentation * on elastic.co */ - public CompletableFuture help() { + public CompletableFuture help() { return this.transport.performRequestAsync(HelpRequest._INSTANCE, HelpRequest._ENDPOINT, this.transportOptions); } diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/ElasticsearchCatClient.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/ElasticsearchCatClient.java index 6a43594646..c827b0df4a 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/ElasticsearchCatClient.java +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/ElasticsearchCatClient.java @@ -23,10 +23,9 @@ import co.elastic.clients.elasticsearch._types.ElasticsearchException; import co.elastic.clients.elasticsearch._types.ErrorResponse; import co.elastic.clients.transport.ElasticsearchTransport; -import co.elastic.clients.transport.Endpoint; import co.elastic.clients.transport.JsonEndpoint; -import co.elastic.clients.transport.Transport; import co.elastic.clients.transport.TransportOptions; +import co.elastic.clients.transport.endpoints.TextResponse; import co.elastic.clients.util.ObjectBuilder; import java.io.IOException; import java.util.function.Function; @@ -498,7 +497,7 @@ public HealthResponse health() throws IOException, ElasticsearchException { * "https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-cat">Documentation * on elastic.co */ - public HelpResponse help() throws IOException, ElasticsearchException { + public TextResponse help() throws IOException, ElasticsearchException { return this.transport.performRequest(HelpRequest._INSTANCE, HelpRequest._ENDPOINT, this.transportOptions); } diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/HelpRequest.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/HelpRequest.java index e72870dc69..004234904b 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/HelpRequest.java +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/HelpRequest.java @@ -20,16 +20,12 @@ package co.elastic.clients.elasticsearch.cat; import co.elastic.clients.elasticsearch._types.ErrorResponse; -import co.elastic.clients.json.JsonpDeserializable; -import co.elastic.clients.json.JsonpDeserializer; -import co.elastic.clients.json.ObjectBuilderDeserializer; -import co.elastic.clients.json.ObjectDeserializer; import co.elastic.clients.transport.Endpoint; import co.elastic.clients.transport.endpoints.SimpleEndpoint; -import co.elastic.clients.util.ObjectBuilder; -import jakarta.json.stream.JsonGenerator; +import co.elastic.clients.transport.endpoints.TextResponse; +import co.elastic.clients.transport.endpoints.TextEndpoint; + import java.util.Collections; -import java.util.Objects; //---------------------------------------------------------------- // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. @@ -71,7 +67,7 @@ public HelpRequest() { /** * Endpoint "{@code cat.help}". */ - public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + public static final Endpoint _ENDPOINT = new TextEndpoint<>( "es/cat.help", // Request method @@ -95,5 +91,5 @@ public HelpRequest() { request -> { return Collections.emptyMap(); - }, SimpleEndpoint.emptyMap(), false, HelpResponse._DESERIALIZER); + }, SimpleEndpoint.emptyMap(), false, null); } diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/HelpResponse.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/HelpResponse.java deleted file mode 100644 index 03fced1f8f..0000000000 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/cat/HelpResponse.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package co.elastic.clients.elasticsearch.cat; - -import co.elastic.clients.json.JsonpDeserializable; -import co.elastic.clients.json.JsonpDeserializer; -import co.elastic.clients.json.ObjectBuilderDeserializer; -import co.elastic.clients.json.ObjectDeserializer; -import co.elastic.clients.util.ObjectBuilder; -import jakarta.json.stream.JsonGenerator; -import java.util.Objects; - -//---------------------------------------------------------------- -// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. -//---------------------------------------------------------------- -// -// This code is generated from the Elasticsearch API specification -// at https://github.com/elastic/elasticsearch-specification -// -// Manual updates to this file will be lost when the code is -// re-generated. -// -// If you find a property that is missing or wrongly typed, please -// open an issue or a PR on the API specification repository. -// -//---------------------------------------------------------------- - -// typedef: cat.help.Response - -/** - * - * @see API - * specification - */ - -public class HelpResponse { - public HelpResponse() { - } - - /** - * Singleton instance for {@link HelpResponse}. - */ - public static final HelpResponse _INSTANCE = new HelpResponse(); - - public static final JsonpDeserializer _DESERIALIZER = JsonpDeserializer - .emptyObject(HelpResponse._INSTANCE); - -} diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/doc-files/api-spec.html b/java-client/src/main/java/co/elastic/clients/elasticsearch/doc-files/api-spec.html index a256b9726f..a00e4b8e5c 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/doc-files/api-spec.html +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/doc-files/api-spec.html @@ -1134,10 +1134,9 @@ 'cat.health.HealthRecord': 'cat/health/types.ts#L23-L99', 'cat.health.Request': 'cat/health/CatHealthRequest.ts#L23-L65', 'cat.health.Response': 'cat/health/CatHealthResponse.ts#L22-L25', -'cat.help.Request': 'cat/help/CatHelpRequest.ts#L20-L36', -'cat.help.Response': 'cat/help/CatHelpResponse.ts#L20-L25', -'cat.indices.IndicesRecord': 'cat/indices/types.ts#L20-L808', -'cat.indices.Request': 'cat/indices/CatIndicesRequest.ts#L24-L99', +'cat.help.Request': 'cat/help/CatHelpRequest.ts#L22-L39', +'cat.indices.IndicesRecord': 'cat/indices/types.ts#L20-L812', +'cat.indices.Request': 'cat/indices/CatIndicesRequest.ts#L30-L107', 'cat.indices.Response': 'cat/indices/CatIndicesResponse.ts#L22-L25', 'cat.master.MasterRecord': 'cat/master/types.ts#L20-L39', 'cat.master.Request': 'cat/master/CatMasterRequest.ts#L24-L68', @@ -2645,9 +2644,8 @@ 'nodes.get_repositories_metering_info.Request': 'nodes/get_repositories_metering_info/GetRepositoriesMeteringInfoRequest.ts#L23-L49', 'nodes.get_repositories_metering_info.Response': 'nodes/get_repositories_metering_info/GetRepositoriesMeteringInfoResponse.ts#L36-L39', 'nodes.get_repositories_metering_info.ResponseBase': 'nodes/get_repositories_metering_info/GetRepositoriesMeteringInfoResponse.ts#L25-L34', -'nodes.hot_threads.Request': 'nodes/hot_threads/NodesHotThreadsRequest.ts#L25-L88', -'nodes.hot_threads.Response': 'nodes/hot_threads/NodesHotThreadsResponse.ts#L20-L22', -'nodes.info.DeprecationIndexing': 'nodes/info/types.ts#L154-L156', +'nodes.hot_threads.Request': 'nodes/hot_threads/NodesHotThreadsRequest.ts#L25-L94', +'nodes.info.DeprecationIndexing': 'nodes/info/types.ts#L154-L157', 'nodes.info.NodeInfo': 'nodes/info/types.ts#L32-L72', 'nodes.info.NodeInfoAction': 'nodes/info/types.ts#L194-L196', 'nodes.info.NodeInfoAggregation': 'nodes/info/types.ts#L250-L252', diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/ElasticsearchNodesAsyncClient.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/ElasticsearchNodesAsyncClient.java index 51446e631b..c7bc581656 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/ElasticsearchNodesAsyncClient.java +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/ElasticsearchNodesAsyncClient.java @@ -24,8 +24,8 @@ import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.Endpoint; import co.elastic.clients.transport.JsonEndpoint; -import co.elastic.clients.transport.Transport; import co.elastic.clients.transport.TransportOptions; +import co.elastic.clients.transport.endpoints.TextResponse; import co.elastic.clients.util.ObjectBuilder; import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -158,9 +158,9 @@ public final CompletableFuture getRepositor * on elastic.co */ - public CompletableFuture hotThreads(HotThreadsRequest request) { + public CompletableFuture hotThreads(HotThreadsRequest request) { @SuppressWarnings("unchecked") - JsonEndpoint endpoint = (JsonEndpoint) HotThreadsRequest._ENDPOINT; + Endpoint endpoint = (Endpoint) HotThreadsRequest._ENDPOINT; return this.transport.performRequestAsync(request, endpoint, this.transportOptions); } @@ -178,7 +178,7 @@ public CompletableFuture hotThreads(HotThreadsRequest reques * on elastic.co */ - public final CompletableFuture hotThreads( + public final CompletableFuture hotThreads( Function> fn) { return hotThreads(fn.apply(new HotThreadsRequest.Builder()).build()); } @@ -193,7 +193,7 @@ public final CompletableFuture hotThreads( * on elastic.co */ - public CompletableFuture hotThreads() { + public CompletableFuture hotThreads() { return this.transport.performRequestAsync(new HotThreadsRequest.Builder().build(), HotThreadsRequest._ENDPOINT, this.transportOptions); } diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/ElasticsearchNodesClient.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/ElasticsearchNodesClient.java index 18f48a09db..7d5796f54e 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/ElasticsearchNodesClient.java +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/ElasticsearchNodesClient.java @@ -25,8 +25,8 @@ import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.Endpoint; import co.elastic.clients.transport.JsonEndpoint; -import co.elastic.clients.transport.Transport; import co.elastic.clients.transport.TransportOptions; +import co.elastic.clients.transport.endpoints.TextResponse; import co.elastic.clients.util.ObjectBuilder; import java.io.IOException; import java.util.function.Function; @@ -160,9 +160,9 @@ public final GetRepositoriesMeteringInfoResponse getRepositoriesMeteringInfo( * on elastic.co */ - public HotThreadsResponse hotThreads(HotThreadsRequest request) throws IOException, ElasticsearchException { + public TextResponse hotThreads(HotThreadsRequest request) throws IOException, ElasticsearchException { @SuppressWarnings("unchecked") - JsonEndpoint endpoint = (JsonEndpoint) HotThreadsRequest._ENDPOINT; + Endpoint endpoint = (Endpoint) HotThreadsRequest._ENDPOINT; return this.transport.performRequest(request, endpoint, this.transportOptions); } @@ -180,7 +180,7 @@ public HotThreadsResponse hotThreads(HotThreadsRequest request) throws IOExcepti * on elastic.co */ - public final HotThreadsResponse hotThreads(Function> fn) + public final TextResponse hotThreads(Function> fn) throws IOException, ElasticsearchException { return hotThreads(fn.apply(new HotThreadsRequest.Builder()).build()); } @@ -195,7 +195,7 @@ public final HotThreadsResponse hotThreads(Function */ - public HotThreadsResponse hotThreads() throws IOException, ElasticsearchException { + public TextResponse hotThreads() throws IOException, ElasticsearchException { return this.transport.performRequest(new HotThreadsRequest.Builder().build(), HotThreadsRequest._ENDPOINT, this.transportOptions); } diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/HotThreadsRequest.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/HotThreadsRequest.java index f7e7eac577..69a5c43f08 100644 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/HotThreadsRequest.java +++ b/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/HotThreadsRequest.java @@ -23,22 +23,19 @@ import co.elastic.clients.elasticsearch._types.RequestBase; import co.elastic.clients.elasticsearch._types.ThreadType; import co.elastic.clients.elasticsearch._types.Time; -import co.elastic.clients.json.JsonpDeserializable; -import co.elastic.clients.json.JsonpDeserializer; -import co.elastic.clients.json.ObjectBuilderDeserializer; -import co.elastic.clients.json.ObjectDeserializer; import co.elastic.clients.transport.Endpoint; import co.elastic.clients.transport.endpoints.SimpleEndpoint; +import co.elastic.clients.transport.endpoints.TextResponse; +import co.elastic.clients.transport.endpoints.TextEndpoint; import co.elastic.clients.util.ApiTypeHelper; import co.elastic.clients.util.ObjectBuilder; -import jakarta.json.stream.JsonGenerator; + import java.lang.Boolean; import java.lang.Long; import java.lang.String; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -364,7 +361,7 @@ public HotThreadsRequest build() { /** * Endpoint "{@code nodes.hot_threads}". */ - public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + public static final Endpoint _ENDPOINT = new TextEndpoint<>( "es/nodes.hot_threads", // Request method @@ -445,5 +442,5 @@ public HotThreadsRequest build() { } return params; - }, SimpleEndpoint.emptyMap(), false, HotThreadsResponse._DESERIALIZER); + }, SimpleEndpoint.emptyMap(), false, null); } diff --git a/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/HotThreadsResponse.java b/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/HotThreadsResponse.java deleted file mode 100644 index 1443e96518..0000000000 --- a/java-client/src/main/java/co/elastic/clients/elasticsearch/nodes/HotThreadsResponse.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package co.elastic.clients.elasticsearch.nodes; - -import co.elastic.clients.json.JsonpDeserializable; -import co.elastic.clients.json.JsonpDeserializer; -import co.elastic.clients.json.ObjectBuilderDeserializer; -import co.elastic.clients.json.ObjectDeserializer; -import co.elastic.clients.util.ObjectBuilder; -import jakarta.json.stream.JsonGenerator; -import java.util.Objects; - -//---------------------------------------------------------------- -// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. -//---------------------------------------------------------------- -// -// This code is generated from the Elasticsearch API specification -// at https://github.com/elastic/elasticsearch-specification -// -// Manual updates to this file will be lost when the code is -// re-generated. -// -// If you find a property that is missing or wrongly typed, please -// open an issue or a PR on the API specification repository. -// -//---------------------------------------------------------------- - -// typedef: nodes.hot_threads.Response - -/** - * - * @see API - * specification - */ - -public class HotThreadsResponse { - public HotThreadsResponse() { - } - - /** - * Singleton instance for {@link HotThreadsResponse}. - */ - public static final HotThreadsResponse _INSTANCE = new HotThreadsResponse(); - - public static final JsonpDeserializer _DESERIALIZER = JsonpDeserializer - .emptyObject(HotThreadsResponse._INSTANCE); - -} diff --git a/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java b/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java index 26dcd273b6..51e4d8ef50 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java +++ b/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java @@ -28,6 +28,8 @@ import co.elastic.clients.transport.endpoints.BinaryEndpoint; import co.elastic.clients.transport.endpoints.BooleanEndpoint; import co.elastic.clients.transport.endpoints.BooleanResponse; +import co.elastic.clients.transport.endpoints.TextResponse; +import co.elastic.clients.transport.endpoints.TextEndpoint; import co.elastic.clients.transport.http.HeaderMap; import co.elastic.clients.transport.http.RepeatableBodyResponse; import co.elastic.clients.transport.http.TransportHttpClient; @@ -439,14 +441,37 @@ private ResponseT decodeTransportResponse( } return response; - } else if (endpoint instanceof BooleanEndpoint) { - BooleanEndpoint bep = (BooleanEndpoint) endpoint; + } else if (endpoint instanceof BooleanEndpoint bep) { @SuppressWarnings("unchecked") ResponseT response = (ResponseT) new BooleanResponse(bep.getResult(statusCode)); return response; + } else if (endpoint instanceof TextEndpoint) { + // Expecting a body + if (entity == null) { + throw new TransportException( + clientResp, + "Expecting a response body, but none was sent", + endpoint.id() + ); + } + checkTextContentType(entity.contentType(), clientResp, endpoint); + try ( InputStream content = entity.asInputStream()) { + String textResponse = new String(content.readAllBytes(), StandardCharsets.UTF_8); + @SuppressWarnings("unchecked") + ResponseT response = (ResponseT) new TextResponse(textResponse); + return response; + } catch (Exception e) { + throw new TransportException( + clientResp, + "Failed to decode text response", + endpoint.id(), + e + ); + } + } else if (endpoint instanceof BinaryEndpoint) { @SuppressWarnings("unchecked") ResponseT response = (ResponseT) new BinaryDataResponse(entity); @@ -505,6 +530,21 @@ private void checkJsonContentType( "Expecting JSON data but response content-type is: " + contentType, endpoint.id()); } + private void checkTextContentType( + String contentType, TransportHttpClient.Response clientResp, Endpoint endpoint + ) throws IOException { + if (contentType == null) { + throw new TransportException(clientResp, "Response has no content-type", endpoint.id()); + } + + if (contentType.startsWith("text/plain")) { + return; + } + + throw new TransportException(clientResp, + "Expecting text data but response content-type is: " + contentType, endpoint.id()); + } + private static void addStandardHeaders(HeaderMap headers) { headers.put(HeaderMap.USER_AGENT, USER_AGENT_VALUE); headers.put(HeaderMap.CLIENT_META, CLIENT_META_VALUE); diff --git a/java-client/src/main/java/co/elastic/clients/transport/endpoints/TextEndpoint.java b/java-client/src/main/java/co/elastic/clients/transport/endpoints/TextEndpoint.java new file mode 100644 index 0000000000..4a14586d1a --- /dev/null +++ b/java-client/src/main/java/co/elastic/clients/transport/endpoints/TextEndpoint.java @@ -0,0 +1,41 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package co.elastic.clients.transport.endpoints; + +import java.util.Map; +import java.util.function.Function; + +public class TextEndpoint extends EndpointBase { + + public TextEndpoint( + String id, + Function method, + Function requestUrl, + Function> pathParameters, + Function> queryParameters, + Function> headers, + boolean hasRequestBody, + Object ignored // same number of arguments as SimpleEndpoint + ) { + super(id, method, requestUrl, pathParameters, queryParameters, headers, hasRequestBody ? returnSelf() : returnNull()); + } +} diff --git a/java-client/src/main/java/co/elastic/clients/transport/endpoints/TextResponse.java b/java-client/src/main/java/co/elastic/clients/transport/endpoints/TextResponse.java new file mode 100644 index 0000000000..1fa2ba9c48 --- /dev/null +++ b/java-client/src/main/java/co/elastic/clients/transport/endpoints/TextResponse.java @@ -0,0 +1,35 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package co.elastic.clients.transport.endpoints; + +/** + * An API response that has a simple text body. + */ +public class TextResponse { + private final String value; + + public TextResponse(String value) { + this.value = value; + } + + public String value() { + return value; + } +} diff --git a/java-client/src/test/java/co/elastic/clients/transport/endpoints/TextEndpointTest.java b/java-client/src/test/java/co/elastic/clients/transport/endpoints/TextEndpointTest.java new file mode 100644 index 0000000000..d6caf1db6e --- /dev/null +++ b/java-client/src/test/java/co/elastic/clients/transport/endpoints/TextEndpointTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package co.elastic.clients.transport.endpoints; + +import co.elastic.clients.elasticsearch.ElasticsearchClient; +import co.elastic.clients.elasticsearch.ElasticsearchTestClient; +import co.elastic.clients.elasticsearch.ElasticsearchTestServer; +import co.elastic.clients.json.jackson.JacksonJsonpMapper; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +public class TextEndpointTest extends Assertions { + + static ElasticsearchClient elasticsearchClient; + + @BeforeAll + public static void setup() { + var server = ElasticsearchTestServer.global(); + elasticsearchClient = ElasticsearchTestClient.createClient(server.url(), new JacksonJsonpMapper(), + server.sslContext()); + } + + @Test + public void testTextBody() throws IOException { + TextResponse resp = elasticsearchClient.cat().help(); + assertTrue(resp.value().contains("=^.^=")); + } +}