Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce Content-Type requirement on the rest layer and remove deprecated methods #23146

Merged
merged 8 commits into from
Feb 17, 2017

Conversation

jaymode
Copy link
Member

@jaymode jaymode commented Feb 13, 2017

This commit enforces the requirement of Content-Type for the REST layer and removes the deprecated methods in transport requests and their usages.

While doing this, it turns out that there are many places where *Entity classes are used from the apache http client libraries and many of these usages did not specify the content type. The methods that do not specify a content type explicitly have been added to forbidden apis to prevent more of these from entering our code base.

Relates #19388

…ted methods

This commit enforces the requirement of Content-Type for the REST layer and removes the deprecated methods in transport
requests and their usages.

While doing this, it turns out that there are many places where *Entity classes are used from the apache http client
libraries and many of these usages did not specify the content type. The methods that do not specify a content type
explicitly have been added to forbidden apis to prevent more of these from entering our code base.

Relates elastic#19388
@clintongormley
Copy link
Contributor

Please add breaking changes docs

@jaymode
Copy link
Member Author

jaymode commented Feb 14, 2017

Please add breaking changes docs

Thanks for the reminder. Breaking changes docs were added as part of #22691 and I cleaned them up some more.

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few comments, LGTM besides those

@defaultMessage Explicitly specify the ContentType of HTTP entities
org.apache.http.entity.StringEntity#<init>(java.lang.String)
org.apache.http.entity.StringEntity#<init>(java.lang.String,java.lang.String)
org.apache.http.entity.StringEntity#<init>(java.lang.String,java.nio.charset.Charset)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also add ByteArrayEntity here? what is the difference between the http-signatures file below and this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ I should add all of those here. The difference is the http-signatures file is used only for the rest projects as they do not use the es-test-signatures.

I could move the http signatures to the buildSrc and then have the default forbidden apis for tests include that file as well. This way we only need to update the file in one place.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would do that, unless there are downsides that I am not seeing

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing all these.

" upgrade easier");
}
return true;
}, Property.NodeScope, Property.Deprecated);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a test for this? just making sure that a 5.x cluster having the setting set to false can upgrade to 6.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add this as a setting for a node in the rolling-upgrade tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good.

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 (JSON, YAML, CBOR, SMILE, and NDJSON).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do throw error when one sets CBOR or YAML using _bulk, or NDJSON using e.g. search ?


The default value is `false`.
Additionally, when using the `source` query string parameter the
content type should be specified using the `source_content_type` query
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be ? :)

@@ -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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add a bullet point on the removal of all those setters from the Java api? If we don't want to list them all, shall we just explain the change which type of methods it affects and how to fix the compile error?

@jaymode jaymode merged commit b234644 into elastic:master Feb 17, 2017
@jaymode
Copy link
Member Author

jaymode commented Feb 17, 2017

Thanks @javanna !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>breaking :Core/Infra/REST API REST infrastructure and utilities :Core/Infra/Transport API Transport client API v6.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants