This is an automated email from the ASF dual-hosted git repository.
crazyhzm pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new 6b617a1ce9 Feature/dubbo 3.2 rest fix http method pathmatcher (#12890)
6b617a1ce9 is described below
commit 6b617a1ce99552545ebe087fd993f24a224f0c8b
Author: suncairong163 <[email protected]>
AuthorDate: Thu Aug 17 16:56:51 2023 +0800
Feature/dubbo 3.2 rest fix http method pathmatcher (#12890)
* fix rest service deployer serializable error
* fix rest http method judge
---
.../dubbo/common/constants/CommonConstants.java | 1 -
.../apache/dubbo/metadata/rest/PathMatcher.java | 12 +++--
.../apache/dubbo/rpc/protocol/rest/Constants.java | 6 ---
.../rpc/protocol/rest/PathAndInvokerMapper.java | 56 +++++++++++++++++++++-
.../rpc/protocol/rest/RestRPCInvocationUtil.java | 25 ++++------
.../rpc/protocol/rest/deploy/ServiceDeployer.java | 11 +++++
.../rest/filter/ServiceInvokeRestFilter.java | 21 ++++----
.../protocol/rest/handler/NettyHttpHandler.java | 4 --
.../rest/netty/RestHttpRequestDecoder.java | 2 +-
.../protocol/rest/request/NettyRequestFacade.java | 7 +++
.../rpc/protocol/rest/request/RequestFacade.java | 11 ++++-
.../rest/rest/TestGetInvokerServiceImpl.java | 5 +-
12 files changed, 115 insertions(+), 46 deletions(-)
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index c303c3c3ab..09f7d146c7 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -643,7 +643,6 @@ public interface CommonConstants {
String DUBBO_PACKABLE_METHOD_FACTORY = "dubbo.application.parameters." +
PACKABLE_METHOD_FACTORY_KEY;
- String SERVICE_DEPLOYER_ATTRIBUTE_KEY = "serviceDeployer";
String RESTEASY_NETTY_HTTP_REQUEST_ATTRIBUTE_KEY =
"resteasyNettyHttpRequest";
String DUBBO_MANUAL_REGISTER_KEY = "dubbo.application.manual-register";
diff --git
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/PathMatcher.java
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/PathMatcher.java
index 7abefcf71e..e08e0733b2 100644
---
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/PathMatcher.java
+++
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/PathMatcher.java
@@ -110,13 +110,17 @@ public class PathMatcher {
}
public static PathMatcher getInvokeCreatePathMatcher(String path, String
version, String group, Integer port, String method) {
- return new PathMatcher(path, version, group, port,
method).noNeedHttpMethodCompare();
+ return new PathMatcher(path, version, group, port,
method).compareHttpMethod(false);
}
public static PathMatcher getInvokeCreatePathMatcher(Method serviceMethod)
{
return new
PathMatcher(serviceMethod).setNeedCompareServiceMethod(true);
}
+ public static PathMatcher convertPathMatcher(PathMatcher pathMatcher) {
+ return getInvokeCreatePathMatcher(pathMatcher.path,
pathMatcher.version, pathMatcher.group, pathMatcher.port,
pathMatcher.httpMethod);
+ }
+
public boolean hasPathVariable() {
return hasPathVariable;
}
@@ -134,8 +138,8 @@ public class PathMatcher {
return this;
}
- private PathMatcher noNeedHttpMethodCompare() {
- this.needCompareHttpMethod = false;
+ public PathMatcher compareHttpMethod(boolean needCompareHttpMethod) {
+ this.needCompareHttpMethod = needCompareHttpMethod;
return this;
}
@@ -176,7 +180,7 @@ public class PathMatcher {
* @return
*/
private boolean httpMethodMatch(PathMatcher that) {
- return !that.needCompareHttpMethod || !this.needCompareHttpMethod ?
true: Objects.equals(this.httpMethod, that.httpMethod);
+ return !that.needCompareHttpMethod || !this.needCompareHttpMethod ?
true : Objects.equals(this.httpMethod, that.httpMethod);
}
private boolean serviceMethodEqual(PathMatcher thatPathMatcher,
PathMatcher thisPathMatcher) {
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/Constants.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/Constants.java
index c2918062f4..c7d49dd316 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/Constants.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/Constants.java
@@ -31,10 +31,4 @@ public interface Constants {
String NETTY_HTTP = "netty_http";
- // exception mapper
- String EXCEPTION_MAPPER_KEY = "exception.mapper";
-
-
-
-
}
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/PathAndInvokerMapper.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/PathAndInvokerMapper.java
index d04b652958..c9fea955ec 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/PathAndInvokerMapper.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/PathAndInvokerMapper.java
@@ -24,7 +24,10 @@ import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.protocol.rest.exception.DoublePathCheckException;
import
org.apache.dubbo.rpc.protocol.rest.pair.InvokerAndRestMethodMetadataPair;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -36,6 +39,8 @@ public class PathAndInvokerMapper {
private final Map<PathMatcher, InvokerAndRestMethodMetadataPair>
pathToServiceMapContainPathVariable = new ConcurrentHashMap<>();
private final Map<PathMatcher, InvokerAndRestMethodMetadataPair>
pathToServiceMapNoPathVariable = new ConcurrentHashMap<>();
+ // for http method compare 405
+ private final Map<PathMatcher, Set<String>> pathMatcherToHttpMethodMap =
new HashMap<>();
/**
* deploy path metadata
@@ -105,7 +110,7 @@ public class PathAndInvokerMapper {
InvokerAndRestMethodMetadataPair beforeMetadata =
pathMatcherPairMap.get(pathMatcher);
// true when reExport
- if
(!invokerRestMethodMetadataPair.compareServiceMethod(beforeMetadata)){
+ if
(!invokerRestMethodMetadataPair.compareServiceMethod(beforeMetadata)) {
throw new DoublePathCheckException(
"dubbo rest double path check error, current path is: " +
pathMatcher
+ " ,and service method is: " +
invokerRestMethodMetadataPair.getRestMethodMetadata().getReflectMethod()
@@ -116,8 +121,57 @@ public class PathAndInvokerMapper {
pathMatcherPairMap.put(pathMatcher, invokerRestMethodMetadataPair);
+ addPathMatcherToHttpMethodsMap(pathMatcher);
+
logger.info("dubbo rest deploy pathMatcher:" + pathMatcher + ", and
service method is :" +
invokerRestMethodMetadataPair.getRestMethodMetadata().getReflectMethod());
}
+ private void addPathMatcherToHttpMethodsMap(PathMatcher pathMatcher) {
+
+ PathMatcher newPathMatcher =
PathMatcher.convertPathMatcher(pathMatcher);
+
+ if (!pathMatcherToHttpMethodMap.containsKey(newPathMatcher)) {
+ HashSet<String> httpMethods = new HashSet<>();
+
+ httpMethods.add(pathMatcher.getHttpMethod());
+
+ pathMatcherToHttpMethodMap.put(newPathMatcher, httpMethods);
+
+ }
+
+ Set<String> httpMethods =
pathMatcherToHttpMethodMap.get(newPathMatcher);
+
+ httpMethods.add(newPathMatcher.getHttpMethod());
+
+ }
+
+ public boolean isHttpMethodAllowed(PathMatcher pathMatcher) {
+
+ PathMatcher newPathMatcher =
PathMatcher.convertPathMatcher(pathMatcher);
+ if (!pathMatcherToHttpMethodMap.containsKey(newPathMatcher)) {
+ return false;
+ }
+
+
+ Set<String> httpMethods =
pathMatcherToHttpMethodMap.get(newPathMatcher);
+
+ return httpMethods.contains(newPathMatcher.getHttpMethod());
+
+ }
+
+ public String pathHttpMethods(PathMatcher pathMatcher) {
+
+ PathMatcher newPathMatcher =
PathMatcher.convertPathMatcher(pathMatcher);
+ if (!pathMatcherToHttpMethodMap.containsKey(newPathMatcher)) {
+ return null;
+ }
+
+
+ Set<String> httpMethods =
pathMatcherToHttpMethodMap.get(newPathMatcher);
+
+ return httpMethods.toString();
+
+ }
+
}
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestRPCInvocationUtil.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestRPCInvocationUtil.java
index c299c893dc..d125ff3052 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestRPCInvocationUtil.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestRPCInvocationUtil.java
@@ -23,7 +23,6 @@ import org.apache.dubbo.metadata.rest.ArgInfo;
import org.apache.dubbo.metadata.rest.PathMatcher;
import org.apache.dubbo.metadata.rest.RestMethodMetadata;
import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.protocol.rest.annotation.ParamParserManager;
import
org.apache.dubbo.rpc.protocol.rest.annotation.param.parse.provider.ProviderParseContext;
@@ -38,9 +37,6 @@ import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
-import static
org.apache.dubbo.common.constants.CommonConstants.SERVICE_DEPLOYER_ATTRIBUTE_KEY;
-
-
public class RestRPCInvocationUtil {
private static final ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(RestRPCInvocationUtil.class);
@@ -136,13 +132,8 @@ public class RestRPCInvocationUtil {
* @param pathMatcher
* @return
*/
- public static InvokerAndRestMethodMetadataPair
getRestMethodMetadataAndInvokerPair(PathMatcher pathMatcher) {
-
- ServiceDeployer serviceDeployer = (ServiceDeployer)
RpcContext.getServiceContext().getObjectAttachment(SERVICE_DEPLOYER_ATTRIBUTE_KEY);
+ public static InvokerAndRestMethodMetadataPair
getRestMethodMetadataAndInvokerPair(PathMatcher pathMatcher, ServiceDeployer
serviceDeployer) {
- if (serviceDeployer == null) {
- return null;
- }
return
serviceDeployer.getPathAndInvokerMapper().getRestMethodMetadata(pathMatcher);
}
@@ -158,7 +149,7 @@ public class RestRPCInvocationUtil {
PathMatcher pathMather = createPathMatcher(request);
- return getRestMethodMetadataAndInvokerPair(pathMather);
+ return getRestMethodMetadataAndInvokerPair(pathMather,
request.getServiceDeployer());
}
@@ -173,20 +164,20 @@ public class RestRPCInvocationUtil {
PathMatcher pathMatcher = createPathMatcher(request);
- return getInvoker(pathMatcher);
+ return getInvoker(pathMatcher, request.getServiceDeployer());
}
/**
* get invoker by service method
- *
+ * <p>
* compare method`s name,param types
*
* @param serviceMethod
* @return
*/
- public static Invoker getInvokerByServiceInvokeMethod(Method
serviceMethod) {
+ public static Invoker getInvokerByServiceInvokeMethod(Method
serviceMethod, ServiceDeployer serviceDeployer) {
if (serviceMethod == null) {
return null;
@@ -194,7 +185,7 @@ public class RestRPCInvocationUtil {
PathMatcher pathMatcher =
PathMatcher.getInvokeCreatePathMatcher(serviceMethod);
- InvokerAndRestMethodMetadataPair pair =
getRestMethodMetadataAndInvokerPair(pathMatcher);
+ InvokerAndRestMethodMetadataPair pair =
getRestMethodMetadataAndInvokerPair(pathMatcher, serviceDeployer);
if (pair == null) {
return null;
@@ -209,8 +200,8 @@ public class RestRPCInvocationUtil {
* @param pathMatcher
* @return
*/
- public static Invoker getInvoker(PathMatcher pathMatcher) {
- InvokerAndRestMethodMetadataPair pair =
getRestMethodMetadataAndInvokerPair(pathMatcher);
+ public static Invoker getInvoker(PathMatcher pathMatcher, ServiceDeployer
serviceDeployer) {
+ InvokerAndRestMethodMetadataPair pair =
getRestMethodMetadataAndInvokerPair(pathMatcher, serviceDeployer);
if (pair == null) {
return null;
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/deploy/ServiceDeployer.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/deploy/ServiceDeployer.java
index 0c75ba5bfb..1830dc2e86 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/deploy/ServiceDeployer.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/deploy/ServiceDeployer.java
@@ -144,4 +144,15 @@ public class ServiceDeployer {
}
+ public boolean isMethodAllowed(PathMatcher pathMatcher) {
+ return pathAndInvokerMapper.isHttpMethodAllowed(pathMatcher);
+ }
+
+ public boolean hashRestMethod(PathMatcher pathMatcher) {
+ return pathAndInvokerMapper.getRestMethodMetadata(pathMatcher) != null;
+ }
+
+ public String pathHttpMethods(PathMatcher pathMatcher) {
+ return pathAndInvokerMapper.pathHttpMethods(pathMatcher);
+ }
}
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/filter/ServiceInvokeRestFilter.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/filter/ServiceInvokeRestFilter.java
index 2704db0781..404f8edd5a 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/filter/ServiceInvokeRestFilter.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/filter/ServiceInvokeRestFilter.java
@@ -22,6 +22,7 @@ import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.metadata.rest.PathMatcher;
import org.apache.dubbo.metadata.rest.RestMethodMetadata;
import org.apache.dubbo.metadata.rest.media.MediaType;
import org.apache.dubbo.rpc.Invoker;
@@ -72,26 +73,28 @@ public class ServiceInvokeRestFilter implements
RestRequestFilter {
RequestFacade request,
URL url,
ServiceDeployer serviceDeployer) throws Exception {
- // acquire metadata by request
- InvokerAndRestMethodMetadataPair restMethodMetadataPair =
RestRPCInvocationUtil.getRestMethodMetadataAndInvokerPair(request);
+ PathMatcher pathMatcher =
RestRPCInvocationUtil.createPathMatcher(request);
// path NoFound 404
- if (restMethodMetadataPair == null) {
- throw new PathNoFoundException("rest service Path no found,
current path info:" + RestRPCInvocationUtil.createPathMatcher(request));
+ if (!serviceDeployer.hashRestMethod(pathMatcher)) {
+ throw new PathNoFoundException("rest service Path no found,
current path info:" + pathMatcher);
}
- Invoker invoker = restMethodMetadataPair.getInvoker();
-
- RestMethodMetadata restMethodMetadata =
restMethodMetadataPair.getRestMethodMetadata();
// method disallowed
- if
(!restMethodMetadata.getRequest().methodAllowed(request.getMethod())) {
+ if (!serviceDeployer.isMethodAllowed(pathMatcher)) {
nettyHttpResponse.sendError(405, "service require request method
is : "
- + restMethodMetadata.getRequest().getMethod()
+ + serviceDeployer.pathHttpMethods(pathMatcher)
+ ", but current request method is: " + request.getMethod()
);
return;
}
+ // compare http method and acquire metadata by request
+ InvokerAndRestMethodMetadataPair restMethodMetadataPair =
RestRPCInvocationUtil.getRestMethodMetadataAndInvokerPair(pathMatcher.compareHttpMethod(true),
serviceDeployer);
+
+ Invoker invoker = restMethodMetadataPair.getInvoker();
+
+ RestMethodMetadata restMethodMetadata =
restMethodMetadataPair.getRestMethodMetadata();
// content-type support judge,throw unSupportException
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/handler/NettyHttpHandler.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/handler/NettyHttpHandler.java
index db4f2d21f1..eb18564f3d 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/handler/NettyHttpHandler.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/handler/NettyHttpHandler.java
@@ -38,8 +38,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import static
org.apache.dubbo.common.constants.CommonConstants.SERVICE_DEPLOYER_ATTRIBUTE_KEY;
-
/**
* netty http request handler
@@ -77,8 +75,6 @@ public class NettyHttpHandler implements
HttpHandler<NettyRequestFacade, NettyHt
Object nettyHttpRequest = requestFacade.getRequest();
-
RpcContext.getServiceContext().setObjectAttachment(SERVICE_DEPLOYER_ATTRIBUTE_KEY,
serviceDeployer);
-
try {
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/netty/RestHttpRequestDecoder.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/netty/RestHttpRequestDecoder.java
index 041a957cdd..7a1aa1bad3 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/netty/RestHttpRequestDecoder.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/netty/RestHttpRequestDecoder.java
@@ -61,7 +61,7 @@ public class RestHttpRequestDecoder extends
MessageToMessageDecoder<io.netty.han
boolean keepAlive = HttpHeaders.isKeepAlive(request);
NettyHttpResponse nettyHttpResponse = new NettyHttpResponse(ctx,
keepAlive);
- NettyRequestFacade requestFacade = new NettyRequestFacade(request,
ctx);
+ NettyRequestFacade requestFacade = new NettyRequestFacade(request,
ctx,serviceDeployer);
executor.execute(() -> {
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/request/NettyRequestFacade.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/request/NettyRequestFacade.java
index 3c24717048..006b404766 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/request/NettyRequestFacade.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/request/NettyRequestFacade.java
@@ -23,6 +23,7 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpContent;
import org.apache.dubbo.common.utils.IOUtils;
+import org.apache.dubbo.rpc.protocol.rest.deploy.ServiceDeployer;
import java.io.IOException;
import java.util.ArrayList;
@@ -48,6 +49,12 @@ public class NettyRequestFacade extends
RequestFacade<FullHttpRequest> {
}
+ public NettyRequestFacade(Object request, ChannelHandlerContext context,
ServiceDeployer serviceDeployer) {
+ super((FullHttpRequest) request, serviceDeployer);
+ this.context = context;
+
+ }
+
protected void initHeaders() {
for (Map.Entry<String, String> header : request.headers()) {
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/request/RequestFacade.java
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/request/RequestFacade.java
index 8d95ac60cb..ab0dcbf484 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/request/RequestFacade.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/request/RequestFacade.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.protocol.rest.request;
import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.protocol.rest.deploy.ServiceDeployer;
import java.io.IOException;
import java.util.ArrayList;
@@ -37,6 +38,7 @@ public abstract class RequestFacade<T> {
protected String path;
protected T request;
protected byte[] body = new byte[0];
+ protected ServiceDeployer serviceDeployer;
public RequestFacade(T request) {
this.request = request;
@@ -45,6 +47,11 @@ public abstract class RequestFacade<T> {
parseBody();
}
+ public RequestFacade(T request, ServiceDeployer serviceDeployer) {
+ this(request);
+ this.serviceDeployer = serviceDeployer;
+ }
+
protected void initHeaders() {
}
@@ -131,5 +138,7 @@ public abstract class RequestFacade<T> {
protected abstract void parseBody();
-
+ public ServiceDeployer getServiceDeployer() {
+ return serviceDeployer;
+ }
}
diff --git
a/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/rest/TestGetInvokerServiceImpl.java
b/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/rest/TestGetInvokerServiceImpl.java
index b61f4afdfa..ed66a1e3f8 100644
---
a/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/rest/TestGetInvokerServiceImpl.java
+++
b/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/rest/TestGetInvokerServiceImpl.java
@@ -31,6 +31,7 @@ public class TestGetInvokerServiceImpl implements
TestGetInvokerService {
@Override
public String getInvoker() {
Object request = RpcContext.getServiceContext().getRequest();
+ RequestFacade requestFacade = (RequestFacade) request;
Invoker invokerByRequest =
RestRPCInvocationUtil.getInvokerByRequest((RequestFacade) request);
@@ -44,9 +45,9 @@ public class TestGetInvokerServiceImpl implements
TestGetInvokerService {
}
- Invoker invokerByServiceInvokeMethod =
RestRPCInvocationUtil.getInvokerByServiceInvokeMethod(hello);
+ Invoker invokerByServiceInvokeMethod =
RestRPCInvocationUtil.getInvokerByServiceInvokeMethod(hello,requestFacade.getServiceDeployer());
- Invoker invoker =
RestRPCInvocationUtil.getInvokerByServiceInvokeMethod(hashcode);
+ Invoker invoker =
RestRPCInvocationUtil.getInvokerByServiceInvokeMethod(hashcode,requestFacade.getServiceDeployer());
Assertions.assertEquals(invokerByRequest,
invokerByServiceInvokeMethod);