Skip to content

Commit

Permalink
Fixes apache#9913, rmi protocol supoort group and version
Browse files Browse the repository at this point in the history
  • Loading branch information
xielongfei committed Apr 21, 2022
1 parent 3a8e5e6 commit fb0a0af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Expand Up @@ -35,6 +35,8 @@
import static org.apache.dubbo.common.Version.isRelease270OrHigher;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;

/**
Expand Down Expand Up @@ -102,7 +104,10 @@ protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcExc
return invocation;
});
}
String serviceUrl = url.toIdentityString();

String pathKey = URL.buildKey(url.getPath(), url.getParameter(GROUP_KEY), url.getParameter(VERSION_KEY));
//The format is 'rmi://{host}:{ip}/{group}/{interfaceName}:{version}'
String serviceUrl = "rmi://" + url.getHost() + ":" + url.getPort() + "/" + pathKey;
if (isGeneric) {
serviceUrl = serviceUrl + "/" + GENERIC_KEY;
}
Expand Down Expand Up @@ -137,9 +142,9 @@ private <T> RmiServiceExporter createExporter(T impl, Class<?> type, URL url, bo
final RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
rmiServiceExporter.setRegistryPort(url.getPort());
if (isGeneric) {
rmiServiceExporter.setServiceName(url.getPath() + "/" + GENERIC_KEY);
rmiServiceExporter.setServiceName(url.getServiceKey() + "/" + GENERIC_KEY);
} else {
rmiServiceExporter.setServiceName(url.getPath());
rmiServiceExporter.setServiceName(url.getServiceKey());
}
rmiServiceExporter.setServiceInterface(type);
rmiServiceExporter.setService(impl);
Expand Down
Expand Up @@ -155,6 +155,30 @@ public void testRemoteApplicationName() throws Exception {

}

@Test
public void testRmiProtocalGroupAndVersion() throws Exception {
int port = NetUtils.getAvailablePort();
RemoteService remoteService = new RemoteServiceImpl();
RemoteService remoteService2 = new RemoteService2Impl();

URL url = URL.valueOf("rmi://127.0.0.1:" + port + "/" + DemoService.class.getName() + "?version=v1&group=g1");
URL url2 = URL.valueOf("rmi://127.0.0.1:" + port + "/" + DemoService.class.getName() + "?version=v2&group=g2");
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, url));
Exporter<?> rpcExporter2 = protocol.export(proxy.getInvoker(remoteService2, RemoteService.class, url2));

remoteService = proxy.getProxy(protocol.refer(RemoteService.class, url));
remoteService2 = proxy.getProxy(protocol.refer(RemoteService.class, url2));
for (int i = 0; i < 1; i++) {
String say = remoteService.sayHello("abcd");
assertEquals("hello abcd@" + RemoteServiceImpl.class.getName(), say);
String say2 = remoteService2.sayHello("group");
assertEquals("hello group@" + RemoteService2Impl.class.getName(), say2);
}
rpcExporter.unexport();
rpcExporter2.unexport();

}

public interface NonStdRmiInterface {
void bark();
}
Expand Down

0 comments on commit fb0a0af

Please sign in to comment.