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

Feature/dubbo32. resteasy filter&intercept support #12492

Conversation

suncairong163
Copy link
Contributor

What is the purpose of the change

add resteasy filter&intercept support

Brief changelog

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

@suncairong163
Copy link
Contributor Author

@AlbumenJ @CrazyHZM

@chickenlj
Copy link
Contributor

Please add the newly added SPI extension to shade configuration in dubbo-all/pom.xml and fix the conflicts.

2023-06-11T15:10:59.4344411Z [ERROR] Failures: 
2023-06-11T15:10:59.4346957Z [ERROR]   FileTest.checkDubboAllTransform:379 Newly created SPI interface must be added to dubbo-all(dubbo-distribution/dubbo-all/pom.xml in shade plugin) to being transformed. Found spis: [org.apache.dubbo.rpc.protocol.rest.filter.RestFilter, org.apache.dubbo.rpc.protocol.rest.filter.RestResponseInterceptor] ==> expected: <true> but was: <false>

suncairong163 and others added 4 commits June 13, 2023 00:52
…to feature/dubbo32._resteasy_filter&intercept_support

# Conflicts:
#	dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/handler/NettyHttpHandler.java
#	dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/JaxrsRestProtocolTest.java
@@ -58,7 +62,7 @@ protected void decode(ChannelHandlerContext ctx, io.netty.handler.codec.http.Ful

// business handler
try {
handler.handle(requestFacade, nettyHttpResponse);
new NettyHttpHandler(serviceDeployer, url).handle(requestFacade, nettyHttpResponse);
Copy link
Member

Choose a reason for hiding this comment

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

This can result in constant creation of NettyHttpHandler instances

Comment on lines 79 to 85
new RestFilter() {
@Override
public void filter(URL url, RequestFacade requestFacade, NettyHttpResponse response, RestFilterChain restFilterChain) throws Exception {

restFilterChain.filter(url, requestFacade, response, restFilterChain);
}
}.filter(url, requestFacade, nettyHttpResponse, new RestFilterChain(restFilters));
Copy link
Member

Choose a reason for hiding this comment

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

This looks like RestFilterChain is fixed, because restFilters are fixed, I think the RestFilterChain here is not unnecessary, looking at the RestFilterChain logic, should just iterate through the execution of these restfilter. I don't see much logic at the moment.

Comment on lines 33 to 41
public class ServiceInvokeRestResponseInterceptor implements RestResponseInterceptor {

@Override
public void intercept(URL url, RequestFacade request, NettyHttpResponse nettyHttpResponse, Object result, RpcInvocation rpcInvocation, RestResponseInterceptorChain interceptorChain, ServiceDeployer serviceDeployer) throws Exception {

writeResult(nettyHttpResponse, request, url, result, rpcInvocation.getReturnType());
nettyHttpResponse.setStatus(200);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This does not need to exist and may skew other non-200 results.

…intercept_support' into feature/dubbo32._resteasy_filter&intercept_support

# Conflicts:
#	dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java
@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2023

Codecov Report

Merging #12492 (1625bd5) into 3.2 (d4856e2) will increase coverage by 0.62%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##                3.2   #12492       +/-   ##
=============================================
+ Coverage     68.73%   69.35%    +0.62%     
+ Complexity      341        2      -339     
=============================================
  Files          3619     1647     -1972     
  Lines        169138    68122   -101016     
  Branches      28109     9961    -18148     
=============================================
- Hits         116249    47248    -69001     
+ Misses        42799    16320    -26479     
+ Partials      10090     4554     -5536     

see 2047 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@suncairong163
Copy link
Contributor Author

@CrazyHZM change request & response filter


@Override
public void proceed() throws IOException, WebApplicationException {
LogMessages.LOGGER.debugf("Interceptor Context: %s, Method : proceed", getClass().getName());
Copy link
Member

Choose a reason for hiding this comment

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

Replace with dubbo's own logger.

Copy link
Member

Choose a reason for hiding this comment

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

import java.util.ArrayList;
import java.util.List;

public class RestFilterManager {
Copy link
Member

Choose a reason for hiding this comment

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

Each method should go back to where it was originally used and static classes are not a very good approach.
For example, executeRequestFilters and executeResponseFilters should revert to NettyHttpHandler, and restRequestFilters should be fetched from the FrameworkModel in the context. Such as the url FrameworkModel.

@suncairong163
Copy link
Contributor Author

@CrazyHZM fix some change request

@sonarcloud
Copy link

sonarcloud bot commented Jul 12, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 79 Code Smells

63.2% 63.2% Coverage
2.8% 2.8% Duplication

@CrazyHZM CrazyHZM merged commit d452ea4 into apache:3.2 Jul 12, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants