diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy index 96b7ac425279a..f7b30e774e340 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy @@ -91,6 +91,7 @@ class PrecommitTasks { if (testForbidden != null) { testForbidden.configure { signaturesURLs += getClass().getResource('/forbidden/es-test-signatures.txt') + signaturesURLs += getClass().getResource('/forbidden/http-signatures.txt') } } Task forbiddenApis = project.tasks.findByName('forbiddenApis') diff --git a/buildSrc/src/main/resources/forbidden/http-signatures.txt b/buildSrc/src/main/resources/forbidden/http-signatures.txt new file mode 100644 index 0000000000000..dcf20bbb09387 --- /dev/null +++ b/buildSrc/src/main/resources/forbidden/http-signatures.txt @@ -0,0 +1,45 @@ +# Licensed to Elasticsearch under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch 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. + +@defaultMessage Explicitly specify the ContentType of HTTP entities when creating +org.apache.http.entity.StringEntity#(java.lang.String) +org.apache.http.entity.StringEntity#(java.lang.String,java.lang.String) +org.apache.http.entity.StringEntity#(java.lang.String,java.nio.charset.Charset) +org.apache.http.entity.ByteArrayEntity#(byte[]) +org.apache.http.entity.ByteArrayEntity#(byte[],int,int) +org.apache.http.entity.FileEntity#(java.io.File) +org.apache.http.entity.InputStreamEntity#(java.io.InputStream) +org.apache.http.entity.InputStreamEntity#(java.io.InputStream,long) +org.apache.http.nio.entity.NByteArrayEntity#(byte[]) +org.apache.http.nio.entity.NByteArrayEntity#(byte[],int,int) +org.apache.http.nio.entity.NFileEntity#(java.io.File) +org.apache.http.nio.entity.NStringEntity#(java.lang.String) +org.apache.http.nio.entity.NStringEntity#(java.lang.String,java.lang.String) + +@defaultMessage Use non-deprecated constructors +org.apache.http.nio.entity.NFileEntity#(java.io.File,java.lang.String) +org.apache.http.nio.entity.NFileEntity#(java.io.File,java.lang.String,boolean) +org.apache.http.entity.FileEntity#(java.io.File,java.lang.String) +org.apache.http.entity.StringEntity#(java.lang.String,java.lang.String,java.lang.String) + +@defaultMessage BasicEntity is easy to mess up and forget to set content type +org.apache.http.entity.BasicHttpEntity#() + +@defaultMessage EntityTemplate is easy to mess up and forget to set content type +org.apache.http.entity.EntityTemplate#(org.apache.http.entity.ContentProducer) + +@defaultMessage SerializableEntity uses java serialization and makes it easy to forget to set content type +org.apache.http.entity.SerializableEntity#(java.io.Serializable) diff --git a/client/rest-high-level/build.gradle b/client/rest-high-level/build.gradle index 162e8608d4431..44ac53d9d56ac 100644 --- a/client/rest-high-level/build.gradle +++ b/client/rest-high-level/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.precommit.PrecommitTasks + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -39,3 +41,9 @@ dependencyLicenses { it.group.startsWith('org.elasticsearch') == false } } + +forbiddenApisMain { + // core does not depend on the httpclient for compile so we add the signatures here. We don't add them for test as they are already + // specified + signaturesURLs += [PrecommitTasks.getResource('/forbidden/http-signatures.txt')] +} \ No newline at end of file diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index 50229a5d916c9..b92ce34f93c04 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -27,7 +27,6 @@ import org.apache.http.ProtocolVersion; import org.apache.http.RequestLine; import org.apache.http.StatusLine; -import org.apache.http.entity.BasicHttpEntity; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; @@ -144,7 +143,7 @@ public void testParseEntity() throws IOException { } { IllegalStateException ise = expectThrows(IllegalStateException.class, - () -> RestHighLevelClient.parseEntity(new BasicHttpEntity(), null)); + () -> RestHighLevelClient.parseEntity(new StringEntity("", (ContentType) null), null)); assertEquals("Elasticsearch didn't return the [Content-Type] header, unable to parse response body", ise.getMessage()); } { diff --git a/client/rest/build.gradle b/client/rest/build.gradle index d5d9c9cfbb5f1..19ec584a1032d 100644 --- a/client/rest/build.gradle +++ b/client/rest/build.gradle @@ -49,8 +49,9 @@ dependencies { } forbiddenApisMain { - //client does not depend on core, so only jdk signatures should be checked - signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')] + //client does not depend on core, so only jdk and http signatures should be checked + signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt'), + PrecommitTasks.getResource('/forbidden/http-signatures.txt')] } forbiddenApisTest { @@ -58,7 +59,8 @@ forbiddenApisTest { bundledSignatures -= 'jdk-non-portable' bundledSignatures += 'jdk-internal' //client does not depend on core, so only jdk signatures should be checked - signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')] + signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt'), + PrecommitTasks.getResource('/forbidden/http-signatures.txt')] } dependencyLicenses { diff --git a/client/rest/src/test/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumerTests.java b/client/rest/src/test/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumerTests.java index 2488ea4b4355a..85b7090bb94c3 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumerTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/HeapBufferedAsyncResponseConsumerTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.client; import org.apache.http.ContentTooLongException; +import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.ProtocolVersion; import org.apache.http.StatusLine; @@ -32,6 +33,8 @@ import org.apache.http.nio.IOControl; import org.apache.http.protocol.HttpContext; +import java.util.concurrent.atomic.AtomicReference; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -56,7 +59,7 @@ public void testResponseProcessing() throws Exception { ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK"); HttpResponse httpResponse = new BasicHttpResponse(statusLine); - httpResponse.setEntity(new StringEntity("test")); + httpResponse.setEntity(new StringEntity("test", ContentType.TEXT_PLAIN)); //everything goes well consumer.responseReceived(httpResponse); @@ -99,11 +102,17 @@ private static void bufferLimitTest(HeapBufferedAsyncResponseConsumer consumer, StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK"); consumer.onResponseReceived(new BasicHttpResponse(statusLine)); - BasicHttpEntity entity = new BasicHttpEntity(); - entity.setContentLength(randomInt(bufferLimit)); + final AtomicReference contentLength = new AtomicReference<>(); + HttpEntity entity = new StringEntity("", ContentType.APPLICATION_JSON) { + @Override + public long getContentLength() { + return contentLength.get(); + } + }; + contentLength.set(randomLong(bufferLimit)); consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON); - entity.setContentLength(randomIntBetween(bufferLimit + 1, MAX_TEST_BUFFER_SIZE)); + contentLength.set(randomLongBetween(bufferLimit + 1, MAX_TEST_BUFFER_SIZE)); try { consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON); } catch(ContentTooLongException e) { diff --git a/client/rest/src/test/java/org/elasticsearch/client/RequestLoggerTests.java b/client/rest/src/test/java/org/elasticsearch/client/RequestLoggerTests.java index 68717dfe223cd..637e1807d2536 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RequestLoggerTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RequestLoggerTests.java @@ -31,6 +31,7 @@ import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpTrace; import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.entity.ContentType; import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHeader; @@ -71,20 +72,21 @@ public void testTraceRequest() throws IOException, URISyntaxException { HttpEntity entity; switch(randomIntBetween(0, 4)) { case 0: - entity = new StringEntity(requestBody, StandardCharsets.UTF_8); + entity = new StringEntity(requestBody, ContentType.APPLICATION_JSON); break; case 1: - entity = new InputStreamEntity(new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8))); + entity = new InputStreamEntity(new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)), + ContentType.APPLICATION_JSON); break; case 2: - entity = new NStringEntity(requestBody, StandardCharsets.UTF_8); + entity = new NStringEntity(requestBody, ContentType.APPLICATION_JSON); break; case 3: - entity = new NByteArrayEntity(requestBody.getBytes(StandardCharsets.UTF_8)); + entity = new NByteArrayEntity(requestBody.getBytes(StandardCharsets.UTF_8), ContentType.APPLICATION_JSON); break; case 4: // Evil entity without a charset - entity = new StringEntity(requestBody, (Charset) null); + entity = new StringEntity(requestBody, ContentType.create("application/json", (Charset) null)); break; default: throw new UnsupportedOperationException(); @@ -122,15 +124,16 @@ public void testTraceResponse() throws IOException { HttpEntity entity; switch(randomIntBetween(0, 2)) { case 0: - entity = new StringEntity(responseBody, StandardCharsets.UTF_8); + entity = new StringEntity(responseBody, ContentType.APPLICATION_JSON); break; case 1: //test a non repeatable entity - entity = new InputStreamEntity(new ByteArrayInputStream(responseBody.getBytes(StandardCharsets.UTF_8))); + entity = new InputStreamEntity(new ByteArrayInputStream(responseBody.getBytes(StandardCharsets.UTF_8)), + ContentType.APPLICATION_JSON); break; case 2: // Evil entity without a charset - entity = new StringEntity(responseBody, (Charset) null); + entity = new StringEntity(responseBody, ContentType.create("application/json", (Charset) null)); break; default: throw new UnsupportedOperationException(); diff --git a/client/rest/src/test/java/org/elasticsearch/client/ResponseExceptionTests.java b/client/rest/src/test/java/org/elasticsearch/client/ResponseExceptionTests.java index 9185222f5104d..1638693a44f5e 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/ResponseExceptionTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/ResponseExceptionTests.java @@ -25,6 +25,7 @@ import org.apache.http.ProtocolVersion; import org.apache.http.RequestLine; import org.apache.http.StatusLine; +import org.apache.http.entity.ContentType; import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHttpResponse; @@ -52,10 +53,11 @@ public void testResponseException() throws IOException { if (hasBody) { HttpEntity entity; if (getRandom().nextBoolean()) { - entity = new StringEntity(responseBody, StandardCharsets.UTF_8); + entity = new StringEntity(responseBody, ContentType.APPLICATION_JSON); } else { //test a non repeatable entity - entity = new InputStreamEntity(new ByteArrayInputStream(responseBody.getBytes(StandardCharsets.UTF_8))); + entity = new InputStreamEntity(new ByteArrayInputStream(responseBody.getBytes(StandardCharsets.UTF_8)), + ContentType.APPLICATION_JSON); } httpResponse.setEntity(entity); } diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java index e75de2f609c66..6d4e3ba4bc861 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java @@ -28,6 +28,7 @@ import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; @@ -249,7 +250,7 @@ private Response bodyTest(final String method) throws IOException { private Response bodyTest(final RestClient restClient, final String method) throws IOException { String requestBody = "{ \"field\": \"value\" }"; - StringEntity entity = new StringEntity(requestBody); + StringEntity entity = new StringEntity(requestBody, ContentType.APPLICATION_JSON); int statusCode = randomStatusCode(getRandom()); Response esResponse; try { diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java index 69048988ee994..541193c733d56 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostTests.java @@ -38,6 +38,7 @@ import org.apache.http.client.utils.URIBuilder; import org.apache.http.concurrent.FutureCallback; import org.apache.http.conn.ConnectTimeoutException; +import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; @@ -293,7 +294,7 @@ public void testIOExceptions() throws IOException { */ public void testBody() throws IOException { String body = "{ \"field\": \"value\" }"; - StringEntity entity = new StringEntity(body); + StringEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON); for (String method : Arrays.asList("DELETE", "GET", "PATCH", "POST", "PUT")) { for (int okStatusCode : getOkStatusCodes()) { Response response = restClient.performRequest(method, "/" + okStatusCode, Collections.emptyMap(), entity); @@ -431,7 +432,7 @@ private HttpUriRequest performRandomRequest(String method) throws Exception { HttpEntity entity = null; boolean hasBody = request instanceof HttpEntityEnclosingRequest && getRandom().nextBoolean(); if (hasBody) { - entity = new StringEntity(randomAsciiOfLengthBetween(10, 100)); + entity = new StringEntity(randomAsciiOfLengthBetween(10, 100), ContentType.APPLICATION_JSON); ((HttpEntityEnclosingRequest) request).setEntity(entity); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java index f0f8d50b4c1c9..e60de1e292916 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java @@ -139,19 +139,6 @@ public PutRepositoryRequest settings(Settings.Builder settings) { return this; } - /** - * Sets the repository settings. - * - * @param source repository settings in json or yaml format - * @return this request - * @deprecated use {@link #settings(String, XContentType)} to avoid content type auto-detection - */ - @Deprecated - public PutRepositoryRequest settings(String source) { - this.settings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * Sets the repository settings. * diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java index fe3713d5a3a68..21b8e8713a19b 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequestBuilder.java @@ -89,19 +89,6 @@ public PutRepositoryRequestBuilder setSettings(Settings.Builder settings) { return this; } - /** - * Sets the repository settings in Json or Yaml format - * - * @param source repository settings - * @return this builder - * @deprecated use {@link #setSettings(String, XContentType)} instead to avoid content type auto detection - */ - @Deprecated - public PutRepositoryRequestBuilder setSettings(String source) { - request.settings(source); - return this; - } - /** * Sets the repository settings in Json or Yaml format * diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java index bd0110e644cb6..efd27d1a38f37 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequest.java @@ -81,16 +81,6 @@ public ClusterUpdateSettingsRequest transientSettings(Settings.Builder settings) return this; } - /** - * Sets the source containing the transient settings to be updated. They will not survive a full cluster restart - * @deprecated use {@link #transientSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public ClusterUpdateSettingsRequest transientSettings(String source) { - this.transientSettings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * Sets the source containing the transient settings to be updated. They will not survive a full cluster restart */ @@ -130,16 +120,6 @@ public ClusterUpdateSettingsRequest persistentSettings(Settings.Builder settings return this; } - /** - * Sets the source containing the persistent settings to be updated. They will get applied cross restarts - * @deprecated use {@link #persistentSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public ClusterUpdateSettingsRequest persistentSettings(String source) { - this.persistentSettings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * Sets the source containing the persistent settings to be updated. They will get applied cross restarts */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java index 906b1867b1f09..6d58c989a8f32 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsRequestBuilder.java @@ -51,16 +51,6 @@ public ClusterUpdateSettingsRequestBuilder setTransientSettings(Settings.Builder return this; } - /** - * Sets the source containing the transient settings to be updated. They will not survive a full cluster restart - * @deprecated use {@link #setTransientSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public ClusterUpdateSettingsRequestBuilder setTransientSettings(String settings) { - request.transientSettings(settings); - return this; - } - /** * Sets the source containing the transient settings to be updated. They will not survive a full cluster restart */ @@ -93,16 +83,6 @@ public ClusterUpdateSettingsRequestBuilder setPersistentSettings(Settings.Builde return this; } - /** - * Sets the source containing the persistent settings to be updated. They will get applied cross restarts - * @deprecated use {@link #setPersistentSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public ClusterUpdateSettingsRequestBuilder setPersistentSettings(String settings) { - request.persistentSettings(settings); - return this; - } - /** * Sets the source containing the persistent settings to be updated. They will get applied cross restarts */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java index 3267b6d9c96ed..ae7647af577e3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java @@ -287,21 +287,6 @@ public CreateSnapshotRequest settings(Settings.Builder settings) { return this; } - /** - * Sets repository-specific snapshot settings in JSON or YAML format - *

- * See repository documentation for more information. - * - * @param source repository-specific snapshot settings - * @return this request - * @deprecated use {@link #settings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public CreateSnapshotRequest settings(String source) { - this.settings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * Sets repository-specific snapshot settings in JSON or YAML format *

diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java index d3b5e12351c28..4022d0497c018 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequestBuilder.java @@ -141,21 +141,6 @@ public CreateSnapshotRequestBuilder setSettings(Settings.Builder settings) { return this; } - /** - * Sets repository-specific snapshot settings in YAML, JSON or properties format - *

- * See repository documentation for more information. - * - * @param source repository-specific snapshot settings - * @return this builder - * @deprecated use {@link #setSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public CreateSnapshotRequestBuilder setSettings(String source) { - request.settings(source); - return this; - } - /** * Sets repository-specific snapshot settings in YAML or JSON format *

diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java index 9d8ed49aaa09f..7e34cb5a5967e 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java @@ -312,21 +312,6 @@ public RestoreSnapshotRequest settings(Settings.Builder settings) { return this; } - /** - * Sets repository-specific restore settings in JSON or YAML format - *

- * See repository documentation for more information. - * - * @param source repository-specific snapshot settings - * @return this request - * @deprecated use {@link #settings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public RestoreSnapshotRequest settings(String source) { - this.settings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * Sets repository-specific restore settings in JSON or YAML format *

@@ -450,16 +435,6 @@ public RestoreSnapshotRequest indexSettings(Settings.Builder settings) { return this; } - /** - * Sets settings that should be added/changed in all restored indices - * @deprecated use {@link #indexSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public RestoreSnapshotRequest indexSettings(String source) { - this.indexSettings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * Sets settings that should be added/changed in all restored indices */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java index 807e238724364..8e42ef4dbee29 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequestBuilder.java @@ -153,21 +153,6 @@ public RestoreSnapshotRequestBuilder setSettings(Settings.Builder settings) { return this; } - /** - * Sets repository-specific restore settings in JSON or YAML format - *

- * See repository documentation for more information. - * - * @param source repository-specific snapshot settings - * @return this builder - * @deprecated use {@link #setSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public RestoreSnapshotRequestBuilder setSettings(String source) { - request.settings(source); - return this; - } - /** * Sets repository-specific restore settings in JSON or YAML format *

@@ -263,19 +248,6 @@ public RestoreSnapshotRequestBuilder setIndexSettings(Settings.Builder settings) return this; } - /** - * Sets index settings that should be added or replaced during restore - * - * @param source index settings - * @return this builder - * @deprecated use {@link #setIndexSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public RestoreSnapshotRequestBuilder setIndexSettings(String source) { - request.indexSettings(source); - return this; - } - /** * Sets index settings that should be added or replaced during restore * diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java index 74885800a7454..f6a9e055399a3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java @@ -45,11 +45,6 @@ public PutStoredScriptRequest() { super(); } - @Deprecated - public PutStoredScriptRequest(String id, String lang, BytesReference content) { - this(id, lang, content, XContentFactory.xContentType(content)); - } - public PutStoredScriptRequest(String id, String lang, BytesReference content, XContentType xContentType) { super(); this.id = id; @@ -107,15 +102,6 @@ public XContentType xContentType() { return xContentType; } - /** - * Set the script source using bytes. - * @deprecated this method is deprecated as it relies on content type detection. Use {@link #content(BytesReference, XContentType)} - */ - @Deprecated - public PutStoredScriptRequest content(BytesReference content) { - return content(content, XContentFactory.xContentType(content)); - } - /** * Set the script source and the content type of the bytes. */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java index f8223d691999b..9985a3394e311 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequestBuilder.java @@ -36,16 +36,6 @@ public PutStoredScriptRequestBuilder setId(String id) { return this; } - /** - * Set the source of the script. - * @deprecated this method requires content type detection. Use {@link #setContent(BytesReference, XContentType)} instead - */ - @Deprecated - public PutStoredScriptRequestBuilder setContent(BytesReference content) { - request.content(content); - return this; - } - /** * Set the source of the script along with the content type of the source */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java index 798c08bd180d0..a294d6cb771e3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java @@ -170,16 +170,6 @@ public CreateIndexRequest settings(Settings.Builder settings) { return this; } - /** - * The settings to create the index with (either json or yaml format) - * @deprecated use {@link #source(String, XContentType)} instead to avoid content type detection - */ - @Deprecated - public CreateIndexRequest settings(String source) { - this.settings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * The settings to create the index with (either json or yaml format) */ @@ -215,18 +205,6 @@ public CreateIndexRequest settings(Map source) { return this; } - /** - * Adds mapping that will be added when the index gets created. - * - * @param type The mapping type - * @param source The mapping source - * @deprecated use {@link #mapping(String, String, XContentType)} to avoid content type detection - */ - @Deprecated - public CreateIndexRequest mapping(String type, String source) { - return mapping(type, new BytesArray(source), XContentFactory.xContentType(source)); - } - /** * Adds mapping that will be added when the index gets created. * @@ -362,15 +340,6 @@ public CreateIndexRequest alias(Alias alias) { return this; } - /** - * Sets the settings and mappings as a single source. - * @deprecated use {@link #source(String, XContentType)} - */ - @Deprecated - public CreateIndexRequest source(String source) { - return source(new BytesArray(source)); - } - /** * Sets the settings and mappings as a single source. */ @@ -382,16 +351,7 @@ public CreateIndexRequest source(String source, XContentType xContentType) { * Sets the settings and mappings as a single source. */ public CreateIndexRequest source(XContentBuilder source) { - return source(source.bytes()); - } - - /** - * Sets the settings and mappings as a single source. - * @deprecated use {@link #source(byte[], XContentType)} - */ - @Deprecated - public CreateIndexRequest source(byte[] source) { - return source(source, 0, source.length); + return source(source.bytes(), source.contentType()); } /** @@ -401,15 +361,6 @@ public CreateIndexRequest source(byte[] source, XContentType xContentType) { return source(source, 0, source.length, xContentType); } - /** - * Sets the settings and mappings as a single source. - * @deprecated use {@link #source(byte[], int, int, XContentType)} - */ - @Deprecated - public CreateIndexRequest source(byte[] source, int offset, int length) { - return source(new BytesArray(source, offset, length)); - } - /** * Sets the settings and mappings as a single source. */ @@ -417,17 +368,6 @@ public CreateIndexRequest source(byte[] source, int offset, int length, XContent return source(new BytesArray(source, offset, length), xContentType); } - /** - * Sets the settings and mappings as a single source. - * @deprecated use {@link #source(BytesReference, XContentType)} - */ - @Deprecated - public CreateIndexRequest source(BytesReference source) { - XContentType xContentType = XContentFactory.xContentType(source); - source(source, xContentType); - return this; - } - /** * Sets the settings and mappings as a single source. */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java index 237c88244b4cd..f7cc45511e0bb 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestBuilder.java @@ -110,19 +110,6 @@ public CreateIndexRequestBuilder setSettings(Map source) { return this; } - /** - * Adds mapping that will be added when the index gets created. - * - * @param type The mapping type - * @param source The mapping source - * @deprecated use {@link #addMapping(String, String, XContentType)} to avoid content type auto-detection - */ - @Deprecated - public CreateIndexRequestBuilder addMapping(String type, String source) { - request.mapping(type, source); - return this; - } - /** * Adds mapping that will be added when the index gets created. * @@ -214,16 +201,6 @@ public CreateIndexRequestBuilder addAlias(Alias alias) { return this; } - /** - * Sets the settings and mappings as a single source. - * @deprecated use {@link #setSource(String, XContentType)} - */ - @Deprecated - public CreateIndexRequestBuilder setSource(String source) { - request.source(source); - return this; - } - /** * Sets the settings and mappings as a single source. */ @@ -232,16 +209,6 @@ public CreateIndexRequestBuilder setSource(String source, XContentType xContentT return this; } - /** - * Sets the settings and mappings as a single source. - * @deprecated use {@link #setSource(BytesReference, XContentType)} - */ - @Deprecated - public CreateIndexRequestBuilder setSource(BytesReference source) { - request.source(source); - return this; - } - /** * Sets the settings and mappings as a single source. */ @@ -250,16 +217,6 @@ public CreateIndexRequestBuilder setSource(BytesReference source, XContentType x return this; } - /** - * Sets the settings and mappings as a single source. - * @deprecated use {@link #setSource(byte[], XContentType)} - */ - @Deprecated - public CreateIndexRequestBuilder setSource(byte[] source) { - request.source(source); - return this; - } - /** * Sets the settings and mappings as a single source. */ @@ -268,16 +225,6 @@ public CreateIndexRequestBuilder setSource(byte[] source, XContentType xContentT return this; } - /** - * Sets the settings and mappings as a single source. - * @deprecated use {@link #setSource(byte[], int, int, XContentType)} - */ - @Deprecated - public CreateIndexRequestBuilder setSource(byte[] source, int offset, int length) { - request.source(source, offset, length); - return this; - } - /** * Sets the settings and mappings as a single source. */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index 400701f91ca2f..b0e7056ef1d4e 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -270,15 +270,6 @@ public PutMappingRequest source(Map mappingSource) { } } - /** - * The mapping source definition. - * @deprecated use {@link #source(String, XContentType)} - */ - @Deprecated - public PutMappingRequest source(String mappingSource) { - return source(mappingSource, XContentFactory.xContentType(mappingSource)); - } - /** * The mapping source definition. */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java index 012a593ebc473..43bfe78c4871b 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java @@ -81,16 +81,6 @@ public PutMappingRequestBuilder setSource(Map mappingSource) { return this; } - /** - * The mapping source definition. - * @deprecated use {@link #setSource(String, XContentType)} - */ - @Deprecated - public PutMappingRequestBuilder setSource(String mappingSource) { - request.source(mappingSource); - return this; - } - /** * The mapping source definition. */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java index 80f3fb1a0718d..f07e913e9c82e 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java @@ -120,16 +120,6 @@ public UpdateSettingsRequest settings(Settings.Builder settings) { return this; } - /** - * Sets the settings to be updated (either json or yaml format) - * @deprecated use {@link #settings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public UpdateSettingsRequest settings(String source) { - this.settings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * Sets the settings to be updated (either json or yaml format) */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java index a9cecbfc5a434..8cf86fadc1673 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequestBuilder.java @@ -70,16 +70,6 @@ public UpdateSettingsRequestBuilder setSettings(Settings.Builder settings) { return this; } - /** - * Sets the settings to be updated (either json or yaml format) - * @deprecated use {@link #setSettings(String, XContentType)} to avoid content type detection - */ - @Deprecated - public UpdateSettingsRequestBuilder setSettings(String source) { - request.settings(source); - return this; - } - /** * Sets the settings to be updated (either json or yaml format) */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index b0c13540dfa0b..b954aab7a6778 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -180,16 +180,6 @@ public PutIndexTemplateRequest settings(Settings.Builder settings) { return this; } - /** - * The settings to create the index template with (either json/yaml format). - * @deprecated use {@link #settings(String, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequest settings(String source) { - this.settings = Settings.builder().loadFromSource(source).build(); - return this; - } - /** * The settings to create the index template with (either json/yaml format). */ @@ -216,19 +206,6 @@ public Settings settings() { return this.settings; } - /** - * Adds mapping that will be added when the index gets created. - * - * @param type The mapping type - * @param source The mapping source - * @deprecated use {@link #mapping(String, String, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequest mapping(String type, String source) { - XContentType xContentType = XContentFactory.xContentType(source); - return mapping(type, source, xContentType); - } - /** * Adds mapping that will be added when the index gets created. * @@ -385,15 +362,6 @@ public PutIndexTemplateRequest source(Map templateSource) { return this; } - /** - * The template source definition. - * @deprecated use {@link #source(String, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequest source(String templateSource) { - return source(XContentHelper.convertToMap(XContentFactory.xContent(templateSource), templateSource, true)); - } - /** * The template source definition. */ @@ -401,15 +369,6 @@ public PutIndexTemplateRequest source(String templateSource, XContentType xConte return source(XContentHelper.convertToMap(xContentType.xContent(), templateSource, true)); } - /** - * The template source definition. - * @deprecated use {@link #source(byte[], XContentType)} - */ - @Deprecated - public PutIndexTemplateRequest source(byte[] source) { - return source(source, 0, source.length); - } - /** * The template source definition. */ @@ -417,15 +376,6 @@ public PutIndexTemplateRequest source(byte[] source, XContentType xContentType) return source(source, 0, source.length, xContentType); } - /** - * The template source definition. - * @deprecated use {@link #source(byte[], int, int, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequest source(byte[] source, int offset, int length) { - return source(new BytesArray(source, offset, length)); - } - /** * The template source definition. */ @@ -433,15 +383,6 @@ public PutIndexTemplateRequest source(byte[] source, int offset, int length, XCo return source(new BytesArray(source, offset, length), xContentType); } - /** - * The template source definition. - * @deprecated use {@link #source(BytesReference, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequest source(BytesReference source) { - return source(XContentHelper.convertToMap(source, true).v2()); - } - /** * The template source definition. */ diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java index e7ca25e51191b..7b365f94ab498 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java @@ -100,16 +100,6 @@ public PutIndexTemplateRequestBuilder setSettings(Settings.Builder settings) { return this; } - /** - * The settings to crete the index template with (either json or yaml format) - * @deprecated use {@link #setSettings(String, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequestBuilder setSettings(String source) { - request.settings(source); - return this; - } - /** * The settings to crete the index template with (either json or yaml format) */ @@ -126,19 +116,6 @@ public PutIndexTemplateRequestBuilder setSettings(Map source) { return this; } - /** - * Adds mapping that will be added when the index template gets created. - * - * @param type The mapping type - * @param source The mapping source - * @deprecated use {@link #addMapping(String, String, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequestBuilder addMapping(String type, String source) { - request.mapping(type, source); - return this; - } - /** * Adds mapping that will be added when the index template gets created. * @@ -249,16 +226,6 @@ public PutIndexTemplateRequestBuilder setSource(Map templateSource) { return this; } - /** - * The template source definition. - * @deprecated use {@link #setSource(BytesReference, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequestBuilder setSource(String templateSource) { - request.source(templateSource); - return this; - } - /** * The template source definition. */ @@ -267,26 +234,6 @@ public PutIndexTemplateRequestBuilder setSource(BytesReference templateSource, X return this; } - /** - * The template source definition. - * @deprecated use {@link #setSource(BytesReference, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequestBuilder setSource(BytesReference templateSource) { - request.source(templateSource); - return this; - } - - /** - * The template source definition. - * @deprecated use {@link #setSource(byte[], XContentType)} - */ - @Deprecated - public PutIndexTemplateRequestBuilder setSource(byte[] templateSource) { - request.source(templateSource); - return this; - } - /** * The template source definition. */ @@ -295,16 +242,6 @@ public PutIndexTemplateRequestBuilder setSource(byte[] templateSource, XContentT return this; } - /** - * The template source definition. - * @deprecated use {@link #setSource(byte[], int, int, XContentType)} - */ - @Deprecated - public PutIndexTemplateRequestBuilder setSource(byte[] templateSource, int offset, int length) { - request.source(templateSource, offset, length); - return this; - } - /** * The template source definition. */ diff --git a/core/src/main/java/org/elasticsearch/action/bulk/BulkProcessor.java b/core/src/main/java/org/elasticsearch/action/bulk/BulkProcessor.java index cbfc843162883..fdb2ef3aba260 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/BulkProcessor.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/BulkProcessor.java @@ -289,15 +289,6 @@ private synchronized void internalAdd(DocWriteRequest request, @Nullable Object executeIfNeeded(); } - /** - * Adds the data from the bytes to be processed by the bulk processor - * @deprecated use {@link #add(BytesReference, String, String, XContentType)} instead to avoid content type auto-detection - */ - @Deprecated - public BulkProcessor add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception { - return add(data, defaultIndex, defaultType, null, null); - } - /** * Adds the data from the bytes to be processed by the bulk processor */ @@ -306,19 +297,6 @@ public BulkProcessor add(BytesReference data, @Nullable String defaultIndex, @Nu return add(data, defaultIndex, defaultType, null, null, xContentType); } - /** - * Adds the data from the bytes to be processed by the bulk processor - * @deprecated use {@link #add(BytesReference, String, String, String, Object, XContentType)} instead to avoid content type - * auto-detection - */ - @Deprecated - public synchronized BulkProcessor add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType, - @Nullable String defaultPipeline, @Nullable Object payload) throws Exception { - bulkRequest.add(data, defaultIndex, defaultType, null, null, null, defaultPipeline, payload, true); - executeIfNeeded(); - return this; - } - /** * Adds the data from the bytes to be processed by the bulk processor */ diff --git a/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java b/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java index 450149999ea2a..b60728b9d4587 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java @@ -243,15 +243,6 @@ public long estimatedSizeInBytes() { return sizeInBytes; } - /** - * Adds a framed data in binary format - * @deprecated use {@link #add(byte[], int, int, XContentType)} - */ - @Deprecated - public BulkRequest add(byte[] data, int from, int length) throws IOException { - return add(data, from, length, null, null); - } - /** * Adds a framed data in binary format */ @@ -259,15 +250,6 @@ public BulkRequest add(byte[] data, int from, int length, XContentType xContentT return add(data, from, length, null, null, xContentType); } - /** - * Adds a framed data in binary format - * @deprecated use {@link #add(byte[], int, int, String, String, XContentType)} - */ - @Deprecated - public BulkRequest add(byte[] data, int from, int length, @Nullable String defaultIndex, @Nullable String defaultType) throws IOException { - return add(new BytesArray(data, from, length), defaultIndex, defaultType); - } - /** * Adds a framed data in binary format */ @@ -276,16 +258,6 @@ public BulkRequest add(byte[] data, int from, int length, @Nullable String defau return add(new BytesArray(data, from, length), defaultIndex, defaultType, xContentType); } - /** - * Adds a framed data in binary format - * - * @deprecated use {@link #add(BytesReference, String, String, XContentType)} - */ - @Deprecated - public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType) throws IOException { - return add(data, defaultIndex, defaultType, null, null, null, null, null, true); - } - /** * Adds a framed data in binary format */ @@ -294,16 +266,6 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null return add(data, defaultIndex, defaultType, null, null, null, null, null, true, xContentType); } - /** - * Adds a framed data in binary format - * - * @deprecated use {@link #add(BytesReference, String, String, boolean, XContentType)} - */ - @Deprecated - public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType, boolean allowExplicitIndex) throws IOException { - return add(data, defaultIndex, defaultType, null, null, null, null, null, allowExplicitIndex); - } - /** * Adds a framed data in binary format */ @@ -312,13 +274,6 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null return add(data, defaultIndex, defaultType, null, null, null, null, null, allowExplicitIndex, xContentType); } - @Deprecated - public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable String defaultRouting, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSourceContext, @Nullable String defaultPipeline, @Nullable Object payload, boolean allowExplicitIndex) throws IOException { - XContentType xContentType = XContentFactory.xContentType(data); - return add(data, defaultIndex, defaultType, defaultRouting, defaultFields, defaultFetchSourceContext, defaultPipeline, payload, - allowExplicitIndex, xContentType); - } - public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable String defaultRouting, @Nullable String[] defaultFields, @Nullable FetchSourceContext defaultFetchSourceContext, @Nullable String defaultPipeline, @Nullable Object payload, boolean allowExplicitIndex, XContentType xContentType) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java index 8f634fa28a41b..7d2bca54d15e2 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/BulkRequestBuilder.java @@ -96,16 +96,6 @@ public BulkRequestBuilder add(UpdateRequestBuilder request) { return this; } - /** - * Adds a framed data in binary format - * @deprecated use {@link #add(byte[], int, int, XContentType)} - */ - @Deprecated - public BulkRequestBuilder add(byte[] data, int from, int length) throws Exception { - request.add(data, from, length, null, null); - return this; - } - /** * Adds a framed data in binary format */ @@ -114,16 +104,6 @@ public BulkRequestBuilder add(byte[] data, int from, int length, XContentType xC return this; } - /** - * Adds a framed data in binary format - * @deprecated use {@link #add(byte[], int, int, String, String, XContentType)} - */ - @Deprecated - public BulkRequestBuilder add(byte[] data, int from, int length, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception { - request.add(data, from, length, defaultIndex, defaultType); - return this; - } - /** * Adds a framed data in binary format */ diff --git a/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java index 4ab2eb3b17a40..ca9e41c8e8a6a 100644 --- a/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -121,7 +121,7 @@ public IndexRequest(String index) { /** * Constructs a new index request against the specific index and type. The - * {@link #source(byte[])} must be set. + * {@link #source(byte[], XContentType)} must be set. */ public IndexRequest(String index, String type) { this.index = index; @@ -316,16 +316,6 @@ public IndexRequest source(Map source, XContentType contentType) throws Elastics } } - /** - * Sets the document source to index. - * - * @deprecated use {@link #source(String, XContentType)} - */ - @Deprecated - public IndexRequest source(String source) { - return source(new BytesArray(source), XContentFactory.xContentType(source)); - } - /** * Sets the document source to index. * @@ -383,16 +373,6 @@ public IndexRequest source(XContentType xContentType, Object... source) { } } - /** - * Sets the document to index in bytes form. - * @deprecated use {@link #source(BytesReference, XContentType)} - */ - @Deprecated - public IndexRequest source(BytesReference source) { - return source(source, XContentFactory.xContentType(source)); - - } - /** * Sets the document to index in bytes form. */ @@ -402,15 +382,6 @@ public IndexRequest source(BytesReference source, XContentType xContentType) { return this; } - /** - * Sets the document to index in bytes form. - * @deprecated use {@link #source(byte[], XContentType)} - */ - @Deprecated - public IndexRequest source(byte[] source) { - return source(source, 0, source.length); - } - /** * Sets the document to index in bytes form. */ @@ -418,20 +389,6 @@ public IndexRequest source(byte[] source, XContentType xContentType) { return source(source, 0, source.length, xContentType); } - /** - * Sets the document to index in bytes form (assumed to be safe to be used from different - * threads). - * - * @param source The source to index - * @param offset The offset in the byte array - * @param length The length of the data - * @deprecated use {@link #source(byte[], int, int, XContentType)} - */ - @Deprecated - public IndexRequest source(byte[] source, int offset, int length) { - return source(new BytesArray(source, offset, length), XContentFactory.xContentType(source)); - } - /** * Sets the document to index in bytes form (assumed to be safe to be used from different * threads). diff --git a/core/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java index 7af43ec35eccb..88b094a33f521 100644 --- a/core/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/index/IndexRequestBuilder.java @@ -80,16 +80,6 @@ public IndexRequestBuilder setParent(String parent) { return this; } - /** - * Sets the source. - * @deprecated use {@link #setSource(BytesReference, XContentType)} - */ - @Deprecated - public IndexRequestBuilder setSource(BytesReference source) { - request.source(source); - return this; - } - /** * Sets the source. */ @@ -118,19 +108,6 @@ public IndexRequestBuilder setSource(Map source, XContentType content return this; } - /** - * Sets the document source to index. - *

- * Note, its preferable to either set it using {@link #setSource(org.elasticsearch.common.xcontent.XContentBuilder)} - * or using the {@link #setSource(byte[], XContentType)}. - * @deprecated use {@link #setSource(String, XContentType)} - */ - @Deprecated - public IndexRequestBuilder setSource(String source) { - request.source(source); - return this; - } - /** * Sets the document source to index. *

@@ -150,16 +127,6 @@ public IndexRequestBuilder setSource(XContentBuilder sourceBuilder) { return this; } - /** - * Sets the document to index in bytes form. - * @deprecated use {@link #setSource(byte[], XContentType)} - */ - @Deprecated - public IndexRequestBuilder setSource(byte[] source) { - request.source(source); - return this; - } - /** * Sets the document to index in bytes form. */ @@ -168,21 +135,6 @@ public IndexRequestBuilder setSource(byte[] source, XContentType xContentType) { return this; } - /** - * Sets the document to index in bytes form (assumed to be safe to be used from different - * threads). - * - * @param source The source to index - * @param offset The offset in the byte array - * @param length The length of the data - * @deprecated use {@link #setSource(byte[], int, int, XContentType)} - */ - @Deprecated - public IndexRequestBuilder setSource(byte[] source, int offset, int length) { - request.source(source, offset, length); - return this; - } - /** * Sets the document to index in bytes form (assumed to be safe to be used from different * threads). diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index 930943ea0f270..d34865b687258 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -553,16 +553,6 @@ public UpdateRequest doc(Map source, XContentType contentType) { return this; } - /** - * Sets the doc to use for updates when a script is not specified. - * @deprecated use {@link #doc(String, XContentType)} - */ - @Deprecated - public UpdateRequest doc(String source) { - safeDoc().source(source); - return this; - } - /** * Sets the doc to use for updates when a script is not specified. */ @@ -571,16 +561,6 @@ public UpdateRequest doc(String source, XContentType xContentType) { return this; } - /** - * Sets the doc to use for updates when a script is not specified. - * @deprecated use {@link #doc(byte[], XContentType)} - */ - @Deprecated - public UpdateRequest doc(byte[] source) { - safeDoc().source(source); - return this; - } - /** * Sets the doc to use for updates when a script is not specified. */ @@ -589,16 +569,6 @@ public UpdateRequest doc(byte[] source, XContentType xContentType) { return this; } - /** - * Sets the doc to use for updates when a script is not specified. - * @deprecated use {@link #doc(byte[], int, int, XContentType)} - */ - @Deprecated - public UpdateRequest doc(byte[] source, int offset, int length) { - safeDoc().source(source, offset, length); - return this; - } - /** * Sets the doc to use for updates when a script is not specified. */ @@ -669,16 +639,6 @@ public UpdateRequest upsert(Map source, XContentType contentType) { return this; } - /** - * Sets the doc source of the update request to be used when the document does not exists. - * @deprecated use {@link #upsert(String, XContentType)} - */ - @Deprecated - public UpdateRequest upsert(String source) { - safeUpsertRequest().source(source); - return this; - } - /** * Sets the doc source of the update request to be used when the document does not exists. */ @@ -687,16 +647,6 @@ public UpdateRequest upsert(String source, XContentType xContentType) { return this; } - /** - * Sets the doc source of the update request to be used when the document does not exists. - * @deprecated use {@link #upsert(byte[], XContentType)} - */ - @Deprecated - public UpdateRequest upsert(byte[] source) { - safeUpsertRequest().source(source); - return this; - } - /** * Sets the doc source of the update request to be used when the document does not exists. */ @@ -705,16 +655,6 @@ public UpdateRequest upsert(byte[] source, XContentType xContentType) { return this; } - /** - * Sets the doc source of the update request to be used when the document does not exists. - * @deprecated use {@link #upsert(byte[], int, int, XContentType)} - */ - @Deprecated - public UpdateRequest upsert(byte[] source, int offset, int length) { - safeUpsertRequest().source(source, offset, length); - return this; - } - /** * Sets the doc source of the update request to be used when the document does not exists. */ diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java index 92b2ce6d7d872..5ba187013e79f 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequestBuilder.java @@ -221,16 +221,6 @@ public UpdateRequestBuilder setDoc(Map source, XContentType contentType) { return this; } - /** - * Sets the doc to use for updates when a script is not specified. - * @deprecated use {@link #setDoc(String, XContentType)} - */ - @Deprecated - public UpdateRequestBuilder setDoc(String source) { - request.doc(source); - return this; - } - /** * Sets the doc to use for updates when a script is not specified. */ @@ -239,16 +229,6 @@ public UpdateRequestBuilder setDoc(String source, XContentType xContentType) { return this; } - /** - * Sets the doc to use for updates when a script is not specified. - * @deprecated use {@link #setDoc(byte[], XContentType)} - */ - @Deprecated - public UpdateRequestBuilder setDoc(byte[] source) { - request.doc(source); - return this; - } - /** * Sets the doc to use for updates when a script is not specified. */ @@ -257,16 +237,6 @@ public UpdateRequestBuilder setDoc(byte[] source, XContentType xContentType) { return this; } - /** - * Sets the doc to use for updates when a script is not specified. - * @deprecated use {@link #setDoc(byte[], int, int, XContentType)} - */ - @Deprecated - public UpdateRequestBuilder setDoc(byte[] source, int offset, int length) { - request.doc(source, offset, length); - return this; - } - /** * Sets the doc to use for updates when a script is not specified. */ @@ -326,16 +296,6 @@ public UpdateRequestBuilder setUpsert(Map source, XContentType contentType) { return this; } - /** - * Sets the doc source of the update request to be used when the document does not exists. - * @deprecated use {@link #setUpsert(String, XContentType)} - */ - @Deprecated - public UpdateRequestBuilder setUpsert(String source) { - request.upsert(source); - return this; - } - /** * Sets the doc source of the update request to be used when the document does not exists. */ @@ -344,16 +304,6 @@ public UpdateRequestBuilder setUpsert(String source, XContentType xContentType) return this; } - /** - * Sets the doc source of the update request to be used when the document does not exists. - * @deprecated use {@link #setDoc(byte[], XContentType)} - */ - @Deprecated - public UpdateRequestBuilder setUpsert(byte[] source) { - request.upsert(source); - return this; - } - /** * Sets the doc source of the update request to be used when the document does not exists. */ @@ -362,16 +312,6 @@ public UpdateRequestBuilder setUpsert(byte[] source, XContentType xContentType) return this; } - /** - * Sets the doc source of the update request to be used when the document does not exists. - * @deprecated use {@link #setUpsert(byte[], int, int, XContentType)} - */ - @Deprecated - public UpdateRequestBuilder setUpsert(byte[] source, int offset, int length) { - request.upsert(source, offset, length); - return this; - } - /** * Sets the doc source of the update request to be used when the document does not exists. */ diff --git a/core/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java b/core/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java index 12e5ea6d5d965..800304a95ac59 100644 --- a/core/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java +++ b/core/src/main/java/org/elasticsearch/cluster/action/index/MappingUpdatedAction.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.Index; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.Mapping; @@ -68,7 +69,7 @@ private PutMappingRequestBuilder updateMappingRequest(Index index, String type, if (type.equals(MapperService.DEFAULT_MAPPING)) { throw new IllegalArgumentException("_default_ mapping should not be updated"); } - return client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString()) + return client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString(), XContentType.JSON) .setMasterNodeTimeout(timeout).setTimeout(timeout); } diff --git a/core/src/main/java/org/elasticsearch/http/HttpTransportSettings.java b/core/src/main/java/org/elasticsearch/http/HttpTransportSettings.java index b5e254aa4c2ef..9bf8be2da45dd 100644 --- a/core/src/main/java/org/elasticsearch/http/HttpTransportSettings.java +++ b/core/src/main/java/org/elasticsearch/http/HttpTransportSettings.java @@ -19,6 +19,7 @@ package org.elasticsearch.http; +import org.elasticsearch.common.Booleans; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.transport.PortsRange; @@ -69,7 +70,14 @@ public final class HttpTransportSettings { public static final Setting SETTING_HTTP_DETAILED_ERRORS_ENABLED = Setting.boolSetting("http.detailed_errors.enabled", true, Property.NodeScope); public static final Setting SETTING_HTTP_CONTENT_TYPE_REQUIRED = - Setting.boolSetting("http.content_type.required", false, Property.NodeScope); + new Setting<>("http.content_type.required", (s) -> Boolean.toString(true), (s) -> { + final boolean value = Booleans.parseBoolean(s); + if (value == false) { + throw new IllegalArgumentException("http.content_type.required cannot be set to false. It exists only to make a rolling" + + " upgrade easier"); + } + return true; + }, Property.NodeScope, Property.Deprecated); public static final Setting SETTING_HTTP_MAX_CONTENT_LENGTH = Setting.byteSizeSetting("http.max_content_length", new ByteSizeValue(100, ByteSizeUnit.MB), Property.NodeScope); public static final Setting SETTING_HTTP_MAX_CHUNK_SIZE = diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 39675ffce828b..a4e4c83bc0079 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -69,6 +69,7 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.ShardLock; import org.elasticsearch.env.ShardLockObtainFailedException; @@ -509,7 +510,7 @@ public IndexShard createShard(ShardRouting shardRouting, RecoveryState recoveryS client.admin().indices().preparePutMapping() .setConcreteIndex(shardRouting.index()) // concrete index - no name clash, it uses uuid .setType(type) - .setSource(mapping.source().string()) + .setSource(mapping.source().string(), XContentType.JSON) .get(); } catch (IOException ex) { throw new ElasticsearchException("failed to stringify mapping source", ex); diff --git a/core/src/main/java/org/elasticsearch/rest/RestController.java b/core/src/main/java/org/elasticsearch/rest/RestController.java index 5f033eb4aff1a..8e67a2e74419f 100644 --- a/core/src/main/java/org/elasticsearch/rest/RestController.java +++ b/core/src/main/java/org/elasticsearch/rest/RestController.java @@ -34,10 +34,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.http.HttpServerTransport; -import org.elasticsearch.http.HttpTransportSettings; import org.elasticsearch.indices.breaker.CircuitBreakerService; import java.io.ByteArrayOutputStream; @@ -75,10 +73,6 @@ public class RestController extends AbstractComponent implements HttpServerTrans /** Rest headers that are copied to internal requests made during a rest request. */ private final Set headersToCopy; - private final boolean isContentTypeRequired; - - private final DeprecationLogger deprecationLogger; - public RestController(Settings settings, Set headersToCopy, UnaryOperator handlerWrapper, NodeClient client, CircuitBreakerService circuitBreakerService) { super(settings); @@ -89,8 +83,6 @@ public RestController(Settings settings, Set headersToCopy, UnaryOperato this.handlerWrapper = handlerWrapper; this.client = client; this.circuitBreakerService = circuitBreakerService; - this.isContentTypeRequired = HttpTransportSettings.SETTING_HTTP_CONTENT_TYPE_REQUIRED.get(settings); - this.deprecationLogger = new DeprecationLogger(logger); } /** @@ -182,7 +174,7 @@ public void dispatchRequest(RestRequest request, RestChannel channel, ThreadCont assert contentLength >= 0 : "content length was negative, how is that possible?"; final RestHandler handler = getHandler(request); - if (contentLength > 0 && hasContentTypeOrCanAutoDetect(request, handler) == false) { + if (contentLength > 0 && hasContentType(request, handler) == false) { sendContentTypeErrorMessage(request, responseChannel); } else if (contentLength > 0 && handler != null && handler.supportsContentStream() && request.getXContentType() != XContentType.JSON && request.getXContentType() != XContentType.SMILE) { @@ -266,43 +258,19 @@ void dispatchRequest(final RestRequest request, final RestChannel channel, final /** * If a request contains content, this method will return {@code true} if the {@code Content-Type} header is present, matches an - * {@link XContentType} or the request is plain text, and content type is required. If content type is not required then this method - * returns true unless a content type could not be inferred from the body and the rest handler does not support plain text + * {@link XContentType} or the handler supports a content stream and the content type header is for newline delimited JSON, */ - private boolean hasContentTypeOrCanAutoDetect(final RestRequest restRequest, final RestHandler restHandler) { + private boolean hasContentType(final RestRequest restRequest, final RestHandler restHandler) { if (restRequest.getXContentType() == null) { - if (restHandler != null && restHandler.supportsPlainText()) { - // content type of null with a handler that supports plain text gets through for now. Once we remove plain text this can - // be removed! - deprecationLogger.deprecated("Plain text request bodies are deprecated. Use request parameters or body " + - "in a supported format."); - } else if (restHandler != null && restHandler.supportsContentStream() && restRequest.header("Content-Type") != null) { + if (restHandler != null && restHandler.supportsContentStream() && restRequest.header("Content-Type") != null) { final String lowercaseMediaType = restRequest.header("Content-Type").toLowerCase(Locale.ROOT); // we also support newline delimited JSON: http://specs.okfnlabs.org/ndjson/ if (lowercaseMediaType.equals("application/x-ndjson")) { restRequest.setXContentType(XContentType.JSON); - } else if (isContentTypeRequired) { - return false; - } else { - return autoDetectXContentType(restRequest); + return true; } - } else if (isContentTypeRequired) { - return false; - } else { - return autoDetectXContentType(restRequest); } - } - return true; - } - - private boolean autoDetectXContentType(RestRequest restRequest) { - deprecationLogger.deprecated("Content type detection for rest requests is deprecated. Specify the content type using " + - "the [Content-Type] header."); - XContentType xContentType = XContentFactory.xContentType(restRequest.content()); - if (xContentType == null) { return false; - } else { - restRequest.setXContentType(xContentType); } return true; } diff --git a/core/src/main/java/org/elasticsearch/rest/RestHandler.java b/core/src/main/java/org/elasticsearch/rest/RestHandler.java index 215541b40e87f..1ebc7a7fd1bd2 100644 --- a/core/src/main/java/org/elasticsearch/rest/RestHandler.java +++ b/core/src/main/java/org/elasticsearch/rest/RestHandler.java @@ -39,15 +39,6 @@ default boolean canTripCircuitBreaker() { return true; } - /** - * Indicates if a RestHandler supports plain text bodies - * @deprecated use request parameters or bodies that can be parsed with XContent! - */ - @Deprecated - default boolean supportsPlainText() { - return false; - } - /** * Indicates if the RestHandler supports content as a stream. A stream would be multiple objects delineated by * {@link XContent#streamSeparator()}. If a handler returns true this will affect the types of content that can be sent to diff --git a/core/src/main/java/org/elasticsearch/rest/RestRequest.java b/core/src/main/java/org/elasticsearch/rest/RestRequest.java index 9aea6d213f797..509bfa7a3c0eb 100644 --- a/core/src/main/java/org/elasticsearch/rest/RestRequest.java +++ b/core/src/main/java/org/elasticsearch/rest/RestRequest.java @@ -28,13 +28,10 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; @@ -54,7 +51,6 @@ public abstract class RestRequest implements ToXContent.Params { - private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(RestRequest.class)); // tchar pattern as defined by RFC7230 section 3.2.6 private static final Pattern TCHAR_PATTERN = Pattern.compile("[a-zA-z0-9!#$%&'*+\\-.\\^_`|~]+"); @@ -407,66 +403,17 @@ public final Tuple contentOrSourceParam() { String source = param("source"); String typeParam = param("source_content_type"); - if (source != null) { + if (source != null && typeParam != null) { BytesArray bytes = new BytesArray(source); - final XContentType xContentType; - if (typeParam != null) { - xContentType = parseContentType(Collections.singletonList(typeParam)); - } else { - DEPRECATION_LOGGER.deprecated("Deprecated use of the [source] parameter without the [source_content_type] parameter. Use " + - "the [source_content_type] parameter to specify the content type of the source such as [application/json]"); - xContentType = XContentFactory.xContentType(bytes); - } - + final XContentType xContentType = parseContentType(Collections.singletonList(typeParam)); if (xContentType == null) { - throw new IllegalStateException("could not determine source content type"); + throw new IllegalStateException("Unknown value for source_content_type [" + typeParam + "]"); } return new Tuple<>(xContentType, bytes); } return new Tuple<>(XContentType.JSON, BytesArray.EMPTY); } - /** - * Call a consumer with the parser for the contents of this request if it has contents, otherwise with a parser for the {@code source} - * parameter if there is one, otherwise with {@code null}. Use {@link #contentOrSourceParamParser()} if you should throw an exception - * back to the user when there isn't request content. This version allows for plain text content - */ - @Deprecated - public final void withContentOrSourceParamParserOrNullLenient(CheckedConsumer withParser) - throws IOException { - if (hasContent() && xContentType.get() == null) { - withParser.accept(null); - } - - Tuple tuple = contentOrSourceParam(); - BytesReference content = tuple.v2(); - XContentType xContentType = tuple.v1(); - if (content.length() > 0) { - try (XContentParser parser = xContentType.xContent().createParser(xContentRegistry, content)) { - withParser.accept(parser); - } - } else { - withParser.accept(null); - } - } - - /** - * Get the content of the request or the contents of the {@code source} param without the xcontent type. This is useful the request can - * accept non xcontent values. - * @deprecated we should only take xcontent - */ - @Deprecated - public final BytesReference getContentOrSourceParamOnly() { - if (hasContent()) { - return content(); - } - String source = param("source"); - if (source != null) { - return new BytesArray(source); - } - return BytesArray.EMPTY; - } - /** * Parses the given content type string for the media type. This method currently ignores parameters. */ diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java index 47252f5a10217..5f39db3a357e1 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java @@ -22,7 +22,6 @@ import org.elasticsearch.action.search.ClearScrollRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; @@ -48,15 +47,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC String scrollIds = request.param("scroll_id"); ClearScrollRequest clearRequest = new ClearScrollRequest(); clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds))); - request.withContentOrSourceParamParserOrNullLenient((xContentParser -> { - if (xContentParser == null) { - if (request.hasContent()) { - // TODO: why do we accept this plain text value? maybe we can just use the scroll params? - BytesReference body = request.content(); - String bodyScrollIds = body.utf8ToString(); - clearRequest.setScrollIds(Arrays.asList(splitScrollIds(bodyScrollIds))); - } - } else { + request.withContentOrSourceParamParserOrNull((xContentParser -> { + if (xContentParser != null) { // NOTE: if rest request with xcontent body has request parameters, these parameters does not override xcontent value clearRequest.setScrollIds(null); try { @@ -70,11 +62,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC return channel -> client.clearScroll(clearRequest, new RestStatusToXContentListener<>(channel)); } - @Override - public boolean supportsPlainText() { - return true; - } - private static String[] splitScrollIds(String scrollIds) { if (scrollIds == null) { return Strings.EMPTY_ARRAY; diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java index 2a60fc6317a3c..feba6640b65a1 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java @@ -21,7 +21,6 @@ import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; @@ -58,32 +57,17 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC } request.withContentOrSourceParamParserOrNull(xContentParser -> { - if (xContentParser == null) { - if (request.hasContent()) { - // TODO: why do we accept this plain text value? maybe we can just use the scroll params? - BytesReference body = request.getContentOrSourceParamOnly(); - if (scrollId == null) { - String bodyScrollId = body.utf8ToString(); - searchScrollRequest.scrollId(bodyScrollId); - } - } - } else { + if (xContentParser != null) { // NOTE: if rest request with xcontent body has request parameters, these parameters override xcontent values try { buildFromContent(xContentParser, searchScrollRequest); } catch (IOException e) { throw new IllegalArgumentException("Failed to parse request body", e); } - } - }); + }}); return channel -> client.searchScroll(searchScrollRequest, new RestStatusToXContentListener<>(channel)); } - @Override - public boolean supportsPlainText() { - return true; - } - public static void buildFromContent(XContentParser parser, SearchScrollRequest searchScrollRequest) throws IOException { if (parser.nextToken() != XContentParser.Token.START_OBJECT) { throw new IllegalArgumentException("Malformed content, must start with an object"); diff --git a/core/src/main/java/org/elasticsearch/tasks/TaskResultsService.java b/core/src/main/java/org/elasticsearch/tasks/TaskResultsService.java index 58f623bd436ef..69549c611f1e6 100644 --- a/core/src/main/java/org/elasticsearch/tasks/TaskResultsService.java +++ b/core/src/main/java/org/elasticsearch/tasks/TaskResultsService.java @@ -43,6 +43,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.ResourceAlreadyExistsException; +import org.elasticsearch.common.xcontent.XContentType; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -82,7 +83,7 @@ public void storeResult(TaskResult taskResult, ActionListener listener) { CreateIndexRequest createIndexRequest = new CreateIndexRequest(); createIndexRequest.settings(taskResultIndexSettings()); createIndexRequest.index(TASK_INDEX); - createIndexRequest.mapping(TASK_TYPE, taskResultIndexMapping()); + createIndexRequest.mapping(TASK_TYPE, taskResultIndexMapping(), XContentType.JSON); createIndexRequest.cause("auto(task api)"); createIndexAction.execute(null, createIndexRequest, new ActionListener() { @@ -110,7 +111,8 @@ public void onFailure(Exception e) { IndexMetaData metaData = state.getMetaData().index(TASK_INDEX); if (metaData.getMappings().containsKey(TASK_TYPE) == false) { // The index already exists but doesn't have our mapping - client.admin().indices().preparePutMapping(TASK_INDEX).setType(TASK_TYPE).setSource(taskResultIndexMapping()) + client.admin().indices().preparePutMapping(TASK_INDEX).setType(TASK_TYPE) + .setSource(taskResultIndexMapping(), XContentType.JSON) .execute(new ActionListener() { @Override public void onResponse(PutMappingResponse putMappingResponse) { diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java index 74416742d12cb..722482837a30f 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java @@ -25,6 +25,7 @@ import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.test.ESIntegTestCase; @@ -48,7 +49,7 @@ public class GetIndexIT extends ESIntegTestCase { @Override protected void setupSuiteScopeCluster() throws Exception { - assertAcked(prepareCreate("idx").addAlias(new Alias("alias_idx")).addMapping("type1", "{\"type1\":{}}") + assertAcked(prepareCreate("idx").addAlias(new Alias("alias_idx")).addMapping("type1", "{\"type1\":{}}", XContentType.JSON) .setSettings(Settings.builder().put("number_of_shards", 1)).get()); ensureSearchable("idx"); createIndex("empty_idx"); diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java index 15cb43d89a927..d2b63ad396583 100644 --- a/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java @@ -243,7 +243,7 @@ public void testSmileIsSupported() throws IOException { } BulkRequest bulkRequest = new BulkRequest(); - bulkRequest.add(data, null, null); + bulkRequest.add(data, null, null, xContentType); assertEquals(1, bulkRequest.requests().size()); DocWriteRequest docWriteRequest = bulkRequest.requests().get(0); assertEquals(DocWriteRequest.OpType.INDEX, docWriteRequest.opType()); diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java index b31426e3978dd..da16b688340fa 100644 --- a/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java +++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java @@ -455,8 +455,8 @@ public void testBulkIndexingWhileInitializing() throws Exception { */ public void testBulkUpdateDocAsUpsertWithParent() throws Exception { client().admin().indices().prepareCreate("test") - .addMapping("parent", "{\"parent\":{}}") - .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}") + .addMapping("parent", "{\"parent\":{}}", XContentType.JSON) + .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON) .execute().actionGet(); ensureGreen(); @@ -519,8 +519,8 @@ public void testBulkUpdateDocAsUpsertWithParent() throws Exception { */ public void testBulkUpdateUpsertWithParent() throws Exception { assertAcked(prepareCreate("test") - .addMapping("parent", "{\"parent\":{}}") - .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}")); + .addMapping("parent", "{\"parent\":{}}", XContentType.JSON) + .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON)); ensureGreen(); BulkRequestBuilder builder = client().prepareBulk(); @@ -603,8 +603,8 @@ public void testBulkUpdateUpsertWithParent() throws Exception { * Test for https://github.com/elastic/elasticsearch/issues/8365 */ public void testBulkUpdateChildMissingParentRouting() throws Exception { - assertAcked(prepareCreate("test").addMapping("parent", "{\"parent\":{}}").addMapping("child", - "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}")); + assertAcked(prepareCreate("test").addMapping("parent", "{\"parent\":{}}", XContentType.JSON) + .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON)); ensureGreen(); BulkRequestBuilder builder = client().prepareBulk(); diff --git a/core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java b/core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java index 55d51a42677cf..5b9649a7559c8 100644 --- a/core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/index/IndexRequestTests.java @@ -209,11 +209,11 @@ public void testToStringSizeLimit() throws UnsupportedEncodingException { IndexRequest request = new IndexRequest("index", "type"); String source = "{\"name\":\"value\"}"; - request.source(source); + request.source(source, XContentType.JSON); assertEquals("index {[index][type][null], source[" + source + "]}", request.toString()); source = "{\"name\":\"" + randomUnicodeOfLength(IndexRequest.MAX_SOURCE_LENGTH_IN_TOSTRING) + "\"}"; - request.source(source); + request.source(source, XContentType.JSON); int actualBytes = source.getBytes("UTF-8").length; assertEquals("index {[index][type][null], source[n/a, actual length: [" + new ByteSizeValue(actualBytes).toString() + "], max length: " + new ByteSizeValue(IndexRequest.MAX_SOURCE_LENGTH_IN_TOSTRING).toString() + "]}", request.toString()); diff --git a/core/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java b/core/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java index c033ad7ff2737..0770fb2c4dc84 100644 --- a/core/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java @@ -22,6 +22,7 @@ import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.discovery.MasterNotDiscoveredException; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.node.Node; @@ -129,7 +130,8 @@ public void testAliasFilterValidation() throws Exception { logger.info("--> start data node / non master node"); internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false)); - assertAcked(prepareCreate("test").addMapping("type1", "{\"type1\" : {\"properties\" : {\"table_a\" : { \"type\" : \"nested\", \"properties\" : {\"field_a\" : { \"type\" : \"keyword\" },\"field_b\" :{ \"type\" : \"keyword\" }}}}}}")); + assertAcked(prepareCreate("test").addMapping("type1", "{\"type1\" : {\"properties\" : {\"table_a\" : { \"type\" : \"nested\", " + + "\"properties\" : {\"field_a\" : { \"type\" : \"keyword\" },\"field_b\" :{ \"type\" : \"keyword\" }}}}}}", XContentType.JSON)); client().admin().indices().prepareAliases().addAlias("test", "a_test", QueryBuilders.nestedQuery("table_a", QueryBuilders.termQuery("table_a.field_b", "y"), ScoreMode.Avg)).get(); } } diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java index c3e544f9b2b84..9fd90e3c314e0 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperParsingException; @@ -73,8 +74,8 @@ public void testAddExtraChildTypePointingToAlreadyParentExistingType() throws Ex public void testParentIsAString() throws Exception { // Shouldn't be able the add the _parent field pointing to an already existing type, which isn't a parent type Exception e = expectThrows(MapperParsingException.class, () -> client().admin().indices().prepareCreate("test") - .addMapping("parent", "{\"properties\":{}}") - .addMapping("child", "{\"_parent\": \"parent\",\"properties\":{}}") + .addMapping("parent", "{\"properties\":{}}", XContentType.JSON) + .addMapping("child", "{\"_parent\": \"parent\",\"properties\":{}}", XContentType.JSON) .get()); assertEquals("Failed to parse mapping [child]: [_parent] must be an object containing [type]", e.getMessage()); } diff --git a/core/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java b/core/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java index 25153576b6b2b..6f79922075bf9 100644 --- a/core/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java +++ b/core/src/test/java/org/elasticsearch/gateway/GatewayIndexStateIT.java @@ -38,6 +38,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.discovery.zen.ElectMasterService; import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment; @@ -459,7 +460,7 @@ public void testRecoverMissingAnalyzer() throws Exception { " }\n" + " }\n" + " }\n" + - " }}").get(); + " }}", XContentType.JSON).get(); logger.info("--> indexing a simple document"); client().prepareIndex("test", "type1", "1").setSource("field1", "value one").setRefreshPolicy(IMMEDIATE).get(); logger.info("--> waiting for green status"); diff --git a/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java b/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java index bc341d339ce39..f957a55bf1409 100644 --- a/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java +++ b/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.Index; @@ -86,7 +87,7 @@ public void testOneNodeRecoverFromGateway() throws Exception { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("properties").startObject("appAccountIds").field("type", "text").endObject().endObject() .endObject().endObject().string(); - assertAcked(prepareCreate("test").addMapping("type1", mapping)); + assertAcked(prepareCreate("test").addMapping("type1", mapping, XContentType.JSON)); client().prepareIndex("test", "type1", "10990239").setSource(jsonBuilder().startObject() .startArray("appAccountIds").value(14).value(179).endArray().endObject()).execute().actionGet(); @@ -160,7 +161,7 @@ public void testSingleNodeNoFlush() throws Exception { assertAcked(prepareCreate("test").setSettings( SETTING_NUMBER_OF_SHARDS, numberOfShards(), SETTING_NUMBER_OF_REPLICAS, randomIntBetween(0, 1) - ).addMapping("type1", mapping)); + ).addMapping("type1", mapping, XContentType.JSON)); int value1Docs; int value2Docs; diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java index 577087ba9522b..2797ae7fcc844 100644 --- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -253,8 +253,8 @@ public void testGetDocWithMultivaluedFields() throws Exception { .endObject() .endObject().endObject().string(); assertAcked(prepareCreate("test") - .addMapping("type1", mapping1) - .addMapping("type2", mapping2) + .addMapping("type1", mapping1, XContentType.JSON) + .addMapping("type2", mapping2, XContentType.JSON) .setSettings(Settings.builder().put("index.refresh_interval", -1))); ensureGreen(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java b/core/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java index 7bf23fa4184e9..6e841509c0d92 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/CamelCaseFieldNameTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.mapper; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.ParsedDocument; @@ -31,7 +32,7 @@ public void testCamelCaseFieldNameStaysAsIs() throws Exception { .endObject().endObject().string(); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper documentMapper = index.mapperService().documentMapper("type"); ParsedDocument doc = documentMapper.parse("test", "type", "1", XContentFactory.jsonBuilder().startObject() @@ -39,7 +40,8 @@ public void testCamelCaseFieldNameStaysAsIs() throws Exception { .endObject().bytes()); assertNotNull(doc.dynamicMappingsUpdate()); - client().admin().indices().preparePutMapping("test").setType("type").setSource(doc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("type") + .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); documentMapper = index.mapperService().documentMapper("type"); assertNotNull(documentMapper.mappers().getMapper("thisIsCamelCase")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java b/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java index c78bd33652831..eddc51348f912 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperIntegrationIT.java @@ -22,6 +22,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; @@ -76,7 +77,7 @@ public void testDynamicObjectCopyTo() throws Exception { .endObject().endObject().endObject().string(); assertAcked( client().admin().indices().prepareCreate("test-idx") - .addMapping("doc", mapping) + .addMapping("doc", mapping, XContentType.JSON) ); client().prepareIndex("test-idx", "doc", "1") .setSource("foo", "bar") diff --git a/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java index f5f8334d8603e..85fddfc800103 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/CopyToMapperTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.ParseContext.Document; @@ -66,7 +67,7 @@ public void testCopyToFieldsParsing() throws Exception { .endObject().endObject().endObject().string(); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("type1").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("type1").setSource(mapping, XContentType.JSON).get(); DocumentMapper docMapper = index.mapperService().documentMapper("type1"); FieldMapper fieldMapper = docMapper.mappers().getMapper("copy_test"); @@ -114,7 +115,8 @@ public void testCopyToFieldsParsing() throws Exception { assertThat(doc.getFields("new_field")[0].numericValue().intValue(), equalTo(42)); assertNotNull(parsedDoc.dynamicMappingsUpdate()); - client().admin().indices().preparePutMapping("test").setType("type1").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("type1") + .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("type1"); fieldMapper = docMapper.mappers().getMapper("new_field"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index 314157650d637..db748143576f3 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -38,6 +38,7 @@ import org.elasticsearch.common.lucene.all.AllField; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.ParseContext.Document; import org.elasticsearch.plugins.Plugin; @@ -1273,7 +1274,7 @@ public void testDynamicFieldsStartingAndEndingWithDot() throws Exception { .endObject().endArray() .endObject().bytes(); - client().prepareIndex("idx", "type").setSource(bytes).get(); + client().prepareIndex("idx", "type").setSource(bytes, XContentType.JSON).get(); bytes = XContentFactory.jsonBuilder().startObject().startArray("top.") .startObject().startArray("foo.") @@ -1288,7 +1289,7 @@ public void testDynamicFieldsStartingAndEndingWithDot() throws Exception { .endObject().bytes(); try { - client().prepareIndex("idx", "type").setSource(bytes).get(); + client().prepareIndex("idx", "type").setSource(bytes, XContentType.JSON).get(); fail("should have failed to dynamically introduce a double-dot field"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java index af217030f2c1a..85e186e2f8221 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DoubleIndexingDocTests.java @@ -26,6 +26,7 @@ import org.apache.lucene.store.Directory; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.ParsedDocument; @@ -43,7 +44,7 @@ public void testDoubleIndexingSameDoc() throws Exception { .startObject("properties").endObject() .endObject().endObject().string(); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper mapper = index.mapperService().documentMapper("type"); QueryShardContext context = index.newQueryShardContext(0, null, () -> 0L); @@ -57,7 +58,8 @@ public void testDoubleIndexingSameDoc() throws Exception { .endObject() .bytes()); assertNotNull(doc.dynamicMappingsUpdate()); - client().admin().indices().preparePutMapping("test").setType("type").setSource(doc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("type") + .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); mapper = index.mapperService().documentMapper("type"); writer.addDocument(doc.rootDoc()); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java index 41256113cd6bf..344f3debdf6b6 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.BooleanFieldMapper.BooleanFieldType; @@ -599,7 +600,7 @@ public void testNumericDetectionEnabled() throws Exception { .endObject().endObject().string(); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper defaultMapper = index.mapperService().documentMapper("type"); ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder() @@ -609,7 +610,8 @@ public void testNumericDetectionEnabled() throws Exception { .endObject() .bytes()); assertNotNull(doc.dynamicMappingsUpdate()); - client().admin().indices().preparePutMapping("test").setType("type").setSource(doc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("type") + .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); defaultMapper = index.mapperService().documentMapper("type"); FieldMapper mapper = defaultMapper.mappers().smartNameFieldMapper("s_long"); @@ -624,7 +626,7 @@ public void testNumericDetectionDefault() throws Exception { .endObject().endObject().string(); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper defaultMapper = index.mapperService().documentMapper("type"); ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder() @@ -634,7 +636,8 @@ public void testNumericDetectionDefault() throws Exception { .endObject() .bytes()); assertNotNull(doc.dynamicMappingsUpdate()); - assertAcked(client().admin().indices().preparePutMapping("test").setType("type").setSource(doc.dynamicMappingsUpdate().toString()).get()); + assertAcked(client().admin().indices().preparePutMapping("test").setType("type") + .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get()); defaultMapper = index.mapperService().documentMapper("type"); FieldMapper mapper = defaultMapper.mappers().smartNameFieldMapper("s_long"); @@ -671,7 +674,7 @@ public void testDateDetectionInheritsFormat() throws Exception { .endObject().endObject().string(); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping, XContentType.JSON).get(); DocumentMapper defaultMapper = index.mapperService().documentMapper("type"); ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder() @@ -682,7 +685,8 @@ public void testDateDetectionInheritsFormat() throws Exception { .endObject() .bytes()); assertNotNull(doc.dynamicMappingsUpdate()); - assertAcked(client().admin().indices().preparePutMapping("test").setType("type").setSource(doc.dynamicMappingsUpdate().toString()).get()); + assertAcked(client().admin().indices().preparePutMapping("test").setType("type") + .setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get()); defaultMapper = index.mapperService().documentMapper("type"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java index 9eb5a78529f0a..437dd7cb99d41 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplatesTests.java @@ -24,6 +24,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentFieldMappers; @@ -46,12 +47,13 @@ public void testMatchTypeOnly() throws Exception { .startObject("mapping").field("index", false).endObject() .endObject().endObject().endArray().endObject().endObject(); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("person").setSource(builder.string()).get(); + client().admin().indices().preparePutMapping("test").setType("person").setSource(builder).get(); DocumentMapper docMapper = index.mapperService().documentMapper("person"); builder = JsonXContent.contentBuilder(); builder.startObject().field("s", "hello").field("l", 1).endObject(); ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", builder.bytes()); - client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("person") + .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); DocumentFieldMappers mappers = docMapper.mappers(); @@ -68,11 +70,12 @@ public void testMatchTypeOnly() throws Exception { public void testSimple() throws Exception { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-mapping.json"); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get(); DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json"); ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json)); - client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("person") + .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); Document doc = parsedDoc.rootDoc(); @@ -125,11 +128,12 @@ public void testSimple() throws Exception { public void testSimpleWithXContentTraverse() throws Exception { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-mapping.json"); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get(); DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json"); ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json)); - client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("person") + .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); Document doc = parsedDoc.rootDoc(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java b/core/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java index ec12a628f5ff9..8afe07a6e6848 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/GenericStoreDynamicTemplateTests.java @@ -21,6 +21,7 @@ import org.apache.lucene.index.IndexableField; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.FieldMapper; @@ -36,11 +37,12 @@ public class GenericStoreDynamicTemplateTests extends ESSingleNodeTestCase { public void testSimple() throws Exception { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-mapping.json"); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get(); DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/genericstore/test-data.json"); ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json)); - client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("person") + .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); Document doc = parsedDoc.rootDoc(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java index 5b3ec34e88578..1b4602ef7f22f 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.InternalSettingsPlugin; @@ -227,7 +228,7 @@ public void testMultiField() throws Exception { .endObject() .endObject().endObject().endObject().endObject().string(); CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test") - .addMapping("pin", mapping); + .addMapping("pin", mapping, XContentType.JSON); mappingRequest.execute().actionGet(); // create index and add random test points diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java index 5543baff1a23b..5c6ffb70c73e4 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java @@ -241,7 +241,7 @@ public void testPartitionedConstraints() { // partitioned index must have routing IllegalArgumentException noRoutingException = expectThrows(IllegalArgumentException.class, () -> { client().admin().indices().prepareCreate("test-index") - .addMapping("type", "{\"type\":{}}") + .addMapping("type", "{\"type\":{}}", XContentType.JSON) .setSettings(Settings.builder() .put("index.number_of_shards", 4) .put("index.routing_partition_size", 2)) @@ -252,8 +252,9 @@ public void testPartitionedConstraints() { // partitioned index cannot have parent/child relationships IllegalArgumentException parentException = expectThrows(IllegalArgumentException.class, () -> { client().admin().indices().prepareCreate("test-index") - .addMapping("parent", "{\"parent\":{\"_routing\":{\"required\":true}}}") - .addMapping("child", "{\"child\": {\"_routing\":{\"required\":true}, \"_parent\": {\"type\": \"parent\"}}}") + .addMapping("parent", "{\"parent\":{\"_routing\":{\"required\":true}}}", XContentType.JSON) + .addMapping("child", "{\"child\": {\"_routing\":{\"required\":true}, \"_parent\": {\"type\": \"parent\"}}}", + XContentType.JSON) .setSettings(Settings.builder() .put("index.number_of_shards", 4) .put("index.routing_partition_size", 2)) @@ -263,7 +264,7 @@ public void testPartitionedConstraints() { // valid partitioned index assertTrue(client().admin().indices().prepareCreate("test-index") - .addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}") + .addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON) .setSettings(Settings.builder() .put("index.number_of_shards", 4) .put("index.routing_partition_size", 2)) diff --git a/core/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java b/core/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java index 980568710177a..7728e09c7326f 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/PathMatchDynamicTemplateTests.java @@ -21,6 +21,7 @@ import org.apache.lucene.index.IndexableField; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.FieldMapper; @@ -36,11 +37,12 @@ public class PathMatchDynamicTemplateTests extends ESSingleNodeTestCase { public void testSimple() throws Exception { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-mapping.json"); IndexService index = createIndex("test"); - client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping).get(); + client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get(); DocumentMapper docMapper = index.mapperService().documentMapper("person"); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json"); ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json)); - client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString()).get(); + client().admin().indices().preparePutMapping("test").setType("person") + .setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get(); docMapper = index.mapperService().documentMapper("person"); Document doc = parsedDoc.rootDoc(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java b/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java index 67d7873b7b466..9810e737ebe61 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingOnClusterIT.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalSettingsPlugin; @@ -45,11 +46,11 @@ protected Collection> nodePlugins() { } protected void testConflict(String mapping, String mappingUpdate, Version idxVersion, String... errorMessages) throws InterruptedException { - assertAcked(prepareCreate(INDEX).setSource(mapping).setSettings("index.version.created", idxVersion.id)); + assertAcked(prepareCreate(INDEX).setSource(mapping, XContentType.JSON).setSettings("index.version.created", idxVersion.id)); ensureGreen(INDEX); GetMappingsResponse mappingsBeforeUpdateResponse = client().admin().indices().prepareGetMappings(INDEX).addTypes(TYPE).get(); try { - client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(mappingUpdate).get(); + client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(mappingUpdate, XContentType.JSON).get(); fail(); } catch (IllegalArgumentException e) { for (String errorMessage : errorMessages) { diff --git a/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java b/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java index ac698cc838604..3928f78c3c536 100644 --- a/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java +++ b/core/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java @@ -32,6 +32,7 @@ import org.elasticsearch.index.engine.EngineConfig; import org.elasticsearch.index.engine.EngineFactory; import org.elasticsearch.index.engine.InternalEngineTests; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.store.Store; import org.elasticsearch.index.translog.Translog; @@ -164,7 +165,8 @@ public void testRecoveryAfterPrimaryPromotion() throws Exception { final int rollbackDocs = randomIntBetween(1, 5); logger.info("--> indexing {} rollback docs", rollbackDocs); for (int i = 0; i < rollbackDocs; i++) { - final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "rollback_" + i).source("{}"); + final IndexRequest indexRequest = new IndexRequest(index.getName(), "type", "rollback_" + i) + .source("{}", XContentType.JSON); indexOnPrimary(indexRequest, oldPrimary); indexOnReplica(indexRequest, replica); } @@ -266,7 +268,7 @@ public Engine newReadOnlyEngine(EngineConfig config) { final String id = "pending_" + i; threadPool.generic().submit(() -> { try { - shards.index(new IndexRequest(index.getName(), "type", id).source("{}")); + shards.index(new IndexRequest(index.getName(), "type", id).source("{}", XContentType.JSON)); } catch (Exception e) { throw new AssertionError(e); } finally { diff --git a/core/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateIT.java b/core/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateIT.java index 406541c0f49d1..f1ed7c7682152 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateIT.java @@ -22,6 +22,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.test.ESIntegTestCase; @@ -53,7 +54,7 @@ public void testConcurrentDynamicMapping() throws Exception { for (int i = 0; i < iters; i++) { cluster().wipeIndices("test"); assertAcked(prepareCreate("test") - .addMapping(mappingType, mapping)); + .addMapping(mappingType, mapping, XContentType.JSON)); int numDocs = scaledRandomIntBetween(10, 100); final CountDownLatch latch = new CountDownLatch(numDocs); final List throwable = new CopyOnWriteArrayList<>(); diff --git a/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java index 39262fd19b7b2..5b62c99d242f6 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperService; @@ -102,12 +103,12 @@ public void testUpdateMappingWithoutType() throws Exception { Settings.builder() .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) - ).addMapping("doc", "{\"doc\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}") + ).addMapping("doc", "{\"doc\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON) .execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("doc") - .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}") + .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON) .execute().actionGet(); assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); @@ -127,7 +128,7 @@ public void testUpdateMappingWithoutTypeMultiObjects() throws Exception { client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("doc") - .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}") + .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON) .execute().actionGet(); assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); @@ -143,13 +144,13 @@ public void testUpdateMappingWithConflicts() throws Exception { Settings.builder() .put("index.number_of_shards", 2) .put("index.number_of_replicas", 0) - ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}") + ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON) .execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); try { client().admin().indices().preparePutMapping("test").setType("type") - .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"integer\"}}}}").execute().actionGet(); + .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"integer\"}}}}", XContentType.JSON).execute().actionGet(); fail("Expected MergeMappingException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("mapper [body] of different type, current_type [text], merged_type [integer]")); @@ -158,11 +159,11 @@ public void testUpdateMappingWithConflicts() throws Exception { public void testUpdateMappingWithNormsConflicts() throws Exception { client().admin().indices().prepareCreate("test") - .addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": false }}}}") + .addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": false }}}}", XContentType.JSON) .execute().actionGet(); try { client().admin().indices().preparePutMapping("test").setType("type") - .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": true }}}}").execute() + .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": true }}}}", XContentType.JSON).execute() .actionGet(); fail("Expected MergeMappingException"); } catch (IllegalArgumentException e) { @@ -179,12 +180,12 @@ public void testUpdateMappingNoChanges() throws Exception { Settings.builder() .put("index.number_of_shards", 2) .put("index.number_of_replicas", 0) - ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}") + ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON) .execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("type") - .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}") + .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON) .execute().actionGet(); //no changes, we return @@ -321,7 +322,8 @@ public void testPutMappingsWithBlocks() throws Exception { for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE)) { try { enableIndexBlock("test", block); - assertAcked(client().admin().indices().preparePutMapping("test").setType("doc").setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}")); + assertAcked(client().admin().indices().preparePutMapping("test").setType("doc") + .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON)); } finally { disableIndexBlock("test", block); } @@ -330,7 +332,8 @@ public void testPutMappingsWithBlocks() throws Exception { for (String block : Arrays.asList(SETTING_READ_ONLY, SETTING_BLOCKS_METADATA)) { try { enableIndexBlock("test", block); - assertBlocked(client().admin().indices().preparePutMapping("test").setType("doc").setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}")); + assertBlocked(client().admin().indices().preparePutMapping("test").setType("doc") + .setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON)); } finally { disableIndexBlock("test", block); } diff --git a/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java b/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java index 7b87a62288f30..2f336d8d69cd1 100644 --- a/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java +++ b/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.MockEngineFactoryPlugin; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.indices.IndicesService; @@ -126,7 +127,7 @@ public void testBreakerWithRandomExceptions() throws IOException, InterruptedExc logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); CreateIndexResponse response = client().admin().indices().prepareCreate("test") .setSettings(settings) - .addMapping("type", mapping).execute().actionGet(); + .addMapping("type", mapping, XContentType.JSON).execute().actionGet(); final int numDocs; if (response.isShardsAcked() == false) { /* some seeds just won't let you create the index at all and we enter a ping-pong mode diff --git a/core/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java b/core/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java index 6f9668c368e99..b9eb0abbb7550 100644 --- a/core/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java +++ b/core/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java @@ -31,6 +31,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.test.ESIntegTestCase; @@ -315,7 +316,7 @@ public void testOpenCloseWithDocs() throws IOException, ExecutionException, Inte .endObject().string(); assertAcked(client().admin().indices().prepareCreate("test") - .addMapping("type", mapping)); + .addMapping("type", mapping, XContentType.JSON)); ensureGreen(); int docs = between(10, 100); IndexRequestBuilder[] builder = new IndexRequestBuilder[docs]; diff --git a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java index 91673630c3d49..312ad78e6ca4e 100644 --- a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java @@ -784,7 +784,7 @@ public void testCompletionFieldsParam() throws Exception { assertAcked(prepareCreate("test1") .addMapping( "bar", - "{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}")); + "{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}", XContentType.JSON)); ensureGreen(); client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get(); diff --git a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java index eb6a83b9a914b..10ccc4f002588 100644 --- a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java +++ b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java @@ -807,7 +807,7 @@ public void testPartitionedTemplate() throws Exception { IllegalArgumentException eBadMapping = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().preparePutTemplate("template_2") .setPatterns(Collections.singletonList("te*")) - .addMapping("type", "{\"type\":{\"_routing\":{\"required\":false}}}") + .addMapping("type", "{\"type\":{\"_routing\":{\"required\":false}}}", XContentType.JSON) .setSettings(Settings.builder() .put("index.number_of_shards", "6") .put("index.routing_partition_size", "3")) diff --git a/core/src/test/java/org/elasticsearch/rest/RestControllerTests.java b/core/src/test/java/org/elasticsearch/rest/RestControllerTests.java index 9865ccf2c136c..cc035ecc10340 100644 --- a/core/src/test/java/org/elasticsearch/rest/RestControllerTests.java +++ b/core/src/test/java/org/elasticsearch/rest/RestControllerTests.java @@ -277,40 +277,33 @@ public void testDispatchDoesNotRequireContentTypeForRequestsWithoutContent() { assertTrue(channel.getSendResponseCalled()); } - public void testDispatchWorksWithPlainText() { + public void testDispatchFailsWithPlainText() { String content = randomAsciiOfLengthBetween(1, BREAKER_LIMIT.bytesAsInt()); FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) .withContent(new BytesArray(content), null).withPath("/foo") .withHeaders(Collections.singletonMap("Content-Type", Collections.singletonList("text/plain"))).build(); - AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK); + AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE); restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() { @Override public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); } - - @Override - public boolean supportsPlainText() { - return true; - } }); assertFalse(channel.getSendResponseCalled()); restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY)); assertTrue(channel.getSendResponseCalled()); - assertWarnings("Plain text request bodies are deprecated. Use request parameters or body in a supported format."); } - public void testDispatchWorksWithAutoDetection() { + public void testDispatchUnsupportedContentType() { FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) .withContent(new BytesArray("{}"), null).withPath("/") .withHeaders(Collections.singletonMap("Content-Type", Collections.singletonList("application/x-www-form-urlencoded"))).build(); - AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK); + AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE); assertFalse(channel.getSendResponseCalled()); restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY)); assertTrue(channel.getSendResponseCalled()); - assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header."); } public void testDispatchWorksWithNewlineDelimitedJson() { @@ -361,10 +354,10 @@ public boolean supportsContentStream() { assertTrue(channel.getSendResponseCalled()); } - public void testDispatchWithContentStreamAutoDetect() { + public void testDispatchWithContentStreamNoContentType() { FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) .withContent(new BytesArray("{}"), null).withPath("/foo").build(); - AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.OK); + AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE); restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() { @Override public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { @@ -380,48 +373,11 @@ public boolean supportsContentStream() { assertFalse(channel.getSendResponseCalled()); restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY)); assertTrue(channel.getSendResponseCalled()); - assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header."); } public void testNonStreamingXContentCausesErrorResponse() throws IOException { - // auto detect FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) - .withContent(YamlXContent.contentBuilder().startObject().endObject().bytes(), null).withPath("/foo").build(); - AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE); - restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() { - @Override - public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { - channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); - } - - @Override - public boolean supportsContentStream() { - return true; - } - }); - - assertFalse(channel.getSendResponseCalled()); - restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY)); - assertTrue(channel.getSendResponseCalled()); - - assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header."); - - // specified - fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) .withContent(YamlXContent.contentBuilder().startObject().endObject().bytes(), XContentType.YAML).withPath("/foo").build(); - channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE); - assertFalse(channel.getSendResponseCalled()); - restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY)); - assertTrue(channel.getSendResponseCalled()); - } - - public void testStrictModeContentStream() { - restController = new RestController( - Settings.builder().put(HttpTransportSettings.SETTING_HTTP_CONTENT_TYPE_REQUIRED.getKey(), true).build(), - Collections.emptySet(), null, null, circuitBreakerService); - FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) - .withContent(new BytesArray("{}"), null).withPath("/foo") - .build(); AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.NOT_ACCEPTABLE); restController.registerHandler(RestRequest.Method.GET, "/foo", new RestHandler() { @Override @@ -459,7 +415,6 @@ public boolean supportsContentStream() { assertFalse(channel.getSendResponseCalled()); restController.dispatchRequest(fakeRestRequest, channel, new ThreadContext(Settings.EMPTY)); assertTrue(channel.getSendResponseCalled()); - assertWarnings("Content type detection for rest requests is deprecated. Specify the content type using the [Content-Type] header."); } public void testDispatchBadRequest() { @@ -519,7 +474,7 @@ public HttpStats stats() { } private static final class AssertingChannel extends AbstractRestChannel { - + private final RestStatus expectedStatus; private final AtomicReference responseReference = new AtomicReference<>(); @@ -533,15 +488,15 @@ public void sendResponse(RestResponse response) { assertEquals(expectedStatus, response.status()); responseReference.set(response); } - + RestResponse getRestResponse() { return responseReference.get(); } - + boolean getSendResponseCalled() { return getRestResponse() != null; } - + } private static final class ExceptionThrowingChannel extends AbstractRestChannel { diff --git a/core/src/test/java/org/elasticsearch/rest/RestRequestTests.java b/core/src/test/java/org/elasticsearch/rest/RestRequestTests.java index bddcd39160a89..fa5b25e4549c6 100644 --- a/core/src/test/java/org/elasticsearch/rest/RestRequestTests.java +++ b/core/src/test/java/org/elasticsearch/rest/RestRequestTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.ESTestCase; @@ -61,10 +62,12 @@ public void testContentOrSourceParam() throws IOException { assertEquals(BytesArray.EMPTY, new ContentRestRequest("", emptyMap()).contentOrSourceParam().v2()); assertEquals(new BytesArray("stuff"), new ContentRestRequest("stuff", emptyMap()).contentOrSourceParam().v2()); assertEquals(new BytesArray("stuff"), - new ContentRestRequest("stuff", singletonMap("source", "stuff2")).contentOrSourceParam().v2()); + new ContentRestRequest("stuff", MapBuilder.newMapBuilder() + .put("source", "stuff2").put("source_content_type", "application/json").immutableMap()).contentOrSourceParam().v2()); assertEquals(new BytesArray("{\"foo\": \"stuff\"}"), - new ContentRestRequest("", singletonMap("source", "{\"foo\": \"stuff\"}")).contentOrSourceParam().v2()); - assertWarnings("Deprecated use of the [source] parameter without the [source_content_type] parameter."); + new ContentRestRequest("", MapBuilder.newMapBuilder() + .put("source", "{\"foo\": \"stuff\"}").put("source_content_type", "application/json").immutableMap()) + .contentOrSourceParam().v2()); } public void testHasContentOrSourceParam() throws IOException { @@ -80,8 +83,8 @@ public void testContentOrSourceParamParser() throws IOException { assertEquals("Body required", e.getMessage()); assertEquals(emptyMap(), new ContentRestRequest("{}", emptyMap()).contentOrSourceParamParser().map()); assertEquals(emptyMap(), new ContentRestRequest("{}", singletonMap("source", "stuff2")).contentOrSourceParamParser().map()); - assertEquals(emptyMap(), new ContentRestRequest("", singletonMap("source", "{}")).contentOrSourceParamParser().map()); - assertWarnings("Deprecated use of the [source] parameter without the [source_content_type] parameter."); + assertEquals(emptyMap(), new ContentRestRequest("", MapBuilder.newMapBuilder() + .put("source", "{}").put("source_content_type", "application/json").immutableMap()).contentOrSourceParamParser().map()); } public void testWithContentOrSourceParamParserOrNull() throws IOException { @@ -89,9 +92,10 @@ public void testWithContentOrSourceParamParserOrNull() throws IOException { new ContentRestRequest("{}", emptyMap()).withContentOrSourceParamParserOrNull(parser -> assertEquals(emptyMap(), parser.map())); new ContentRestRequest("{}", singletonMap("source", "stuff2")).withContentOrSourceParamParserOrNull(parser -> assertEquals(emptyMap(), parser.map())); - new ContentRestRequest("", singletonMap("source", "{}")).withContentOrSourceParamParserOrNull(parser -> + new ContentRestRequest("", MapBuilder.newMapBuilder().put("source_content_type", "application/json") + .put("source", "{}").immutableMap()) + .withContentOrSourceParamParserOrNull(parser -> assertEquals(emptyMap(), parser.map())); - assertWarnings("Deprecated use of the [source] parameter without the [source_content_type] parameter."); } public void testContentTypeParsing() { diff --git a/core/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java b/core/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java index 9ceedb2378b61..48b8430077fae 100644 --- a/core/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java +++ b/core/src/test/java/org/elasticsearch/routing/PartitionedRoutingIT.java @@ -22,6 +22,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.test.ESIntegTestCase; import org.mockito.internal.util.collections.Sets; @@ -42,7 +43,7 @@ public void testVariousPartitionSizes() throws Exception { .setSettings(Settings.builder() .put("index.number_of_shards", shards) .put("index.routing_partition_size", partitionSize)) - .addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}") + .addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON) .execute().actionGet(); ensureGreen(); @@ -67,7 +68,7 @@ public void testShrinking() throws Exception { .setSettings(Settings.builder() .put("index.number_of_shards", currentShards) .put("index.routing_partition_size", partitionSize)) - .addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}") + .addMapping("type", "{\"type\":{\"_routing\":{\"required\":true}}}", XContentType.JSON) .execute().actionGet(); ensureGreen(); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java index 78a7fb5c176b4..3d0b55fdb981c 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.joda.DateMathParser; import org.elasticsearch.common.joda.Joda; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.query.MatchNoneQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; @@ -1051,7 +1052,7 @@ public void testSingleValueFieldWithExtendedBoundsTimezone() throws Exception { public void testSingleValueWithMultipleDateFormatsFromMapping() throws Exception { String mappingJson = jsonBuilder().startObject().startObject("type").startObject("properties").startObject("date").field("type", "date").field("format", "dateOptionalTime||dd-MM-yyyy").endObject().endObject().endObject().endObject().string(); - prepareCreate("idx2").addMapping("type", mappingJson).execute().actionGet(); + prepareCreate("idx2").addMapping("type", mappingJson, XContentType.JSON).execute().actionGet(); IndexRequestBuilder[] reqs = new IndexRequestBuilder[5]; for (int i = 0; i < reqs.length; i++) { reqs[i] = client().prepareIndex("idx2", "type", "" + i).setSource(jsonBuilder().startObject().field("date", "10-03-2014").endObject()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java index 6bbe1dc22b2d7..f2a030ab5e8ad 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/TermsDocCountErrorIT.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; @@ -85,7 +86,8 @@ public void setupSuiteScopeCluster() throws Exception { .endObject())); } numRoutingValues = between(1,40); - assertAcked(prepareCreate("idx_with_routing").addMapping("type", "{ \"type\" : { \"_routing\" : { \"required\" : true } } }")); + assertAcked(prepareCreate("idx_with_routing") + .addMapping("type", "{ \"type\" : { \"_routing\" : { \"required\" : true } } }", XContentType.JSON)); for (int i = 0; i < numDocs; i++) { builders.add(client().prepareIndex("idx_single_shard", "type", "" + i) .setRouting(String.valueOf(randomInt(numRoutingValues))) diff --git a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java index e406cb72aeab8..067064dfc156f 100644 --- a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java +++ b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.MockEngineFactoryPlugin; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; @@ -109,7 +110,7 @@ public void testRandomExceptions() throws IOException, InterruptedException, Exe logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); assertAcked(prepareCreate("test") .setSettings(settings) - .addMapping("type", mapping)); + .addMapping("type", mapping, XContentType.JSON)); ensureSearchable(); final int numDocs = between(10, 100); int numCreated = 0; diff --git a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java index 61dd798f5e111..dbba84f86ff08 100644 --- a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java +++ b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.sort.SortOrder; @@ -92,7 +93,7 @@ public void testRandomDirectoryIOExceptions() throws IOException, InterruptedExc logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); client().admin().indices().prepareCreate("test") .setSettings(settings) - .addMapping("type", mapping).execute().actionGet(); + .addMapping("type", mapping, XContentType.JSON).execute().actionGet(); numInitialDocs = between(10, 100); ensureGreen(); for (int i = 0; i < numInitialDocs; i++) { @@ -114,7 +115,7 @@ public void testRandomDirectoryIOExceptions() throws IOException, InterruptedExc logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); client().admin().indices().prepareCreate("test") .setSettings(settings) - .addMapping("type", mapping).execute().actionGet(); + .addMapping("type", mapping, XContentType.JSON).execute().actionGet(); } ClusterHealthResponse clusterHealthResponse = client().admin().cluster() .health(Requests.clusterHealthRequest().waitForYellowStatus().timeout(TimeValue.timeValueSeconds(5))).get(); // it's OK to timeout here diff --git a/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java b/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java index 27b0399944d16..815998ad0936b 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.IdsQueryBuilder; import org.elasticsearch.index.query.MatchQueryBuilder; @@ -2902,7 +2903,7 @@ public void testACopyFieldWithNestedQuery() throws Exception { .field("store", true) .endObject() .endObject().endObject().endObject().string(); - prepareCreate("test").addMapping("type", mapping).get(); + prepareCreate("test").addMapping("type", mapping, XContentType.JSON).get(); client().prepareIndex("test", "type", "1").setSource(jsonBuilder().startObject().startArray("foo") .startObject().field("text", "brown").endObject() diff --git a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java index 62ef56f2dd700..428ac63eaefa7 100644 --- a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java +++ b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java @@ -165,7 +165,7 @@ public void testStoredFields() throws Exception { .startObject("field3").field("type", "text").field("store", true).endObject() .endObject().endObject().endObject().string(); - client().admin().indices().preparePutMapping().setType("type1").setSource(mapping).execute().actionGet(); + client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).execute().actionGet(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() .field("field1", "value1") @@ -255,7 +255,7 @@ public void testScriptDocAndFields() throws Exception { .startObject("num1").field("type", "double").field("store", true).endObject() .endObject().endObject().endObject().string(); - client().admin().indices().preparePutMapping().setType("type1").setSource(mapping).execute().actionGet(); + client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).execute().actionGet(); client().prepareIndex("test", "type1", "1") .setSource(jsonBuilder().startObject() @@ -560,7 +560,7 @@ public void testStoredFieldsWithoutSource() throws Exception { .endObject() .string(); - client().admin().indices().preparePutMapping().setType("type1").setSource(mapping).execute().actionGet(); + client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).execute().actionGet(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() .field("byte_field", (byte) 1) @@ -776,7 +776,7 @@ public void testFieldsPulledFromFieldData() throws Exception { .endObject() .string(); - client().admin().indices().preparePutMapping().setType("type1").setSource(mapping).execute().actionGet(); + client().admin().indices().preparePutMapping().setType("type1").setSource(mapping, XContentType.JSON).execute().actionGet(); ReadableDateTime date = new DateTime(2012, 3, 22, 0, 0, DateTimeZone.UTC); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java index d119d9bacf122..5f722a86a2364 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/DecayFunctionScoreIT.java @@ -613,7 +613,7 @@ public void testManyDocsLin() throws Exception { .field("doc_values", true).endObject().startObject("geo").field("type", "geo_point") .field("ignore_malformed", true); xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").setSettings(settings).addMapping("type", xContentBuilder.string())); + assertAcked(prepareCreate("test").setSettings(settings).addMapping("type", xContentBuilder)); int numDocs = 200; List indexBuilders = new ArrayList<>(); diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java index 568c723f8d16e..5e09b36f6b5ef 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java @@ -215,7 +215,8 @@ public void testShapeRelations() throws Exception { .endObject() .endObject().string(); - CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("shapes").addMapping("polygon", mapping); + CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("shapes") + .addMapping("polygon", mapping, XContentType.JSON); mappingRequest.execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); @@ -384,7 +385,7 @@ public void testBulk() throws Exception { .endObject(); client().admin().indices().prepareCreate("countries").setSettings(settings) - .addMapping("country", xContentBuilder.string()).execute().actionGet(); + .addMapping("country", xContentBuilder).execute().actionGet(); BulkResponse bulk = client().prepareBulk().add(bulkAction, 0, bulkAction.length, null, null, xContentBuilder.contentType()).get(); for (BulkItemResponse item : bulk.getItems()) { diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java index aaff5b5abdce9..13889cec7e15b 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoShapeIntegrationIT.java @@ -22,6 +22,7 @@ import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.GeoShapeFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; @@ -47,7 +48,7 @@ public void testOrientationPersistence() throws Exception { .endObject().endObject().string(); // create index - assertAcked(prepareCreate(idxName).addMapping("shape", mapping)); + assertAcked(prepareCreate(idxName).addMapping("shape", mapping, XContentType.JSON)); mapping = XContentFactory.jsonBuilder().startObject().startObject("shape") .startObject("properties").startObject("location") @@ -56,7 +57,7 @@ public void testOrientationPersistence() throws Exception { .endObject().endObject() .endObject().endObject().string(); - assertAcked(prepareCreate(idxName+"2").addMapping("shape", mapping)); + assertAcked(prepareCreate(idxName+"2").addMapping("shape", mapping, XContentType.JSON)); ensureGreen(idxName, idxName+"2"); internalCluster().fullRestart(); diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java b/core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java index f0efe523bc6f8..e5b1d4a99d91c 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoShapeQueryTests.java @@ -67,7 +67,7 @@ public void testNullShape() throws Exception { .field("type", "geo_shape") .endObject().endObject() .endObject().endObject().string(); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping).execute().actionGet(); + client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).execute().actionGet(); ensureGreen(); client().prepareIndex("test", "type1", "aNullshape").setSource("{\"location\": null}", XContentType.JSON) @@ -83,7 +83,7 @@ public void testIndexPointsFilterRectangle() throws Exception { .field("tree", "quadtree") .endObject().endObject() .endObject().endObject().string(); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping).execute().actionGet(); + client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).execute().actionGet(); ensureGreen(); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() @@ -130,7 +130,7 @@ public void testEdgeCases() throws Exception { .field("tree", "quadtree") .endObject().endObject() .endObject().endObject().string(); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping).execute().actionGet(); + client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).execute().actionGet(); ensureGreen(); client().prepareIndex("test", "type1", "blakely").setSource(jsonBuilder().startObject() @@ -167,7 +167,7 @@ public void testIndexedShapeReference() throws Exception { .field("tree", "quadtree") .endObject().endObject() .endObject().endObject().string(); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping).execute().actionGet(); + client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).execute().actionGet(); createIndex("shapes"); ensureGreen(); @@ -449,7 +449,7 @@ public void testPointsOnly() throws Exception { .endObject().endObject() .endObject().endObject().string(); - client().admin().indices().prepareCreate("geo_points_only").addMapping("type1", mapping).execute().actionGet(); + client().admin().indices().prepareCreate("geo_points_only").addMapping("type1", mapping, XContentType.JSON).execute().actionGet(); ensureGreen(); ShapeBuilder shape = RandomShapeGenerator.createShape(random()); diff --git a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java index 9ee41e9e37d09..81a3fc0d6b57b 100644 --- a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.MoreLikeThisQueryBuilder; import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item; import org.elasticsearch.index.query.QueryBuilders; @@ -152,7 +153,7 @@ public void testMoreLikeThisWithAliasesInLikeDocuments() throws Exception { .startObject("properties") .endObject() .endObject().endObject().string(); - client().admin().indices().prepareCreate(indexName).addMapping(typeName, mapping).get(); + client().admin().indices().prepareCreate(indexName).addMapping(typeName, mapping, XContentType.JSON).get(); client().admin().indices().prepareAliases().addAlias(indexName, aliasName).get(); assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); @@ -174,7 +175,7 @@ public void testMoreLikeThisIssue2197() throws Exception { .startObject("properties") .endObject() .endObject().endObject().string(); - client().admin().indices().prepareCreate("foo").addMapping("bar", mapping).execute().actionGet(); + client().admin().indices().prepareCreate("foo").addMapping("bar", mapping, XContentType.JSON).execute().actionGet(); client().prepareIndex("foo", "bar", "1") .setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject().endObject()) .execute().actionGet(); @@ -197,7 +198,7 @@ public void testMoreLikeWithCustomRouting() throws Exception { .startObject("properties") .endObject() .endObject().endObject().string(); - client().admin().indices().prepareCreate("foo").addMapping("bar", mapping).execute().actionGet(); + client().admin().indices().prepareCreate("foo").addMapping("bar", mapping, XContentType.JSON).execute().actionGet(); ensureGreen(); client().prepareIndex("foo", "bar", "1") @@ -220,7 +221,7 @@ public void testMoreLikeThisIssueRoutingNotSerialized() throws Exception { .endObject().endObject().string(); assertAcked(prepareCreate("foo", 2, Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put(SETTING_NUMBER_OF_REPLICAS, 0)) - .addMapping("bar", mapping)); + .addMapping("bar", mapping, XContentType.JSON)); ensureGreen(); client().prepareIndex("foo", "bar", "1") diff --git a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java index c1b930bcc3f19..f22ec392b9953 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SimpleQueryStringIT.java @@ -313,7 +313,8 @@ public void testSimpleQueryStringAnalyzeWildcard() throws ExecutionException, In .endObject() .endObject().string(); - CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test1").addMapping("type1", mapping); + CreateIndexRequestBuilder mappingRequest = client().admin().indices().prepareCreate("test1") + .addMapping("type1", mapping, XContentType.JSON); mappingRequest.execute().actionGet(); indexRandom(true, client().prepareIndex("test1", "type1", "1").setSource("location", "Köln")); refresh(); @@ -364,7 +365,7 @@ public void testEmptySimpleQueryStringWithAnalysis() throws Exception { CreateIndexRequestBuilder mappingRequest = client().admin().indices() .prepareCreate("test1") - .addMapping("type1", mapping); + .addMapping("type1", mapping, XContentType.JSON); mappingRequest.execute().actionGet(); indexRandom(true, client().prepareIndex("test1", "type1", "1").setSource("body", "Some Text")); refresh(); @@ -377,7 +378,7 @@ public void testEmptySimpleQueryStringWithAnalysis() throws Exception { public void testBasicAllQuery() throws Exception { String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json"); - prepareCreate("test").setSource(indexBody).get(); + prepareCreate("test").setSource(indexBody, XContentType.JSON).get(); ensureGreen("test"); List reqs = new ArrayList<>(); @@ -405,7 +406,7 @@ public void testBasicAllQuery() throws Exception { public void testWithDate() throws Exception { String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json"); - prepareCreate("test").setSource(indexBody).get(); + prepareCreate("test").setSource(indexBody, XContentType.JSON).get(); ensureGreen("test"); List reqs = new ArrayList<>(); @@ -432,7 +433,7 @@ public void testWithDate() throws Exception { public void testWithLotsOfTypes() throws Exception { String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json"); - prepareCreate("test").setSource(indexBody).get(); + prepareCreate("test").setSource(indexBody, XContentType.JSON).get(); ensureGreen("test"); List reqs = new ArrayList<>(); @@ -465,7 +466,7 @@ public void testWithLotsOfTypes() throws Exception { public void testDocWithAllTypes() throws Exception { String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json"); - prepareCreate("test").setSource(indexBody).get(); + prepareCreate("test").setSource(indexBody, XContentType.JSON).get(); ensureGreen("test"); List reqs = new ArrayList<>(); @@ -515,7 +516,7 @@ public void testDocWithAllTypes() throws Exception { public void testKeywordWithWhitespace() throws Exception { String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json"); - prepareCreate("test").setSource(indexBody).get(); + prepareCreate("test").setSource(indexBody, XContentType.JSON).get(); ensureGreen("test"); List reqs = new ArrayList<>(); @@ -536,7 +537,7 @@ public void testKeywordWithWhitespace() throws Exception { public void testExplicitAllFieldsRequested() throws Exception { String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index-with-all.json"); prepareCreate("test") - .setSource(indexBody) + .setSource(indexBody, XContentType.JSON) // .setSettings(Settings.builder().put("index.version.created", Version.V_5_0_0.id)).get(); .get(); ensureGreen("test"); @@ -564,7 +565,7 @@ public void testExplicitAllFieldsRequested() throws Exception { @LuceneTestCase.AwaitsFix(bugUrl="currently can't perform phrase queries on fields that don't support positions") public void testPhraseQueryOnFieldWithNoPositions() throws Exception { String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json"); - prepareCreate("test").setSource(indexBody).get(); + prepareCreate("test").setSource(indexBody, XContentType.JSON).get(); ensureGreen("test"); List reqs = new ArrayList<>(); @@ -579,7 +580,7 @@ public void testPhraseQueryOnFieldWithNoPositions() throws Exception { public void testAllFieldsWithSpecifiedLeniency() throws IOException { String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index.json"); - prepareCreate("test").setSource(indexBody).get(); + prepareCreate("test").setSource(indexBody, XContentType.JSON).get(); ensureGreen("test"); Exception e = expectThrows(Exception.class, () -> diff --git a/core/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java b/core/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java index 4a27dcb596470..aad6aa0982c9c 100644 --- a/core/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java +++ b/core/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchContextException; import org.elasticsearch.search.SearchHit; @@ -71,7 +72,7 @@ private int setupIndex(boolean withDocs) throws IOException, ExecutionException, assertAcked(client().admin().indices().prepareCreate("test") .setSettings("number_of_shards", numberOfShards, "index.max_slices_per_scroll", 10000) - .addMapping("type", mapping)); + .addMapping("type", mapping, XContentType.JSON)); ensureGreen(); if (withDocs == false) { diff --git a/core/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java b/core/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java index 50a436c7b2724..c9b4fd80a2936 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java +++ b/core/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; @@ -243,7 +244,7 @@ public void testSortMinValueScript() throws IOException { .endObject() .endObject().string(); - assertAcked(prepareCreate("test").addMapping("type1", mapping)); + assertAcked(prepareCreate("test").addMapping("type1", mapping, XContentType.JSON)); ensureGreen(); for (int i = 0; i < 10; i++) { @@ -355,7 +356,7 @@ public void testDocumentsWithNullValue() throws Exception { .endObject() .endObject() .endObject().string(); - assertAcked(prepareCreate("test").addMapping("type1", mapping)); + assertAcked(prepareCreate("test").addMapping("type1", mapping, XContentType.JSON)); ensureGreen(); client().prepareIndex("test", "type1") diff --git a/core/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java b/core/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java index 00b8fc8e932fe..07502ff338379 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.aggregations.AggregationBuilders; @@ -1064,7 +1065,7 @@ public void testIndexingUnrelatedNullValue() throws Exception { .endObject() .string(); - assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping).get()); + assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping, XContentType.JSON).get()); ensureGreen(); client().prepareIndex(INDEX, TYPE, "1").setSource(FIELD, "strings make me happy", FIELD + "_1", "nulls make me sad") diff --git a/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/WaitForRefreshAndCloseTests.java b/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/WaitForRefreshAndCloseTests.java index ca69a95deeda9..0b1ad2a6dd9ab 100644 --- a/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/WaitForRefreshAndCloseTests.java +++ b/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/WaitForRefreshAndCloseTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.test.rest; import org.apache.http.HttpEntity; +import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import org.elasticsearch.action.ActionFuture; @@ -50,7 +51,8 @@ public void setupIndex() throws IOException { // If we get an error, it should be because the index doesn't exist assertEquals(404, e.getResponse().getStatusLine().getStatusCode()); } - client().performRequest("PUT", indexName(), emptyMap(), new StringEntity("{\"settings\":{\"refresh_interval\":-1}}")); + client().performRequest("PUT", indexName(), emptyMap(), + new StringEntity("{\"settings\":{\"refresh_interval\":-1}}", ContentType.APPLICATION_JSON)); } @After @@ -67,16 +69,17 @@ private String docPath() { } public void testIndexAndThenClose() throws Exception { - closeWhileListenerEngaged(start("PUT", "", new StringEntity("{\"test\":\"test\"}"))); + closeWhileListenerEngaged(start("PUT", "", new StringEntity("{\"test\":\"test\"}", ContentType.APPLICATION_JSON))); } public void testUpdateAndThenClose() throws Exception { - client().performRequest("PUT", docPath(), emptyMap(), new StringEntity("{\"test\":\"test\"}")); - closeWhileListenerEngaged(start("POST", "/_update", new StringEntity("{\"doc\":{\"name\":\"test\"}}"))); + client().performRequest("PUT", docPath(), emptyMap(), new StringEntity("{\"test\":\"test\"}", ContentType.APPLICATION_JSON)); + closeWhileListenerEngaged(start("POST", "/_update", + new StringEntity("{\"doc\":{\"name\":\"test\"}}", ContentType.APPLICATION_JSON))); } public void testDeleteAndThenClose() throws Exception { - client().performRequest("PUT", docPath(), emptyMap(), new StringEntity("{\"test\":\"test\"}")); + client().performRequest("PUT", docPath(), emptyMap(), new StringEntity("{\"test\":\"test\"}", ContentType.APPLICATION_JSON)); closeWhileListenerEngaged(start("DELETE", "", null)); } diff --git a/docs/reference/api-conventions.asciidoc b/docs/reference/api-conventions.asciidoc index 7e8ed1c1c816f..21bd539a4eaaf 100644 --- a/docs/reference/api-conventions.asciidoc +++ b/docs/reference/api-conventions.asciidoc @@ -675,22 +675,17 @@ should also be passed with a media type value that indicates the format of the source, such as `application/json`. [float] -=== Content-Type auto-detection +=== Content-Type Requirements -deprecated[5.3.0, Provide the proper Content-Type header] +The type of the content sent in a request body must be specified using +the `Content-Type` header. The value of this header must map to one of +the supported formats that the API supports. Most APIs support JSON, +YAML, CBOR, and SMILE. The bulk and multi-search APIs support NDJSON, +JSON and SMILE; other types will result in an error response. -The content sent in a request body or using the `source` query string -parameter is inspected to automatically determine the content type -(JSON, YAML, SMILE, or CBOR). - -A strict mode can be enabled which disables auto-detection and requires -that all requests with a body have a Content-Type header that maps to -a supported format. To enabled this strict mode, add the following -setting to the `elasticsearch.yml` file: - - http.content_type.required: true - -The default value is `false`. +Additionally, when using the `source` query string parameter the +content type must be specified using the `source_content_type` query +string parameter. [[url-access-control]] == URL-based access control diff --git a/docs/reference/migration/migrate_6_0.asciidoc b/docs/reference/migration/migrate_6_0.asciidoc index 2bfe5d88f2ddd..c9179d10130ee 100644 --- a/docs/reference/migration/migrate_6_0.asciidoc +++ b/docs/reference/migration/migrate_6_0.asciidoc @@ -37,6 +37,7 @@ way to reindex old indices is to use the `reindex` API. * <> * <> * <> +* <> include::migrate_6_0/cat.asciidoc[] @@ -63,3 +64,5 @@ include::migrate_6_0/scripting.asciidoc[] include::migrate_6_0/ingest.asciidoc[] include::migrate_6_0/percolator.asciidoc[] + +include::migrate_6_0/java.asciidoc[] diff --git a/docs/reference/migration/migrate_6_0/java.asciidoc b/docs/reference/migration/migrate_6_0/java.asciidoc new file mode 100644 index 0000000000000..e5f251c1c4357 --- /dev/null +++ b/docs/reference/migration/migrate_6_0/java.asciidoc @@ -0,0 +1,9 @@ +[[breaking_60_java_changes]] +=== Java API changes + +==== `setSource` methods require XContentType + +Previously the `setSource` methods and other methods that accepted byte/string representations of +an object source did not require the XContentType to be specified. The auto-detection of the content +type is no longer used, so these methods now require the XContentType as an additional argument when +providing the source in bytes or as a string. diff --git a/docs/reference/migration/migrate_6_0/rest.asciidoc b/docs/reference/migration/migrate_6_0/rest.asciidoc index cad56618fe010..934d2c2e6477f 100644 --- a/docs/reference/migration/migrate_6_0/rest.asciidoc +++ b/docs/reference/migration/migrate_6_0/rest.asciidoc @@ -19,6 +19,9 @@ In previous versions of Elasticsearch, having a proper Content-Type for the data Elasticsearch 6.0.0 enforces that all requests with a body must have a supported Content-Type and this type will be used when parsing the data. +When using the `source` query string parameter, the `source_content_type` parameter must also be specified with +the media type of the source. + ==== Boolean API parameters All REST APIs parameters (both request parameters and JSON body) support providing boolean "false" as the diff --git a/docs/reference/modules/http.asciidoc b/docs/reference/modules/http.asciidoc index 3682234f5e6fb..065c91349c25a 100644 --- a/docs/reference/modules/http.asciidoc +++ b/docs/reference/modules/http.asciidoc @@ -100,9 +100,6 @@ simple message will be returned. Defaults to `true` |`http.pipelining.max_events` |The maximum number of events to be queued up in memory before a HTTP connection is closed, defaults to `10000`. -|`http.content_type.required`|Enables or disables strict checking and usage of -the `Content-Type` header for all requests with content, defaults to `false`. - |======================================================================= It also uses the common diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportUpdateByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportUpdateByQueryAction.java index 8ee98d1df0a02..ec9cb94687abf 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportUpdateByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportUpdateByQueryAction.java @@ -120,7 +120,7 @@ protected RequestWrapper buildRequest(ScrollableHitSource.Hit doc) index.index(doc.getIndex()); index.type(doc.getType()); index.id(doc.getId()); - index.source(doc.getSource()); + index.source(doc.getSource(), doc.getXContentType()); index.versionType(VersionType.INTERNAL); index.version(doc.getVersion()); index.setPipeline(mainRequest.getPipeline()); diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexParentChildTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexParentChildTests.java index 58770e10a1caa..fdaf0fa83ccd1 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexParentChildTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexParentChildTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.reindex; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilder; import static org.elasticsearch.index.query.QueryBuilders.hasParentQuery; @@ -89,8 +90,8 @@ public void testErrorMessageWhenBadParentChild() throws Exception { */ private void createParentChildIndex(String indexName) throws Exception { CreateIndexRequestBuilder create = client().admin().indices().prepareCreate(indexName); - create.addMapping("city", "{\"_parent\": {\"type\": \"country\"}}"); - create.addMapping("neighborhood", "{\"_parent\": {\"type\": \"city\"}}"); + create.addMapping("city", "{\"_parent\": {\"type\": \"country\"}}", XContentType.JSON); + create.addMapping("neighborhood", "{\"_parent\": {\"type\": \"city\"}}", XContentType.JSON); assertAcked(create); ensureGreen(); } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSourceTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSourceTests.java index 82efe496b5e23..7a5837ddf7497 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSourceTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSourceTests.java @@ -389,7 +389,7 @@ public void testWrapExceptionToPreserveStatus() throws IOException { assertEquals("No error body.", wrapped.getMessage()); // Successfully get the status without a body - HttpEntity okEntity = new StringEntity("test body", StandardCharsets.UTF_8); + HttpEntity okEntity = new StringEntity("test body", ContentType.TEXT_PLAIN); wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(status.getStatus(), okEntity, cause); assertEquals(status, wrapped.status()); assertEquals(cause, wrapped.getCause()); diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java index dab33fc070d9b..703de568faafc 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.rest; +import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.elasticsearch.client.Response; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -55,7 +56,8 @@ private void createTestDoc(final String indexName, final String typeName) throws builder.field("test", "test"); } builder.endObject(); - client().performRequest("PUT", "/" + indexName + "/" + typeName + "/" + "1", emptyMap(), new StringEntity(builder.string())); + client().performRequest("PUT", "/" + indexName + "/" + typeName + "/" + "1", emptyMap(), + new StringEntity(builder.string(), ContentType.APPLICATION_JSON)); } } @@ -100,7 +102,7 @@ public void testAliasExists() throws IOException { } builder.endObject(); - client().performRequest("POST", "_aliases", emptyMap(), new StringEntity(builder.string())); + client().performRequest("POST", "_aliases", emptyMap(), new StringEntity(builder.string(), ContentType.APPLICATION_JSON)); headTestCase("/_alias/test_alias", emptyMap(), greaterThan(0)); headTestCase("/test/_alias/test_alias", emptyMap(), greaterThan(0)); } @@ -119,7 +121,8 @@ public void testTemplateExists() throws IOException { } builder.endObject(); - client().performRequest("PUT", "/_template/template", emptyMap(), new StringEntity(builder.string())); + client().performRequest("PUT", "/_template/template", emptyMap(), + new StringEntity(builder.string(), ContentType.APPLICATION_JSON)); headTestCase("/_template/template", emptyMap(), greaterThan(0)); } } @@ -147,7 +150,7 @@ public void testGetSourceAction() throws IOException { builder.endObject(); } builder.endObject(); - client().performRequest("PUT", "/test-no-source", emptyMap(), new StringEntity(builder.string())); + client().performRequest("PUT", "/test-no-source", emptyMap(), new StringEntity(builder.string(), ContentType.APPLICATION_JSON)); createTestDoc("test-no-source", "test-no-source"); headTestCase("/test-no-source/test-no-source/1/_source", emptyMap(), NOT_FOUND.getStatus(), equalTo(0)); } diff --git a/qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/IndexingIT.java b/qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/IndexingIT.java index 3dd984415922f..10b69fb297b18 100644 --- a/qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/IndexingIT.java +++ b/qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/IndexingIT.java @@ -28,9 +28,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.seqno.SeqNoStats; import org.elasticsearch.index.seqno.SequenceNumbersService; @@ -38,7 +36,6 @@ import org.elasticsearch.test.rest.yaml.ObjectPath; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; @@ -82,7 +79,7 @@ private void updateIndexSetting(String name, Settings.Builder settings) throws I } private void updateIndexSetting(String name, Settings settings) throws IOException { assertOK(client().performRequest("PUT", name + "/_settings", Collections.emptyMap(), - new StringEntity(Strings.toString(settings)))); + new StringEntity(Strings.toString(settings), ContentType.APPLICATION_JSON))); } protected int indexDocs(String index, final int idStart, final int numDocs) throws IOException { diff --git a/qa/rolling-upgrade/build.gradle b/qa/rolling-upgrade/build.gradle index 539e3f7bd5a46..1d79bb404fdd9 100644 --- a/qa/rolling-upgrade/build.gradle +++ b/qa/rolling-upgrade/build.gradle @@ -30,6 +30,7 @@ task oldClusterTest(type: RestIntegTestTask) { numNodes = 2 clusterName = 'rolling-upgrade' setting 'repositories.url.allowed_urls', 'http://snapshot.test*' + setting 'http.content_type.required', 'true' } systemProperty 'tests.rest.suite', 'old_cluster' } diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java index 752e18dc917a8..397838862c33f 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/ContextAndHeaderTransportIT.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.GeoShapeQueryBuilder; import org.elasticsearch.index.query.MoreLikeThisQueryBuilder; @@ -109,9 +110,9 @@ public void createIndices() throws Exception { .put(SETTING_NUMBER_OF_SHARDS, 1) // A single shard will help to keep the tests repeatable. .build(); assertAcked(transportClient().admin().indices().prepareCreate(lookupIndex) - .setSettings(settings).addMapping("type", mapping)); + .setSettings(settings).addMapping("type", mapping, XContentType.JSON)); assertAcked(transportClient().admin().indices().prepareCreate(queryIndex) - .setSettings(settings).addMapping("type", mapping)); + .setSettings(settings).addMapping("type", mapping, XContentType.JSON)); ensureGreen(queryIndex, lookupIndex); requests.clear(); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java index 9d99cd6d9be5a..99cb7690c8268 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java @@ -37,6 +37,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.Index; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java index 082a4fc604731..0324fedd57a98 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java @@ -55,15 +55,13 @@ public class ClientYamlTestClient { private final ClientYamlSuiteRestSpec restSpec; private final RestClient restClient; private final Version esVersion; - private final Map hostVersionMap; public ClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient, List hosts, - Version esVersion, Map hostVersionMap) throws IOException { + Version esVersion) throws IOException { assert hosts.size() > 0; this.restSpec = restSpec; this.restClient = restClient; this.esVersion = esVersion; - this.hostVersionMap = hostVersionMap; } public Version getEsVersion() { @@ -88,9 +86,9 @@ public ClientYamlTestResponse callApi(String apiName, Map params // And everything else is a url parameter! try { Response response = restClient.performRequest(method, path, queryStringParams, entity); - return new ClientYamlTestResponse(response, hostVersionMap.get(response.getHost())); + return new ClientYamlTestResponse(response); } catch(ResponseException e) { - throw new ClientYamlTestResponseException(e, hostVersionMap.get(e.getResponse().getHost())); + throw new ClientYamlTestResponseException(e); } } @@ -124,9 +122,7 @@ public ClientYamlTestResponse callApi(String apiName, Map params if (supportedMethods.contains("GET") && RandomizedTest.rarely()) { logger.debug("sending the request body as source param with GET method"); queryStringParams.put("source", body); - if (esVersion.onOrAfter(Version.V_5_3_0_UNRELEASED)) { - queryStringParams.put("source_content_type", ContentType.APPLICATION_JSON.toString()); - } + queryStringParams.put("source_content_type", ContentType.APPLICATION_JSON.toString()); requestMethod = "GET"; } else { requestMethod = RandomizedTest.randomFrom(supportedMethods); @@ -173,9 +169,9 @@ public ClientYamlTestResponse callApi(String apiName, Map params logger.debug("calling api [{}]", apiName); try { Response response = restClient.performRequest(requestMethod, requestPath, queryStringParams, requestBody, requestHeaders); - return new ClientYamlTestResponse(response, hostVersionMap.get(response.getHost())); + return new ClientYamlTestResponse(response); } catch(ResponseException e) { - throw new ClientYamlTestResponseException(e, hostVersionMap.get(e.getResponse().getHost())); + throw new ClientYamlTestResponseException(e); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java index 3e308234f521b..481ae752d05f0 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java @@ -21,7 +21,6 @@ import org.apache.http.Header; import org.apache.http.client.methods.HttpHead; import org.apache.http.util.EntityUtils; -import org.elasticsearch.Version; import org.elasticsearch.client.Response; import org.elasticsearch.common.xcontent.XContentType; @@ -38,12 +37,10 @@ public class ClientYamlTestResponse { private final Response response; private final String body; - private final Version nodeVersion; private ObjectPath parsedResponse; - ClientYamlTestResponse(Response response, Version version) throws IOException { + ClientYamlTestResponse(Response response) throws IOException { this.response = response; - this.nodeVersion = version; if (response.getEntity() != null) { try { this.body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); @@ -83,18 +80,7 @@ public List getWarningHeaders() { List warningHeaders = new ArrayList<>(); for (Header header : response.getHeaders()) { if (header.getName().equals("Warning")) { - if (nodeVersion.onOrAfter(Version.V_5_3_0_UNRELEASED) && response.getRequestLine().getMethod().equals("GET") - && response.getRequestLine().getUri().contains("source") - && response.getRequestLine().getUri().contains("source_content_type") == false && header.getValue().startsWith( - "Deprecated use of the [source] parameter without the [source_content_type] parameter.")) { - // this is because we do not send the source content type header when the node is 5.3.0 or below and the request - // might have been sent to a node with a version > 5.3.0 when running backwards 5.0 tests. The Java RestClient - // has control of the node the request is sent to so we can only detect this after the fact right now - // TODO remove this when we bump versions - } else { - warningHeaders.add(header.getValue()); - } - + warningHeaders.add(header.getValue()); } } return warningHeaders; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java index 48a7ee578d51a..7d983d480296b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java @@ -19,7 +19,6 @@ package org.elasticsearch.test.rest.yaml; -import org.elasticsearch.Version; import org.elasticsearch.client.ResponseException; import java.io.IOException; @@ -33,10 +32,10 @@ public class ClientYamlTestResponseException extends IOException { private final ClientYamlTestResponse restTestResponse; private final ResponseException responseException; - ClientYamlTestResponseException(ResponseException responseException, Version version) throws IOException { + ClientYamlTestResponseException(ResponseException responseException) throws IOException { super(responseException); this.responseException = responseException; - this.restTestResponse = new ClientYamlTestResponse(responseException.getResponse(), version); + this.restTestResponse = new ClientYamlTestResponse(responseException.getResponse()); } /** diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index 0f87f2f388d51..b64f12e9f0250 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -54,7 +54,6 @@ import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -127,7 +126,7 @@ public void initAndResetContext() throws IOException { validateSpec(restSpec); List hosts = getClusterHosts(); RestClient restClient = client(); - Tuple> versionMapTuple = readVersionsFromInfo(restClient, hosts.size()); + Version infoVersion = readVersionsFromInfo(restClient, hosts.size()); Version esVersion; try { Tuple versionVersionTuple = readVersionsFromCatNodes(restClient); @@ -138,14 +137,14 @@ public void initAndResetContext() throws IOException { } catch (ResponseException ex) { if (ex.getResponse().getStatusLine().getStatusCode() == 403) { logger.warn("Fallback to simple info '/' request, _cat/nodes is not authorized"); - esVersion = versionMapTuple.v1(); + esVersion = infoVersion; logger.info("initializing yaml client, minimum es version: [{}] hosts: {}", esVersion, hosts); } else { throw ex; } } ClientYamlTestClient clientYamlTestClient = - new ClientYamlTestClient(restSpec, restClient, hosts, esVersion, versionMapTuple.v2()); + new ClientYamlTestClient(restSpec, restClient, hosts, esVersion); restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient); adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient); String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null); @@ -294,7 +293,7 @@ public static void clearStatic() { private static Tuple readVersionsFromCatNodes(RestClient restClient) throws IOException { // we simply go to the _cat/nodes API and parse all versions in the cluster Response response = restClient.performRequest("GET", "/_cat/nodes", Collections.singletonMap("h", "version,master")); - ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response, Version.CURRENT); + ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response); String nodesCatResponse = restTestResponse.getBodyAsString(); String[] split = nodesCatResponse.split("\n"); Version version = null; @@ -317,13 +316,12 @@ private static Tuple readVersionsFromCatNodes(RestClient restC return new Tuple<>(version, masterVersion); } - private static Tuple> readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException { + private static Version readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException { Version version = null; - Map hostVersionMap = new HashMap<>(); for (int i = 0; i < numHosts; i++) { //we don't really use the urls here, we rely on the client doing round-robin to touch all the nodes in the cluster Response response = restClient.performRequest("GET", "/"); - ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response, Version.CURRENT); + ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response); Object latestVersion = restTestResponse.evaluate("version.number"); if (latestVersion == null) { throw new RuntimeException("elasticsearch version not found in the response"); @@ -334,9 +332,8 @@ private static Tuple> readVersionsFromInfo(RestC } else if (version.onOrAfter(currentVersion)) { version = currentVersion; } - hostVersionMap.put(response.getHost(), currentVersion); } - return new Tuple<>(version, Collections.unmodifiableMap(hostVersionMap)); + return version; } public void test() throws IOException {