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

Provide a way to find dynamic decorators handling the current request #5670

Merged
merged 11 commits into from
May 31, 2024

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented May 9, 2024

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

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 {
Copy link
Contributor Author

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.

Copy link
Contributor

@jrhee17 jrhee17 left a 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 ! 🙇 👍 🙇

ikhoon and others added 3 commits May 10, 2024 10:30
…tServiceRequestContext.java

Co-authored-by: jrhee17 <guins_j@guins.org>
…ontext.java

Co-authored-by: jrhee17 <guins_j@guins.org>
Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Excellent!

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

👍 👍 👍

@minwoox minwoox merged commit e263d76 into line:main May 31, 2024
15 checks passed
ikhoon added a commit to ikhoon/armeria that referenced this pull request Jun 7, 2024
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)
trustin pushed a commit that referenced this pull request Jun 7, 2024
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)
Dogacel pushed a commit to Dogacel/armeria that referenced this pull request Jun 8, 2024
…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)`.
Dogacel pushed a commit to Dogacel/armeria that referenced this pull request Jun 8, 2024
…#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants