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

Support multiple Path annotations #1870

Merged
merged 10 commits into from
Oct 23, 2019
Merged

Conversation

jrhee17
Copy link
Contributor

@jrhee17 jrhee17 commented Jun 29, 2019

Motivation:
A user might want to specify multiple paths for annotated http services.

Modification:

  • Allow repeatable annotations for @Path annotation.
  • Different behavior in path declaration (described below)
  • One AnnotatedHttpService is created for each (httpMethod, pathMapping)
    • It is difficult to accommodate multiple pathMappings using a single AnnotatedHttpService because AnnotatedValueResolver may be different
    • It may be possible to optimize this by serving multiple httpMethods that have the same pathMapping using a single AnnotatedHttpService at the cost of code complexiy
  • Merge MethodInfo endpoints with same (httpMethod, methodName)
  • Known issue: overloaded methods for AnnotatedHttpService are not displayed in docs. I'm thinking this can be tackled in a separate PR.

Breaking change in path declaration behavior

AS-IS

@Get("/")
@Post
public void method1() {} // accepts both Get("/") and Post("/")

TO-BE

@Get("/")
@Post
public void method1() {} // exception thrown. Path declared for Get not applied to Post

@trustin
Copy link
Member

trustin commented Jun 29, 2019

Test looks good to me. 👍

@codecov
Copy link

codecov bot commented Jun 29, 2019

Codecov Report

Merging #1870 into master will increase coverage by 0.01%.
The diff coverage is 97.05%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1870      +/-   ##
============================================
+ Coverage     73.59%   73.61%   +0.01%     
- Complexity     9589     9601      +12     
============================================
  Files           838      838              
  Lines         36944    36985      +41     
  Branches       4554     4555       +1     
============================================
+ Hits          27190    27227      +37     
  Misses         7429     7429              
- Partials       2325     2329       +4
Impacted Files Coverage Δ Complexity Δ
.../com/linecorp/armeria/server/docs/ServiceInfo.java 78.94% <100%> (+8.21%) 20 <4> (+4) ⬆️
...ternal/annotation/AnnotatedHttpServiceFactory.java 87.24% <96.38%> (+1.66%) 90 <23> (+10) ⬆️
...a/com/linecorp/armeria/internal/DefaultValues.java 66.66% <0%> (-33.34%) 4% <0%> (-1%)
...n/java/com/linecorp/armeria/server/HttpServer.java 40% <0%> (-20%) 2% <0%> (-1%)
...necorp/armeria/server/GracefulShutdownSupport.java 97.43% <0%> (-2.57%) 4% <0%> (ø)
.../main/java/com/linecorp/armeria/server/Server.java 82.74% <0%> (-1.18%) 29% <0%> (ø)
...a/com/linecorp/armeria/common/util/Exceptions.java 38.59% <0%> (-0.88%) 24% <0%> (-1%)
...com/linecorp/armeria/server/HttpServerHandler.java 80.73% <0%> (-0.67%) 81% <0%> (-1%)
...inecorp/armeria/server/HttpResponseSubscriber.java 85.04% <0%> (-0.43%) 75% <0%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cca8e3c...84bbda3. Read the comment docs.

@jrhee17 jrhee17 changed the title [WIP] add unit test for supporting multiple paths [WIP] support multiple @Path annotations Jun 30, 2019
@trustin
Copy link
Member

trustin commented Jul 10, 2019

How's it going? Just let us know if you have any questions working on this. 😉

@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch from 2a7e1b5 to 56dbfb1 Compare August 7, 2019 15:38
@trustin
Copy link
Member

trustin commented Aug 8, 2019

Please let us know once this pull request is ready for reviews.

@jrhee17
Copy link
Contributor Author

jrhee17 commented Aug 9, 2019

I saw your comment late :P Yep:) I'll remove the WIP label and add a comment when ready

@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch 4 times, most recently from 8d1f791 to c4e08b7 Compare August 11, 2019 16:33
@ikhoon
Copy link
Contributor

ikhoon commented Sep 4, 2019

Fixes: #1822 (just for link)

@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch from e93974d to 781d06a Compare October 3, 2019 17:08
@trustin
Copy link
Member

trustin commented Oct 4, 2019

@jrhee17 Thanks a lot for coming back! Is it now ready for reviews?

@jrhee17
Copy link
Contributor Author

jrhee17 commented Oct 4, 2019

Hi :D . I think overall this is good to go, but let me clean up code/add some documentation/add tests before asking for review. I'll leave a comment when ready

@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch from 781d06a to d02effe Compare October 6, 2019 14:34
@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch from d02effe to 004cb49 Compare October 6, 2019 17:59
@jrhee17 jrhee17 changed the title [WIP] support multiple @Path annotations Support multiple @Path annotations Oct 7, 2019
@jrhee17
Copy link
Contributor Author

jrhee17 commented Oct 7, 2019

I think this PR is (finally) ready for review now~ :-)

@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch from 4814559 to 68f12e4 Compare October 7, 2019 16:27
@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch 2 times, most recently from 7e0ea70 to 48d9bed Compare October 10, 2019 16:29
@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch from 48d9bed to 042691a Compare October 10, 2019 22:34
@jrhee17 jrhee17 closed this Oct 17, 2019
@jrhee17 jrhee17 reopened this Oct 17, 2019
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 work, @jrhee17! 👍

@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch from 4c76bdd to 49bfafd Compare October 17, 2019 22:40
Copy link
Contributor

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

Left some nits. Thanks a lot @jrhee17!

site/src/sphinx/server-annotated-service.rst Show resolved Hide resolved
@@ -79,14 +79,12 @@ function removeBrackets(headers: string): string {
return headers.substring(1, length - 1).trim();
}

function isExactPathMapping(method: Method): boolean {
function isSingleExactPathMapping(method: Method): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

We use this value to display different forms in doc service.
If this is true, HttpQueryString shows up. If not, EndpointPath shows up.
When multiple paths are specified, we should display EndpointPath to get a whole path from the user.
So this is the right way to achieve the behavior at the moment. But when we implement this, we should reconsider this behavior. Just left a comment for the remind. 😄

Copy link
Contributor

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

Thanks a lot, @jrhee17!
You are the best. 👍

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks, @jrhee17 This is awesome work 👍👍

@jrhee17 jrhee17 force-pushed the feature/multiple-paths branch from 4663ab4 to 84bbda3 Compare October 23, 2019 01:04
@minwoox minwoox changed the title Support multiple @Path annotations Support multiple Path annotations Oct 23, 2019
@minwoox minwoox merged commit c760adf into line:master Oct 23, 2019
@minwoox minwoox added this to the 0.95.0 milestone Oct 23, 2019
@minwoox
Copy link
Contributor

minwoox commented Oct 23, 2019

Thanks a lot, @jrhee17! 🙇
Hope to see your next work. 😄

@jrhee17 jrhee17 deleted the feature/multiple-paths branch August 30, 2021 05:11
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.

5 participants