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 for Spring 6 HTTP interface #5370

Merged
merged 17 commits into from Mar 26, 2024
Merged

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Jan 5, 2024

Motivation:

The Spring Framework 6 supports defining declarative HTTP services using Java interfaces like Feign.
That could be an alternative choice for Spring users instead of Retrofit.

Modifications:

  • Add spring6 module to provide ArmeriaHttpExchangeAdapter.
  • ArmeriaClientHttpRequest and ArmeriaClientHttpRequest are moved to Spring 6 module from the WebFlux module.
    • The WebFlux module now depends on Spring 6 to share the files.
  • ClientRequest and ClientResponse in Spring 6 are used as a bridge to encode an object into HttpData and vice versa.

Result:

You can now create Spring 6 HTTP interface with Armeria WebClient.

import com.linecorp.armeria.client.WebClient;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

WebClient webClient = ...;
ArmeriaHttpExchangeAdapter adapter = ArmeriaHttpExchangeAdapter.of(webClient);
MyService service =
  HttpServiceProxyFactory.builderFor(adapter)
                         .build()
                         .createClient(MyService.class);

Copy link

codecov bot commented Jan 31, 2024

Codecov Report

Attention: Patch coverage is 81.20301% with 25 lines in your changes are missing coverage. Please review.

Project coverage is 74.04%. Comparing base (ccb29fe) to head (4692594).
Report is 2 commits behind head on main.

❗ Current head 4692594 differs from pull request most recent head 3d21a9f. Consider uploading reports for the commit 3d21a9f to get more accurate results

Files Patch % Lines
...eria/spring/client/ArmeriaHttpExchangeAdapter.java 76.47% 14 Missing and 6 partials ⚠️
...ring/client/ArmeriaHttpExchangeAdapterBuilder.java 76.92% 3 Missing ⚠️
.../armeria/spring/client/RequestAttributeAccess.java 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5370       +/-   ##
===========================================
+ Coverage        0   74.04%   +74.04%     
- Complexity      0    20839    +20839     
===========================================
  Files           0     1805     +1805     
  Lines           0    76697    +76697     
  Branches        0     9776     +9776     
===========================================
+ Hits            0    56794    +56794     
- Misses          0    15279    +15279     
- Partials        0     4624     +4624     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ikhoon ikhoon added this to the 1.28.0 milestone Jan 31, 2024
@ikhoon ikhoon marked this pull request as ready for review January 31, 2024 06:01
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.

Looks pretty good. 👍
Left some questions.

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.

Left a question but it looks really great! Thanks!

*
* GreetingService greetingService = ...
* // The request attribute will be set to the "X-Request-Id" header.
* greetingService.hello("123");
Copy link
Member

Choose a reason for hiding this comment

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

Question: So the decorator is not added to the client, the 123 will be ignored. Is that correct?
If so, is there any way to prevent this situation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. It's up to the user how to use the request attribute.
In Spring, the value of @RequestAttribute is propagated to Filter.
It is an optional feature for which additional validation may not be needed.

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.

Thanks! Changes look straightforward to me 👍 👍 👍

@minwoox minwoox merged commit aeda43f into line:main Mar 26, 2024
14 of 16 checks passed
@minwoox
Copy link
Member

minwoox commented Mar 26, 2024

Thanks a lot, @ikhoon!

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

3 participants