com.alibaba.dubbo.rpc.service.GenericService Java Examples

The following examples show how to use com.alibaba.dubbo.rpc.service.GenericService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnumBak.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public void testGenricCustomArg(){
    
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");
    
    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->"+obj);
    reference.destroy();
}
 
Example #2
Source File: EnumBak.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericEnum() throws InterruptedException {
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE
    );
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);

    URL consumerurl = serviceurl;

    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);

    invoker.destroy();
    reference.destroy();
}
 
Example #3
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #4
Source File: HttpProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericInvokeWithBean() {
    HttpServiceImpl server = new HttpServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("http://127.0.0.1:5342/" + HttpService.class.getName() + "?version=1.0.0&generic=bean");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);

    JavaBeanDescriptor javaBeanDescriptor = JavaBeanSerializeUtil.serialize("haha");

    Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{javaBeanDescriptor});
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) result));
    invoker.destroy();
    exporter.unexport();
}
 
Example #5
Source File: HttpProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericInvokeWithNativeJava() throws IOException, ClassNotFoundException {
    HttpServiceImpl server = new HttpServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("http://127.0.0.1:5342/" + HttpService.class.getName() + "?version=1.0.0&generic=nativejava");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);

    Serialization serialization = new NativeJavaSerialization();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject("haha");
    objectOutput.flushBuffer();

    Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{byteArrayOutputStream.toByteArray()});
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream((byte[]) result);
    ObjectInput objectInput = serialization.deserialize(url, byteArrayInputStream);
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", objectInput.readObject());
    invoker.destroy();
    exporter.unexport();
}
 
Example #6
Source File: HessianProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericInvokeWithNativeJava() throws IOException, ClassNotFoundException {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&generic=nativejava");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);

    Serialization serialization = new NativeJavaSerialization();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject("haha");
    objectOutput.flushBuffer();

    Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{byteArrayOutputStream.toByteArray()});
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream((byte[]) result);
    ObjectInput objectInput = serialization.deserialize(url, byteArrayInputStream);
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", objectInput.readObject());
    invoker.destroy();
    exporter.unexport();
}
 
Example #7
Source File: HttpProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericInvoke() {
    HttpServiceImpl server = new HttpServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("http://127.0.0.1:5342/" + HttpService.class.getName() + "?version=1.0.0");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    String result = (String) client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{"haha"});
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
 
Example #8
Source File: HttpProtocol.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = getAddr(url);
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, createExporter(impl, type));

    final String genericPath = path + "/" + Constants.GENERIC_KEY;

    skeletonMap.put(genericPath, createExporter(impl, GenericService.class));
    return new Runnable() {
        @Override
        public void run() {
            skeletonMap.remove(path);
            skeletonMap.remove(genericPath);
        }
    };
}
 
Example #9
Source File: HessianProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericInvokeWithRpcContext() {
    RpcContext.getContext().setAttachment("myContext", "123");

    HessianServiceImpl server = new HessianServiceImpl();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    String result = (String) client.$invoke("context", new String[]{"java.lang.String"}, new Object[]{"haha"});
    Assert.assertEquals("Hello, haha context, 123", result);
    invoker.destroy();
    exporter.unexport();
}
 
Example #10
Source File: HessianProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericInvokeWithBean() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&generic=bean");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);

    JavaBeanDescriptor javaBeanDescriptor = JavaBeanSerializeUtil.serialize("haha");

    Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{javaBeanDescriptor});
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) result));
    invoker.destroy();
    exporter.unexport();
}
 
Example #11
Source File: EnumBak.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void testGenricCustomArg(){
    
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");
    
    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->"+obj);
    reference.destroy();
}
 
Example #12
Source File: EnumBak.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testGenricCustomArg() {

    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);

    GenericService demoProxy = (GenericService) proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");

    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->" + obj);
    reference.destroy();
}
 
Example #13
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #14
Source File: EnumBak.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericEnum() throws InterruptedException{
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
            );
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);
    
    URL consumerurl = serviceurl;
    
    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);
    
    invoker.destroy();
    reference.destroy();
}
 
Example #15
Source File: DubboSinkFunction.java    From alchemy with Apache License 2.0 6 votes vote down vote up
private ReferenceConfig<GenericService> referenceConfig(DubboProperties properties) throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName(properties.getApplicationName());
    ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
    reference.setApplication(application);
    reference.setRegistry(new RegistryConfig(properties.getRegistryAddr()));
    reference.setInterface(properties.getInterfaceName());
    reference.setVersion(properties.getVersion());
    reference.setGeneric(true);
    reference.setCheck(false);
    reference.setInit(true);
    if(properties.getProperties() != null){
        BeanUtils.copyProperties(reference, properties.getProperties());
    }
    return reference;
}
 
Example #16
Source File: EnumBak.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericEnum() throws InterruptedException{
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
            );
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);
    
    URL consumerurl = serviceurl;
    
    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);
    
    invoker.destroy();
    reference.destroy();
}
 
Example #17
Source File: AlibabaDubboProxyService.java    From soul with Apache License 2.0 6 votes vote down vote up
/**
 * Generic invoker object.
 *
 * @param body     the body
 * @param metaData the meta data
 * @return the object
 * @throws SoulException the soul exception
 */
public Object genericInvoker(final String body, final MetaData metaData) throws SoulException {
    ReferenceConfig<GenericService> reference = ApplicationConfigCache.getInstance().get(metaData.getServiceName());
    if (Objects.isNull(reference) || StringUtils.isEmpty(reference.getInterface())) {
        ApplicationConfigCache.getInstance().invalidate(metaData.getServiceName());
        reference = ApplicationConfigCache.getInstance().initRef(metaData);
    }
    GenericService genericService = reference.get();
    try {
        if (null == body || "".equals(body) || "{}".equals(body) || "null".equals(body)) {
            return genericService.$invoke(metaData.getMethodName(), new String[]{}, new Object[]{});
        } else {
            Pair<String[], Object[]> pair = dubboParamResolveService.buildParameter(body, metaData.getParameterTypes());
            return genericService.$invoke(metaData.getMethodName(), pair.getLeft(), pair.getRight());
        }
    } catch (GenericException e) {
        log.error("dubbo invoker have exception", e);
        throw new SoulException(e.getMessage());
    }
}
 
Example #18
Source File: ReferenceConfig.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (isGeneric()
           || (getConsumer() != null && getConsumer().isGeneric())) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                   .getContextClassLoader());
        }
       } catch (ClassNotFoundException t) {
           throw new IllegalStateException(t.getMessage(), t);
       }
    return interfaceClass;
}
 
Example #19
Source File: DubboServiceFactory.java    From pampas with Apache License 2.0 6 votes vote down vote up
public Object genericInvoke(DubboRequest dubboRequest) {

        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
        reference.setApplication(application);
        reference.setRegistry(registry);
        reference.setInterface(dubboRequest.getService());
        reference.setGeneric(true);
        ReferenceConfigCache cache = ReferenceConfigCache.getCache();
        GenericService genericService = cache.get(reference);

        int len = dubboRequest.getParams().size();
        String[] invokeParamTyeps = new String[len];
        Object[] invokeParams = new Object[len];
        for (int i = 0; i < len; i++) {
            invokeParamTyeps[i] = String.valueOf(dubboRequest.getParams().getJSONObject(i).getString("type"));
            invokeParams[i] = dubboRequest.getParams().getJSONObject(i).get("value");
        }
        return genericService.$invoke(dubboRequest.getMethod(), invokeParamTyeps, invokeParams);

    }
 
Example #20
Source File: ServiceConfig.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (ref instanceof GenericService) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                .getContextClassLoader());
        }
    } catch (ClassNotFoundException t) {
        throw new IllegalStateException(t.getMessage(), t);
    }
    return interfaceClass;
}
 
Example #21
Source File: Consumer.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

         System.out.println("\n\n\nstart to generic invoke");
         ApplicationConfig applicationConfig = new ApplicationConfig();
         ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
         applicationConfig.setName("UserProviderGer");
         reference.setApplication(applicationConfig);
         RegistryConfig registryConfig = new RegistryConfig();
         registryConfig.setAddress("zookeeper://127.0.0.1:2181");
         reference.setRegistry(registryConfig);
         reference.setGeneric(true);
         reference.setInterface("com.ikurento.user.UserProvider");
         GenericService genericService = reference.get();
         Object[] parameterArgs = new Object[]{"A003"};
         Object result = genericService.$invoke("GetUser", null , parameterArgs);
         System.out.println("res: " + result);

         System.out.println("\n\n\nstart to generic invoke1");
         User user = new User();
         user.setName("Patrick");
         user.setId("id");
         user.setAge(10);
         parameterArgs = new Object[]{user};
         Object result1 = genericService.$invoke("queryUser", new String[]{"com.ikurento.user.User"} , parameterArgs);
         System.out.println("res: " + result1);
    }
 
Example #22
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #23
Source File: EnumBak.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericEnum() throws InterruptedException{
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
            );
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);
    
    URL consumerurl = serviceurl;
    
    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);
    
    invoker.destroy();
    reference.destroy();
}
 
Example #24
Source File: EnumBak.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public void testGenricCustomArg(){
    
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");
    
    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->"+obj);
    reference.destroy();
}
 
Example #25
Source File: DubboMonitorConsumerFactory.java    From EasyTransaction with Apache License 2.0 6 votes vote down vote up
private <T extends EtMonitor> EtMonitor generateProxy(String appId, Class<T> monitorInterface) {
    return (EtMonitor) Proxy.newProxyInstance(monitorInterface.getClassLoader(), new Class[] { monitorInterface }, new InvocationHandler() {
        
        private GenericService service = generateService(appId, monitorInterface);
        private ConcurrentHashMap<Method, String[]> mapParameterCLassString = new ConcurrentHashMap<>();
        
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            
            String[] paramTypeStr = mapParameterCLassString.computeIfAbsent(method, m->{
                return Arrays.stream(m.getParameterTypes()).map(clazz->clazz.getName()).toArray(String[]::new);
            });
            
            return service.$invoke(method.getName(), paramTypeStr, args);
        }
    });
}
 
Example #26
Source File: ReferenceConfig.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (isGeneric()
           || (getConsumer() != null && getConsumer().isGeneric())) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                   .getContextClassLoader());
        }
       } catch (ClassNotFoundException t) {
           throw new IllegalStateException(t.getMessage(), t);
       }
    return interfaceClass;
}
 
Example #27
Source File: ServiceConfig.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (ref instanceof GenericService) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                .getContextClassLoader());
        }
    } catch (ClassNotFoundException t) {
        throw new IllegalStateException(t.getMessage(), t);
    }
    return interfaceClass;
}
 
Example #28
Source File: ServiceConfig.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (ref instanceof GenericService) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                .getContextClassLoader());
        }
    } catch (ClassNotFoundException t) {
        throw new IllegalStateException(t.getMessage(), t);
    }
    return interfaceClass;
}
 
Example #29
Source File: DubboServiceConfig.java    From dubbo-mock with Apache License 2.0 6 votes vote down vote up
public ServiceConfig<GenericService> fillDubboService(MockService mockService, com.tony.test.mock.po.RegistryConfig registryConfig,
        com.tony.test.mock.po.ProtocolConfig protocolConfig, MockGenericService tmpMockservice) {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setInterface(mockService.getServiceInterface());
    service.setRef(tmpMockservice); // 指向一个通用服务实现 
    RegistryConfig registry = createRegistry(registryConfig.getRegistryAddress(), registryConfig.getRegistryTimeout());
    service.setRegistry(registry);
    service.setProtocols(Lists.newArrayList(new ProtocolConfig(protocolConfig.getProtocolName(), protocolConfig.getProtocolPort())));
    if (!StringUtils.isBlank(mockService.getGroupName())) {
        service.setGroup(mockService.getGroupName());
    }
    service.setTimeout(mockService.getTimeout());
    service.setRetries(mockService.getRetries());
    service.setApplication(new ApplicationConfig(mockService.getApplicationName()));
    return service;
}
 
Example #30
Source File: EnumBak.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void testGenricCustomArg(){
    
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");
    
    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->"+obj);
    reference.destroy();
}