From 3dccbc6f5b53bf666ede8a2c7afe1efe93e0922e Mon Sep 17 00:00:00 2001 From: kimi Date: Tue, 8 Jan 2013 13:56:08 +0800 Subject: [PATCH] =?UTF-8?q?DUBBO-627=20ServiceConfig=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20generic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/dubbo/config/ServiceConfig.java | 26 +++++++++++++++---- .../src/main/resources/META-INF/dubbo.xsd | 5 ++++ .../dubbo/config/spring/ConfigTest.java | 23 ++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) 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 77486f4c8cf..2d420fdd60d 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 @@ -46,6 +46,7 @@ import com.alibaba.dubbo.rpc.ProxyFactory; import com.alibaba.dubbo.rpc.cluster.ConfiguratorFactory; import com.alibaba.dubbo.rpc.service.GenericService; +import com.alibaba.dubbo.rpc.support.ProtocolUtils; /** * ServiceConfig @@ -87,7 +88,7 @@ public class ServiceConfig extends AbstractServiceConfig { private transient volatile boolean unexported; - private transient volatile boolean generic; + private volatile String generic; public ServiceConfig() { } @@ -191,7 +192,9 @@ protected synchronized void doExport() { } if (ref instanceof GenericService) { interfaceClass = GenericService.class; - generic = true; + if (StringUtils.isEmpty(generic)) { + generic = Boolean.TRUE.toString(); + } } else { try { interfaceClass = Class.forName(interfaceName, true, Thread.currentThread() @@ -201,7 +204,7 @@ protected synchronized void doExport() { } checkInterfaceAndMethods(interfaceClass, methods); checkRef(); - generic = false; + generic = Boolean.FALSE.toString(); } if(local !=null){ if(local=="true"){ @@ -414,8 +417,8 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List r } // end of methods for } - if (generic) { - map.put("generic", String.valueOf(true)); + if (ProtocolUtils.isGeneric(generic)) { + map.put("generic", generic); map.put("methods", Constants.ANY_VALUE); } else { String revision = Version.getVersion(interfaceClass, version); @@ -612,6 +615,19 @@ public ProviderConfig getProvider() { return provider; } + public void setGeneric(String generic) { + if (StringUtils.isEmpty(generic)) { return; } + if (ProtocolUtils.isGeneric(generic)) { + this.generic = generic; + } else { + throw new IllegalArgumentException("Unsupported generic type " + generic); + } + } + + public String getGeneric() { + return generic; + } + public void setProvider(ProviderConfig provider) { this.provider = provider; } diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd index 633046bd5d5..94809fd480f 100644 --- a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/dubbo.xsd @@ -1051,6 +1051,11 @@ + + + + + diff --git a/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/ConfigTest.java index 18110a15a17..a5dfa1bc178 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/ConfigTest.java @@ -30,6 +30,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.support.ClassPathXmlApplicationContext; +import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.common.extension.ExtensionLoader; import com.alibaba.dubbo.common.utils.NetUtils; @@ -939,6 +940,28 @@ public void testReferGenericExport() throws Exception { } } + @Test + public void testGenericServiceConfig() throws Exception { + ServiceConfig service = new ServiceConfig(); + service.setApplication(new ApplicationConfig("test")); + service.setRegistry(new RegistryConfig("N/A")); + service.setInterface(DemoService.class.getName()); + service.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN); + service.setRef(new GenericService(){ + + public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { + return null; + } + }); + try { + service.export(); + URL url = service.getExportedUrls().get(0); + Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY)); + } finally { + service.unexport(); + } + } + private static void unexportService(ServiceConfig config) { if (config != null) { config.unexport();