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

Add Response.isClosed() #1008

Merged
merged 1 commit into from
Aug 24, 2021
Merged

Add Response.isClosed() #1008

merged 1 commit into from
Aug 24, 2021

Conversation

NicoNes
Copy link
Contributor

@NicoNes NicoNes commented Aug 10, 2021

This PR is the follow-up to the issue and discussion we had with @ronsigal.

To sum up it was about adding a method in the Response class to know when a response instance is closed. So that we no longer need to write code like:


try {
   if (response.getEntity() != null) return response;
}
catch(IllegalStateException ise) {
   // IllegalStateException from ClientResponse.getEntity() means the response is closed and got no entity
} 

but instead:

if (!response.isClosed() && response.getEntity() != null) {
   return response;
}

I agree that the default implementation I proposed is a bit weird, not intuitive etc . I did it so that vendors don't need to make changes on their side.
I'm OK to remove it if you think it's not necessary.

Thanks

Copy link
Contributor

@andymc12 andymc12 left a comment

Choose a reason for hiding this comment

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

LGTM - thanks!

Copy link
Contributor

@mkarg mkarg left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for this contribution!

@mkarg
Copy link
Contributor

mkarg commented Aug 11, 2021

I'd like to propose that we add this to 3.1 already as it does not change the API in an incompatible way thanks to the default implementation.

Speaking of the default implementation I'd like to kindly ask all vendors to override it using an implementation that works with higher performance than the default solution.

Last but not least I am kindly asking for TCK coverage.

@NicoNes
Copy link
Contributor Author

NicoNes commented Aug 11, 2021

@mkarg do you want me to add somehing as follow in the doc ?

For backwards compatibility, there is a default implementation that just relies on IllegalStateException thrown by hasEntity when response instance is closed.
Implementations should consider replacing this with a more performant implementation

@mkarg
Copy link
Contributor

mkarg commented Aug 15, 2021

@mkarg do you want me to add somehing as follow in the doc ?

For backwards compatibility, there is a default implementation that just relies on IllegalStateException thrown by hasEntity when response instance is closed.
Implementations should consider replacing this with a more performant implementation

I do not see a need for this, actually.

@mkarg
Copy link
Contributor

mkarg commented Aug 15, 2021

@NicoNes If you like to contribute it: For this feature we need a note in the "Changes since" section of the spec, an example in the examples folder would be great, and the TCK needs to test that the actual implementation provided by the vendor works just as correct as your default implementation.

@spericas
Copy link
Contributor

@NicoNes If you like to contribute it: For this feature we need a note in the "Changes since" section of the spec

That's required only for changes to the spec document.

an example in the examples folder would be great, and the TCK needs to test that the actual implementation provided by the vendor works just as correct as your default implementation.

Given the simplicity of this (just a convenience method), more of a nice to have IMO.

@NicoNes
Copy link
Contributor Author

NicoNes commented Aug 19, 2021

Well @spericas and @mkarg given your two different opinions I don't really know what I have to do. Please let me know.

Thanks

@mkarg
Copy link
Contributor

mkarg commented Aug 19, 2021

@NicoNes If you like to contribute it: For this feature we need a note in the "Changes since" section of the spec

That's required only for changes to the spec document.

an example in the examples folder would be great, and the TCK needs to test that the actual implementation provided by the vendor works just as correct as your default implementation.

Given the simplicity of this (just a convenience method), more of a nice to have IMO.

Okay, let's rephrase: It would be nice to have it, so users know about its existence and usage. :-)

@spericas
Copy link
Contributor

@NicoNes The PR has all the necessary approvals to be merged.

@mkarg mkarg self-assigned this Aug 24, 2021
@mkarg mkarg added the api label Aug 24, 2021
@mkarg mkarg added this to the 3.1 milestone Aug 24, 2021
@mkarg mkarg merged commit 4ecc44c into jakartaee:master Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants