Package com.alibaba.dubbo.rpc.service

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


            ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
            reference.setApplication(new ApplicationConfig("validation-consumer"));
            reference.setInterface(ValidationService.class.getName());
            reference.setUrl("dubbo://127.0.0.1:29582?scope=remote&validation=true");
            reference.setGeneric(true);
            GenericService validationService = reference.get();
            try {
                // Save OK
                Map<String, Object> parameter = new HashMap<String, Object>();
                parameter.put("name", "liangfei");
                parameter.put("Email", "liangfei@liang.fei");
                parameter.put("Age", 50);
                parameter.put("LoginDate", new Date(System.currentTimeMillis() - 1000000));
                parameter.put("ExpiryDate", new Date(System.currentTimeMillis() + 1000000));
                validationService.$invoke("save", new String[] {ValidationParameter.class.getName()}, new Object[] {parameter});
               
                // Save Error
                try {
                    parameter = new HashMap<String, Object>();
                    validationService.$invoke("save", new String[] {ValidationParameter.class.getName()}, new Object[] {parameter});
                    Assert.fail();
                } catch (RpcException e) {
                    Assert.assertTrue(e.getMessage().contains("ConstraintViolation"));
                }
               
                // Delete OK
                validationService.$invoke("delete", new String[] {long.class.getName(), String.class.getName()}, new Object[] {2, "abc"});
               
                // Delete Error
                try {
                    validationService.$invoke("delete", new String[] {long.class.getName(), String.class.getName()}, new Object[] {0, "abc"});
                    Assert.fail();
                } catch (RpcException e) {
                    Assert.assertTrue(e.getMessage().contains("ConstraintViolation"));
                }
                try {
                    validationService.$invoke("delete", new String[] {long.class.getName(), String.class.getName()}, new Object[] {2, null});
                    Assert.fail();
                } catch (RpcException e) {
                    Assert.assertTrue(e.getMessage().contains("ConstraintViolation"));
                }
                try {
                    validationService.$invoke("delete", new String[] {long.class.getName(), String.class.getName()}, new Object[] {0, null});
                    Assert.fail();
                } catch (RpcException e) {
                    Assert.assertTrue(e.getMessage().contains("ConstraintViolation"));
                }
            } finally {
View Full Code Here


        ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
        sc.setApplication(ac);
        sc.setRegistry(rc);
        sc.setInterface(DemoService.class.getName());
        sc.setRef(new GenericService() {

            public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
                return null;
            }
        });
View Full Code Here

        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;
            }
        });
View Full Code Here

        ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
        service.setApplication(new ApplicationConfig("generic-provider"));
        service.setRegistry(new RegistryConfig("N/A"));
        service.setProtocol(new ProtocolConfig("dubbo", 29581));
        service.setInterface(DemoService.class.getName());
        service.setRef(new GenericService() {

            public Object $invoke(String method, String[] parameterTypes, Object[] args)
                throws GenericException {
                if ("sayName".equals(method)) {
                    return "Generic " + args[0];
View Full Code Here

            ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
            reference.setApplication(new ApplicationConfig("generic-consumer"));
            reference.setInterface(DemoService.class);
            reference.setUrl("dubbo://127.0.0.1:29581?scope=remote");
            reference.setGeneric(true);
            GenericService genericService = reference.get();
            try {
                List<Map<String, Object>> users = new ArrayList<Map<String, Object>>();
                Map<String, Object> user = new HashMap<String, Object>();
                user.put("class", "com.alibaba.dubbo.config.api.User");
                user.put("name", "actual.provider");
                users.add(user);
                users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{users});
                Assert.assertEquals(1, users.size());
                Assert.assertEquals("actual.provider", users.get(0).get("name"));
            } finally {
                reference.destroy();
            }
View Full Code Here

            ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
            reference.setApplication(new ApplicationConfig("generic-consumer"));
            reference.setInterface(DemoService.class);
            reference.setUrl("dubbo://127.0.0.1:29581?scope=remote");
            reference.setGeneric(Constants.GENERIC_SERIALIZATION_NATIVE_JAVA);
            GenericService genericService = reference.get();
            try {
                String name = "kimi";
                ByteArrayOutputStream bos = new ByteArrayOutputStream(512);
                ExtensionLoader.getExtensionLoader(Serialization.class)
                    .getExtension("nativejava").serialize(null, bos).writeObject(name);
                byte[] arg = bos.toByteArray();
                Object obj = genericService.$invoke("sayName", new String[]{String.class.getName()}, new Object[]{arg});
                Assert.assertTrue(obj instanceof byte[]);
                byte[] result = (byte[]) obj;
                Assert.assertEquals(ref.sayName(name), ExtensionLoader.getExtensionLoader(Serialization.class)
                    .getExtension("nativejava").deserialize(null, new ByteArrayInputStream(result)).readObject().toString());

                // getUsers
                List<User> users = new ArrayList<User>();
                User user = new User();
                user.setName(name);
                users.add(user);
                bos = new ByteArrayOutputStream(512);
                ExtensionLoader.getExtensionLoader(Serialization.class)
                    .getExtension("nativejava").serialize(null, bos).writeObject(users);
                obj = genericService.$invoke("getUsers",
                                             new String[]{List.class.getName()},
                                             new Object[]{bos.toByteArray()});
                Assert.assertTrue(obj instanceof byte[]);
                result = (byte[]) obj;
                Assert.assertEquals(users,
                                    ExtensionLoader.getExtensionLoader(Serialization.class)
                                        .getExtension("nativejava")
                                        .deserialize(null, new ByteArrayInputStream(result))
                                        .readObject());

                // echo(int)
                bos = new ByteArrayOutputStream(512);
                ExtensionLoader.getExtensionLoader(Serialization.class).getExtension("nativejava")
                    .serialize(null, bos).writeObject(Integer.MAX_VALUE);
                obj = genericService.$invoke("echo", new String[]{int.class.getName()}, new Object[]{bos.toByteArray()});
                Assert.assertTrue(obj instanceof byte[]);
                Assert.assertEquals(Integer.MAX_VALUE,
                                    ExtensionLoader.getExtensionLoader(Serialization.class)
                                        .getExtension("nativejava")
                                        .deserialize(null, new ByteArrayInputStream((byte[]) obj))
View Full Code Here

            reference = new ReferenceConfig<GenericService>();
            reference.setApplication(new ApplicationConfig("bean-consumer"));
            reference.setInterface(DemoService.class);
            reference.setUrl("dubbo://127.0.0.1:29581?scope=remote");
            reference.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN);
            GenericService genericService = reference.get();
            User user = new User();
            user.setName("zhangsan");
            List<User> users = new ArrayList<User>();
            users.add(user);
            Object result = genericService.$invoke("getUsers", new String[]{ReflectUtils.getName(List.class)}, new Object[]{JavaBeanSerializeUtil.serialize(users, JavaBeanAccessor.METHOD)});
            Assert.assertTrue(result instanceof JavaBeanDescriptor);
            JavaBeanDescriptor descriptor = (JavaBeanDescriptor) result;
            Assert.assertTrue(descriptor.isCollectionType());
            Assert.assertEquals(1, descriptor.propertySize());
            descriptor = (JavaBeanDescriptor) descriptor.getProperty(0);
View Full Code Here

        ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
        service.setApplication(new ApplicationConfig("bean-provider"));
        service.setRegistry(new RegistryConfig("N/A"));
        service.setProtocol(new ProtocolConfig("dubbo", 29581));
        service.setInterface(DemoService.class.getName());
        service.setRef(new GenericService() {

            public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
                if ("getUsers".equals(method)) {
                    GenericParameter arg = new GenericParameter();
                    arg.method = method;
View Full Code Here

        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();
    }
View Full Code Here

        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();
    }
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.rpc.service.GenericService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.