-
Notifications
You must be signed in to change notification settings - Fork 926
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
Support RxJava-wrapped HttpResult
response in annotated services
#5386
Conversation
@@ -62,6 +63,12 @@ public HttpResponse convertResponse(ServiceRequestContext ctx, | |||
if (result instanceof HttpResponse) { | |||
return (HttpResponse) result; | |||
} | |||
if (result instanceof HttpResult) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very familiar with the converter setup, so I'm not 100% sure if this is the only guaranteed entrypoint to the converter chain where we might receive an HttpResult
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the place to put logic because we don't support the conversion recursively.
import io.reactivex.rxjava3.core.Single; | ||
|
||
@ProducesJson | ||
public class ReactiveService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary service for testing purposes. I still need to test Mono
, but I want to figure out how to apply the converters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just leave it as TODO.
I thought we already had something like ReactorResponseConverterFuction
but we don't have.
We can implement it later when we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see! I've just tested an API that returns Mono
and it indeed seems like that's not implemented yet.
b4d8cfb
to
449361d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologize for the late review. The changes look good to me. 👍
@@ -62,6 +63,12 @@ public HttpResponse convertResponse(ServiceRequestContext ctx, | |||
if (result instanceof HttpResponse) { | |||
return (HttpResponse) result; | |||
} | |||
if (result instanceof HttpResult) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the place to put logic because we don't support the conversion recursively.
import io.reactivex.rxjava3.core.Single; | ||
|
||
@ProducesJson | ||
public class ReactiveService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just leave it as TODO.
I thought we already had something like ReactorResponseConverterFuction
but we don't have.
We can implement it later when we need it.
HttpResult
response in annotated servicesHttpResult
response in annotated services
final AnnotatedService service = ctx.config().service().as(AnnotatedService.class); | ||
if (service != null) { | ||
builder.status(service.defaultStatus()); | ||
} else { | ||
builder.status(HttpStatus.OK); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing that changed from the original implementation in AnnotatedService
d5a44e9
to
3d790ea
Compare
3d790ea
to
a5dc644
Compare
Seems like adding |
04e49d6
to
ea25d7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add tests that check if the following types are converted correctly?
CompletableFuture<HttpResult>
and Single<HttpResult>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!!! Thanks a lot, @KarboniteKream! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for reporting/fixing this issue @KarboniteKream 🙇 👍 🙇
@@ -398,7 +402,7 @@ private HttpResponse convertResponse(ServiceRequestContext ctx, @Nullable Object | |||
|
|||
if (result instanceof HttpResult) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note; Perhaps in the future we may just remove this block since CompositeResponseConverterFunction
has this logic already.
I understand this can't be removed this iteration due to breaking changes though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried that but it fails depends on the implementation:
armeria/kotlin/src/test/kotlin/com/linecorp/armeria/server/kotlin/SuspendingAnnotatedServiceTest.kt
Lines 374 to 377 in d34cee7
when (result) { | |
is Bar -> responseConverter.convertResponse(ctx, headers, "hello, bar!", trailers) | |
else -> ResponseConverterFunction.fallthrough() | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I also checked that the content unwrapping logic is the reason for the failure
result = httpResult.content();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean fix! ❤️💯
Motivation:
When returning
Single<HttpResult<T>>
from an annotated service, the response is always serialized as{}
, since we currently just try to serializeHttpResult
with Jackson. Instead, we should convert it toHttpResponse
and only do serialization onHttpResult.content()
.Modifications:
HttpResultUtil
with the logic needed to buildHttpResponse
headers fromHttpResult
HttpResult
conversion logic fromAnnotatedService
toCompositeResponseConverterFunction
Result:
Single<HttpResult<T>>
#5380HttpResult
wrapped in RxJava objects