-
Notifications
You must be signed in to change notification settings - Fork 925
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
Implement @Attribute Injection. #5547
Conversation
28bc91d
to
eac6431
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5547 +/- ##
============================================
+ Coverage 73.95% 74.11% +0.16%
- Complexity 20115 21019 +904
============================================
Files 1730 1819 +89
Lines 74161 77418 +3257
Branches 9465 9891 +426
============================================
+ Hits 54847 57380 +2533
- Misses 14837 15385 +548
- Partials 4477 4653 +176 ☔ View full report in Codecov by Sentry. |
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.
Good start! Looking forward to the update 🙇
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/annotation/Attribute.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedElementNameUtil.java
Outdated
Show resolved
Hide resolved
52f3f53
to
2801cdd
Compare
3e809c7
to
889d887
Compare
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
126284b
to
42ef9a2
Compare
.../src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedElementNameUtil.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedElementNameUtil.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedElementNameUtil.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.
Could you fix all lint errors?
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/annotation/Attribute.java
Outdated
Show resolved
Hide resolved
...rc/test/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolverTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolverTest.java
Outdated
Show resolved
Hide resolved
@ikhoon nim, Thanks for your comment. @ikhoon nim, @minwoox nim, sorry to bother you. |
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.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.
I think we're pretty close again, now. Thanks a lot for your patience, @chickenchickenlove! 🙇
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolver.java
Outdated
Show resolved
Hide resolved
...rc/test/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolverTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/com/linecorp/armeria/internal/server/annotation/AnnotatedValueResolverTest.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/annotation/Attribute.java
Show resolved
Hide resolved
…tion/AnnotatedValueResolver.java Co-authored-by: Trustin Lee <t@motd.kr>
…tion/AnnotatedValueResolver.java Co-authored-by: Trustin Lee <t@motd.kr>
…tion/AnnotatedValueResolverTest.java Co-authored-by: Trustin Lee <t@motd.kr>
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.
Still looks good! 👍
if (targetType.isPrimitive()) { | ||
targetType = Primitives.wrap(targetType); | ||
} |
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.
Micro optimization) Should we do this when rawType
is created to avoid additional costs?
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.
You are right 👍
Using rawType
might result in some additional costs due to Wrapping in all AnnotatedValueResolvers that do not use rawType. However, unnecessary calls will be made at most once during initialization
, and afterwards, it could save on the cost of Wrapping with each incoming user request.
core/src/main/java/com/linecorp/armeria/server/annotation/Attribute.java
Show resolved
Hide resolved
…ibute.java Co-authored-by: Ikhun Um <ih.pert@gmail.com>
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.
Oops! Sorry but would you mind resolving the merge conflict, @chickenchickenlove ? |
Thanks a lot for updating the PR description and resolving the merge conflict, @chickenchickenlove! 🙇🙇🙇 |
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.
Still LGTM. Thanks!
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: - In the past, users could get a value from `ServiceRequestContext` by using `ServiceRequestContext.attr(key)`. however, if it were possible to inject values which in `ServiceRequestContext` into method parameters using any annotation, users would be able to use it more conveniently. ### Modifications: - New annotation. `@Attribute` is added. - Make new field `rawType` in `AnnotatedValueResolver` to validate type cast. - New methods `ofAttribute()` and `attributeResolver()` are added to `AnnotatedValueResolver` to get values from `ServiceRequestContext` and inject them method parameters. - `findName()` in `AnnotatedElementNameUtil` method have been merged into a single method. (refactoring for internal use) - Add test codes. - Add document explaining how to use the `@Attribute` annotation. ### Result: - Closes line#5514 - Users can inject values from the `ServiceRequestContext` into method parameters using the `@Attribute` annotation without `ServiceRequestContext.attr(key)`. --------- Co-authored-by: Trustin Lee <t@motd.kr> Co-authored-by: Ikhun Um <ih.pert@gmail.com> Co-authored-by: minux <songmw725@gmail.com>
Motivation: We must not convert the header name specified in `@Header` when creating an annotated service. This is a regression introduced by #5547, affecting 1.29.0 through 1.29.3. Modifications: - Do not convert the header name specified in `@Header`. Result: - An annotated service that has a `@Header` with the specified name now works correctly.
Motivation: We must not convert the header name specified in `@Header` when creating an annotated service. This is a regression introduced by line#5547, affecting 1.29.0 through 1.29.3. Modifications: - Do not convert the header name specified in `@Header`. Result: - An annotated service that has a `@Header` with the specified name now works correctly.
Motivation:
ServiceRequestContext
by usingServiceRequestContext.attr(key)
. however, if it were possible to inject values which inServiceRequestContext
into method parameters using any annotation, users would be able to use it more conveniently.Modifications:
@Attribute
is added.rawType
inAnnotatedValueResolver
to validate type cast.ofAttribute()
andattributeResolver()
are added toAnnotatedValueResolver
to get values fromServiceRequestContext
and inject them method parameters.findName()
inAnnotatedElementNameUtil
method have been merged into a single method. (refactoring for internal use)@Attribute
annotation.Result:
@Attribute
in annotated services #5514ServiceRequestContext
into method parameters using the@Attribute
annotation withoutServiceRequestContext.attr(key)
.