-
Notifications
You must be signed in to change notification settings - Fork 896
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
Provide a way to find dynamic decorators handling the current request #5670
Conversation
Motivation: `HttpService.as(Class)` can be used to unwrap and find an instance of a decorator or a service. `ServiceRequestContext.config().service().as(Class)` can't find all decorators because decoraters set with `ServerBuilder.decorator()` don't statically wrap the services. I propose to add `ServiceRequestContext.findService(Class)` for finding both dynamic and static decorators handling a request. Modifcations: - Add `ServiceRequestContext.findService(Class)` that gets all service chain from `InitialDispatcherService` and finds the specific service. Result: You can easily find both dynamic and static decorators that handle a request by using `ServiceRequestContext.findService(Class)`.
@@ -162,7 +163,7 @@ public String toString() { | |||
.toString(); | |||
} | |||
|
|||
private static class InitialDispatcherService extends SimpleDecoratingHttpService { | |||
public static final class InitialDispatcherService extends SimpleDecoratingHttpService { |
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 kept InitialDispatcherService
as the nested class because InitialDispatcherService
and RouteDecoratingService
are tightly coupled.
core/src/main/java/com/linecorp/armeria/internal/server/RouteDecoratingService.java
Outdated
Show resolved
Hide resolved
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.
Nicely done 👍 Thanks @ikhoon ! 🙇 👍 🙇
core/src/main/java/com/linecorp/armeria/internal/server/DefaultServiceRequestContext.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServiceRequestContext.java
Outdated
Show resolved
Hide resolved
…tServiceRequestContext.java Co-authored-by: jrhee17 <guins_j@guins.org>
…ontext.java Co-authored-by: jrhee17 <guins_j@guins.org>
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.
Excellent!
core/src/main/java/com/linecorp/armeria/internal/server/DefaultServiceRequestContext.java
Show resolved
Hide resolved
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.
👍 👍 👍
Motivation: This PR is follow-up of line#5632 (comment) and line#5670 that apply `ctx.findService()` to find `CorsService` added with route decorators. Modifications: - Use `ctx.findService()` to find `CorsService` in the service chain of a request Result: CorsServerErrorHandler now correctly handle response exceptions even if `CorsService` added as a route decorator. (Not need to metion in the release notes)
Motivation: This PR is follow-up of #5632 (comment) and #5670 that `ctx.findService()` should be used to find `CorsService` added with route decorators. Modifications: - Use `ctx.findService()` to find `CorsService` in the service chain of a request Result: CorsServerErrorHandler now correctly handles response exceptions even if `CorsService` is added as a route decorator. (Not need to be mentioned in the release notes)
…line#5670) Motivation: `HttpService.as(Class)` can be used to unwrap and find an instance of a decorator or a service. `ServiceRequestContext.config().service().as(Class)` can't find all decorators because decorators set with `ServerBuilder.decorator()` don't statically wrap the services. I propose to add `ServiceRequestContext.findService(Class)` for finding both dynamic and static decorators handling a request. Modifications: - Add `ServiceRequestContext.findService(Class)` that gets all service chain from `InitialDispatcherService` and finds the specific service. Result: You can now easily find both dynamic and static decorators that handle a request by using `ServiceRequestContext.findService(Class)`.
…#5739) Motivation: This PR is follow-up of line#5632 (comment) and line#5670 that `ctx.findService()` should be used to find `CorsService` added with route decorators. Modifications: - Use `ctx.findService()` to find `CorsService` in the service chain of a request Result: CorsServerErrorHandler now correctly handles response exceptions even if `CorsService` is added as a route decorator. (Not need to be mentioned in the release notes)
Motivation:
HttpService.as(Class)
can be used to unwrap and find an instance of a decorator or a service.ServiceRequestContext.config().service().as(Class)
can't find all decorators because decorators set withServerBuilder.decorator()
don't statically wrap the services.I propose to add
ServiceRequestContext.findService(Class)
for finding both dynamic and static decorators handling a request.Modifications:
ServiceRequestContext.findService(Class)
that gets all service chain fromInitialDispatcherService
and finds the specific service.Result:
You can now easily find both dynamic and static decorators that handle a request by using
ServiceRequestContext.findService(Class)
.