chickenlj closed pull request #1873: support proxy for provider side. #67
URL: https://github.com/apache/incubator-dubbo/pull/1873
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java
b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java
index 8637662d33..ec6dcd982c 100644
---
a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java
+++
b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java
@@ -500,6 +500,13 @@ private void doExportUrlsFor1Protocol(ProtocolConfig
protocolConfig, List<URL> r
if (logger.isInfoEnabled()) {
logger.info("Register dubbo service " +
interfaceClass.getName() + " url " + url + " to registry " + registryURL);
}
+
+ // For providers, this is used to enable custom proxy
to generate invoker
+ String proxy = url.getParameter(Constants.PROXY_KEY);
+ if (StringUtils.isNotEmpty(proxy)) {
+ registryURL =
registryURL.addParameter(Constants.PROXY_KEY, proxy);
+ }
+
Invoker<?> invoker = proxyFactory.getInvoker(ref,
(Class) interfaceClass,
registryURL.addParameterAndEncoded(Constants.EXPORT_KEY, url.toFullString()));
DelegateProviderMetaDataInvoker wrapperInvoker = new
DelegateProviderMetaDataInvoker(invoker, this);
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ServiceConfigTest.java
b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ServiceConfigTest.java
index d0eb6bc8d0..ed5a2e33d7 100644
---
a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ServiceConfigTest.java
+++
b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ServiceConfigTest.java
@@ -21,6 +21,7 @@
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.config.api.DemoService;
import com.alibaba.dubbo.config.api.Greeting;
+import com.alibaba.dubbo.config.mock.TestProxyFactory;
import com.alibaba.dubbo.config.provider.impl.DemoServiceImpl;
import com.alibaba.dubbo.config.mock.MockProtocol2;
import com.alibaba.dubbo.config.mock.MockRegistryFactory2;
@@ -45,6 +46,7 @@
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.withSettings;
@@ -53,6 +55,7 @@
private Registry registryDelegate = Mockito.mock(Registry.class);
private Exporter exporter = Mockito.mock(Exporter.class);
private ServiceConfig<DemoServiceImpl> service = new
ServiceConfig<DemoServiceImpl>();
+ private ServiceConfig<DemoServiceImpl> service2 = new
ServiceConfig<DemoServiceImpl>();
@Before
@@ -87,6 +90,14 @@ public void setUp() throws Exception {
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setMethods(Collections.singletonList(method));
+
+ service2.setProvider(provider);
+ service2.setApplication(app);
+ service2.setRegistry(registry);
+ service2.setInterface(DemoService.class);
+ service2.setRef(new DemoServiceImpl());
+ service2.setMethods(Collections.singletonList(method));
+ service2.setProxy("testproxyfactory");
}
@Test
@@ -112,6 +123,14 @@ public void testExport() throws Exception {
Mockito.verify(protocolDelegate).export(Mockito.any(Invoker.class));
}
+ @Test
+ public void testProxy() throws Exception {
+ service2.export();
+
+ assertThat(service2.getExportedUrls(), hasSize(1));
+ assertEquals(2, TestProxyFactory.count); // local injvm and registry
protocol, so expected is 2
+ }
+
@Test
@Ignore("cannot pass in travis")
public void testUnexport() throws Exception {
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/mock/TestProxyFactory.java
b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/mock/TestProxyFactory.java
new file mode 100644
index 0000000000..d70ecf7640
--- /dev/null
+++
b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/mock/TestProxyFactory.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.dubbo.config.mock;
+
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubbo.rpc.Invoker;
+import com.alibaba.dubbo.rpc.RpcException;
+import com.alibaba.dubbo.rpc.proxy.jdk.JdkProxyFactory;
+
+public class TestProxyFactory extends JdkProxyFactory {
+ public static int count = 0;
+
+ @Override
+ public <T> Invoker<T> getInvoker(T proxy, Class<T> type, URL url) throws
RpcException {
+ count++;
+ return super.getInvoker(proxy, type, url);
+ }
+}
diff --git
a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.rpc.ProxyFactory
b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.rpc.ProxyFactory
index 0ae5c21f89..d1af147787 100644
---
a/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.rpc.ProxyFactory
+++
b/dubbo-config/dubbo-config-api/src/test/resources/META-INF/services/com.alibaba.dubbo.rpc.ProxyFactory
@@ -1 +1,2 @@
-mockproxyfactory=com.alibaba.dubbo.config.mock.MockProxyFactory
\ No newline at end of file
+mockproxyfactory=com.alibaba.dubbo.config.mock.MockProxyFactory
+testproxyfactory=com.alibaba.dubbo.config.mock.TestProxyFactory
\ No newline at end of file
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]