Topics

Question on CompletionStage

 

Pavel,

 

as the spec does not explicitly mention it, can you please confirm that what the spec actually wants to say is that CompletionStage does not only imply async when declared as a method's return type, but also when CompletionStage is de-facto returned by a method or by a interceptor (i. e. the method itself is not declared to return CompletionStage, but might return Object and an interceptor produces a CompletionStage from that)? This would allow framework providers to provide "JAX-RS adapter" like an interceptor turning RxJava's Observable into Java 8's CompletionStage. The spec is a bit short here.

 

Thanks

-Markus

Pavel Bucek
 

Hi Markus,

confirming what you wrote would be extending of what is pretty explicitly written in the spec, so I can't do that.

Currently, the behavior is "defined" by what AsyncResponse provides and there is nothing like you mentioned there, so I don't think that the usecase you described is supported - returned Observable (or any other type) will be processed as any other type, so the pipeline will be triggered right after the object is returned from the resource method.

Returning CompletionStage is equal to invoking AsyncResponse#resume in CompletionStage#whenComplete callback, nothing more, nothing less..

Regards,
Pavel


On 18/08/2017 17:23, Markus KARG wrote:

Pavel,

 

as the spec does not explicitly mention it, can you please confirm that what the spec actually wants to say is that CompletionStage does not only imply async when declared as a method's return type, but also when CompletionStage is de-facto returned by a method or by a interceptor (i. e. the method itself is not declared to return CompletionStage, but might return Object and an interceptor produces a CompletionStage from that)? This would allow framework providers to provide "JAX-RS adapter" like an interceptor turning RxJava's Observable into Java 8's CompletionStage. The spec is a bit short here.

 

Thanks

-Markus


Sergey Beryozkin
 

Hi Pavel

FYI, in CXF returning Observable will be handled similarly to returning CompletionStage

Cheers, Sergey

On 22/08/17 09:06, Pavel Bucek wrote:

Hi Markus,

confirming what you wrote would be extending of what is pretty explicitly written in the spec, so I can't do that.

Currently, the behavior is "defined" by what AsyncResponse provides and there is nothing like you mentioned there, so I don't think that the usecase you described is supported - returned Observable (or any other type) will be processed as any other type, so the pipeline will be triggered right after the object is returned from the resource method.

Returning CompletionStage is equal to invoking AsyncResponse#resume in CompletionStage#whenComplete callback, nothing more, nothing less..

Regards,
Pavel


On 18/08/2017 17:23, Markus KARG wrote:

Pavel,

 

as the spec does not explicitly mention it, can you please confirm that what the spec actually wants to say is that CompletionStage does not only imply async when declared as a method's return type, but also when CompletionStage is de-facto returned by a method or by a interceptor (i. e. the method itself is not declared to return CompletionStage, but might return Object and an interceptor produces a CompletionStage from that)? This would allow framework providers to provide "JAX-RS adapter" like an interceptor turning RxJava's Observable into Java 8's CompletionStage. The spec is a bit short here.

 

Thanks

-Markus



Pavel Bucek
 

Hi Sergey,

I guess that's fine, unless someone registers MessageBodyWriter for Observable, which might then now work properly.

I'm not saying that because I think that it shouldn't be done, its just something which is not defined by the specification and JAX-RS user can't rely on this to work everywhere.

// and I'm certainly not saying that we won't do something like that for Jersey :)

Thanks and regards,
Pavel


On 22/08/2017 16:58, Sergey Beryozkin wrote:
Hi Pavel

FYI, in CXF returning Observable will be handled similarly to returning CompletionStage

Cheers, Sergey
On 22/08/17 09:06, Pavel Bucek wrote:

Hi Markus,

confirming what you wrote would be extending of what is pretty explicitly written in the spec, so I can't do that.

Currently, the behavior is "defined" by what AsyncResponse provides and there is nothing like you mentioned there, so I don't think that the usecase you described is supported - returned Observable (or any other type) will be processed as any other type, so the pipeline will be triggered right after the object is returned from the resource method.

Returning CompletionStage is equal to invoking AsyncResponse#resume in CompletionStage#whenComplete callback, nothing more, nothing less..

Regards,
Pavel


On 18/08/2017 17:23, Markus KARG wrote:

Pavel,

 

as the spec does not explicitly mention it, can you please confirm that what the spec actually wants to say is that CompletionStage does not only imply async when declared as a method's return type, but also when CompletionStage is de-facto returned by a method or by a interceptor (i. e. the method itself is not declared to return CompletionStage, but might return Object and an interceptor produces a CompletionStage from that)? This would allow framework providers to provide "JAX-RS adapter" like an interceptor turning RxJava's Observable into Java 8's CompletionStage. The spec is a bit short here.

 

Thanks

-Markus




 

I think it make sense to file this as an issue for JAX-RS 2.2 / 3.0, so a future specification will align CXF and Jersey and give application developers safety how things shall work.

 

From: jaxrs-spec@javaee.groups.io [mailto:jaxrs-spec@javaee.groups.io] On Behalf Of Pavel Bucek
Sent: Dienstag, 22. August 2017 18:29
To: jaxrs-spec@javaee.groups.io
Subject: Re: [jaxrs] Question on CompletionStage

 

Hi Sergey,

I guess that's fine, unless someone registers MessageBodyWriter for Observable, which might then now work properly.

I'm not saying that because I think that it shouldn't be done, its just something which is not defined by the specification and JAX-RS user can't rely on this to work everywhere.

// and I'm certainly not saying that we won't do something like that for Jersey :)

Thanks and regards,
Pavel

 

On 22/08/2017 16:58, Sergey Beryozkin wrote:

Hi Pavel

FYI, in CXF returning Observable will be handled similarly to returning CompletionStage

Cheers, Sergey
On 22/08/17 09:06, Pavel Bucek wrote:

Hi Markus,

confirming what you wrote would be extending of what is pretty explicitly written in the spec, so I can't do that.

Currently, the behavior is "defined" by what AsyncResponse provides and there is nothing like you mentioned there, so I don't think that the usecase you described is supported - returned Observable (or any other type) will be processed as any other type, so the pipeline will be triggered right after the object is returned from the resource method.

Returning CompletionStage is equal to invoking AsyncResponse#resume in CompletionStage#whenComplete callback, nothing more, nothing less..

Regards,
Pavel

 

On 18/08/2017 17:23, Markus KARG wrote:

Pavel,

 

as the spec does not explicitly mention it, can you please confirm that what the spec actually wants to say is that CompletionStage does not only imply async when declared as a method's return type, but also when CompletionStage is de-facto returned by a method or by a interceptor (i. e. the method itself is not declared to return CompletionStage, but might return Object and an interceptor produces a CompletionStage from that)? This would allow framework providers to provide "JAX-RS adapter" like an interceptor turning RxJava's Observable into Java 8's CompletionStage. The spec is a bit short here.

 

Thanks

-Markus

 

 

 

Sergey Beryozkin
 

Hi Pavel

On 22/08/17 17:29, Pavel Bucek wrote:

Hi Sergey,

I guess that's fine, unless someone registers MessageBodyWriter for Observable, which might then now work properly.

You are right technically having MBW<Observable> is a possibility but practically speaking I can't see anyone doing it, though this is how I started from myself, but it might only work for something like Observable.just("Hello World")

I'm not saying that because I think that it shouldn't be done, its just something which is not defined by the specification and JAX-RS user can't rely on this to work everywhere.

// and I'm certainly not saying that we won't do something like that for Jersey :)


Yeah, lets go beyond the spec limits a bit :-)

Thanks, Sergey

Thanks and regards,
Pavel


On 22/08/2017 16:58, Sergey Beryozkin wrote:
Hi Pavel

FYI, in CXF returning Observable will be handled similarly to returning CompletionStage

Cheers, Sergey
On 22/08/17 09:06, Pavel Bucek wrote:

Hi Markus,

confirming what you wrote would be extending of what is pretty explicitly written in the spec, so I can't do that.

Currently, the behavior is "defined" by what AsyncResponse provides and there is nothing like you mentioned there, so I don't think that the usecase you described is supported - returned Observable (or any other type) will be processed as any other type, so the pipeline will be triggered right after the object is returned from the resource method.

Returning CompletionStage is equal to invoking AsyncResponse#resume in CompletionStage#whenComplete callback, nothing more, nothing less..

Regards,
Pavel


On 18/08/2017 17:23, Markus KARG wrote:

Pavel,

 

as the spec does not explicitly mention it, can you please confirm that what the spec actually wants to say is that CompletionStage does not only imply async when declared as a method's return type, but also when CompletionStage is de-facto returned by a method or by a interceptor (i. e. the method itself is not declared to return CompletionStage, but might return Object and an interceptor produces a CompletionStage from that)? This would allow framework providers to provide "JAX-RS adapter" like an interceptor turning RxJava's Observable into Java 8's CompletionStage. The spec is a bit short here.

 

Thanks

-Markus