Search in sources :

Example 11 with GenericService

use of com.alibaba.dubbo.rpc.service.GenericService in project dubbo by alibaba.

the class ConfigTest method testGenericServiceConfig.

@Test
public void testGenericServiceConfig() throws Exception {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setApplication(new ApplicationConfig("test"));
    service.setRegistry(new RegistryConfig("mock://localhost"));
    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();
        Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
        MockRegistry registry = (MockRegistry) collection.iterator().next();
        URL url = registry.getRegistered().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        MockRegistryFactory.cleanCachedRegistry();
        service.unexport();
    }
}
Also used : GenericService(com.alibaba.dubbo.rpc.service.GenericService) MockRegistry(com.alibaba.dubbo.config.spring.registry.MockRegistry) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Registry(com.alibaba.dubbo.registry.Registry) MockRegistry(com.alibaba.dubbo.config.spring.registry.MockRegistry) GenericException(com.alibaba.dubbo.rpc.service.GenericException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 12 with GenericService

use of com.alibaba.dubbo.rpc.service.GenericService in project dubbo by alibaba.

the class EnumBak method testGenricEnumCompat.

// verify compatibility when 2.0.5 invokes 2.0.3
@Ignore
@Test
public void testGenricEnumCompat() {
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE);
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    GenericService demoProxy = (GenericService) proxy.getProxy(reference);
    Object obj = demoProxy.$invoke("enumlength", new String[] { Type[].class.getName() }, new Object[] { new Type[] { Type.High, Type.High } });
    System.out.println("obj---------->" + obj);
    reference.destroy();
}
Also used : GenericService(com.alibaba.dubbo.rpc.service.GenericService) URL(com.alibaba.dubbo.common.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with GenericService

use of com.alibaba.dubbo.rpc.service.GenericService in project tesla by linking12.

the class DynamicDubboClient method doRemoteCall.

@Override
public String doRemoteCall(final FilterRpcDO rpcDo, final String jsonInput) {
    try {
        final String serviceName = rpcDo.getServiceName();
        final String methodName = rpcDo.getMethodName();
        final String group = rpcDo.getServiceGroup();
        final String version = rpcDo.getServiceVersion();
        final String paramType = rpcDo.getInputParam();
        ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
        reference.setApplication(applicationConfig);
        reference.setRegistry(registryConfig);
        reference.setInterface(serviceName);
        reference.setGroup(group);
        reference.setGeneric(true);
        reference.setCheck(false);
        reference.setVersion(version);
        ReferenceConfigCache cache = ReferenceConfigCache.getCache();
        GenericService genericService = cache.get(reference);
        Pair<String[], Object[]> typeAndValue = paramTypeAndValue(paramType, jsonInput);
        Object response = genericService.$invoke(methodName, typeAndValue.getLeft(), typeAndValue.getRight());
        return JSON.toJSONString(response);
    } catch (Throwable e) {
        throw new IllegalArgumentException(String.format("service definition is wrong,please check the proto file you update,service is %s, method is %s", rpcDo.getServiceName(), rpcDo.getMethodName()), e);
    }
}
Also used : GenericService(com.alibaba.dubbo.rpc.service.GenericService) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) ReferenceConfigCache(com.alibaba.dubbo.config.utils.ReferenceConfigCache)

Aggregations

GenericService (com.alibaba.dubbo.rpc.service.GenericService)13 Test (org.junit.Test)11 DemoService (com.alibaba.dubbo.config.api.DemoService)5 GenericException (com.alibaba.dubbo.rpc.service.GenericException)5 ArrayList (java.util.ArrayList)5 URL (com.alibaba.dubbo.common.URL)4 User (com.alibaba.dubbo.config.api.User)4 DemoServiceImpl (com.alibaba.dubbo.config.provider.impl.DemoServiceImpl)3 HashMap (java.util.HashMap)3 List (java.util.List)3 JavaBeanDescriptor (com.alibaba.dubbo.common.beanutil.JavaBeanDescriptor)2 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)2 DemoService (com.alibaba.dubbo.config.spring.api.DemoService)2 Ignore (org.junit.Ignore)2 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)2 Serialization (com.alibaba.dubbo.common.serialize.Serialization)1 ApplicationConfig (com.alibaba.dubbo.config.ApplicationConfig)1 ProtocolConfig (com.alibaba.dubbo.config.ProtocolConfig)1 RegistryConfig (com.alibaba.dubbo.config.RegistryConfig)1 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)1