com.alibaba.dubbo.rpc.service.GenericException Java Examples
The following examples show how to use
com.alibaba.dubbo.rpc.service.GenericException.
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: ConfigTest.java From dubbox with Apache License 2.0 | 6 votes |
@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 #2
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@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 #3
Source File: AlibabaDubboProxyService.java From soul with Apache License 2.0 | 6 votes |
/** * 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 #4
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 6 votes |
@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 #5
Source File: ConfigTest.java From dubbo3 with Apache License 2.0 | 6 votes |
@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 #6
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 6 votes |
@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 #7
Source File: ConfigTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@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 #8
Source File: ConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); 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; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example #9
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); 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; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example #10
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); 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; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example #11
Source File: ConfigTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); 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; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example #12
Source File: ConfigTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); 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; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example #13
Source File: ConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testReferGenericExport() throws Exception { ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export"); RegistryConfig rc = new RegistryConfig(); rc.setAddress(RegistryConfig.NO_AVAILABLE); 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; } }); ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>(); ref.setApplication(ac); ref.setRegistry(rc); ref.setInterface(DemoService.class.getName()); try { sc.export(); ref.get(); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } finally { sc.unexport(); ref.destroy(); } }
Example #14
Source File: MockGenericService.java From dubbo-mock with Apache License 2.0 | 5 votes |
@Override public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { MethodRule rule = rules.get(method); if (rule == null) return null; DataCountPointer countPointer = rule.getDataCountPointer(); Map<String, Object> context = buildContext(method, parameterTypes, args, countPointer); String s = rule.resolve(context); return JSON.parse(s); }
Example #15
Source File: GenericDemoService.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; }
Example #16
Source File: GenericServiceTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testGenericServiceException() { 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]; } if ("throwDemoException".equals(method)) { throw new GenericException(DemoException.class.getName(), "Generic"); } if ("getUsers".equals(method)) { return args[0]; } return null; } }); service.export(); try { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?generic=true"); DemoService demoService = reference.get(); try { // say name Assert.assertEquals("Generic Haha", demoService.sayName("Haha")); // get users List<User> users = new ArrayList<User>(); users.add(new User("Aaa")); users = demoService.getUsers(users); Assert.assertEquals("Aaa", users.get(0).getName()); // throw demo exception try { demoService.throwDemoException(); Assert.fail(); } catch (DemoException e) { Assert.assertEquals("Generic", e.getMessage()); } } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #17
Source File: GenericServiceTest.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
@Test public void testGenericServiceException() { 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]; } if ("throwDemoException".equals(method)) { throw new GenericException(DemoException.class.getName(), "Generic"); } if ("getUsers".equals(method)) { return args[0]; } return null; } }); service.export(); try { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?generic=true"); DemoService demoService = reference.get(); try { // say name Assert.assertEquals("Generic Haha", demoService.sayName("Haha")); // get users List<User> users = new ArrayList<User>(); users.add(new User("Aaa")); users = demoService.getUsers(users); Assert.assertEquals("Aaa", users.get(0).getName()); // throw demo exception try { demoService.throwDemoException(); Assert.fail(); } catch (DemoException e) { Assert.assertEquals("Generic", e.getMessage()); } } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #18
Source File: GenericDemoService.java From dubbo3 with Apache License 2.0 | 4 votes |
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; }
Example #19
Source File: GenericDemoService.java From dubbox with Apache License 2.0 | 4 votes |
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; }
Example #20
Source File: GenericServiceTest.java From dubbo3 with Apache License 2.0 | 4 votes |
@Test public void testGenericServiceException() { 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]; } if ("throwDemoException".equals(method)) { throw new GenericException(DemoException.class.getName(), "Generic"); } if ("getUsers".equals(method)) { return args[0]; } return null; } }); service.export(); try { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?generic=true"); DemoService demoService = reference.get(); try { // say name Assert.assertEquals("Generic Haha", demoService.sayName("Haha")); // get users List<User> users = new ArrayList<User>(); users.add(new User("Aaa")); users = demoService.getUsers(users); Assert.assertEquals("Aaa", users.get(0).getName()); // throw demo exception try { demoService.throwDemoException(); Assert.fail(); } catch (DemoException e) { Assert.assertEquals("Generic", e.getMessage()); } } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #21
Source File: GenericDemoService.java From dubbox with Apache License 2.0 | 4 votes |
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; }
Example #22
Source File: DubboEasyTransRpcProviderImpl.java From EasyTransaction with Apache License 2.0 | 4 votes |
@Override public void startService(Class<?> businessInterface,Map<BusinessIdentifer, RpcBusinessProvider<?>> businessList) { for(Entry<BusinessIdentifer, RpcBusinessProvider<?>> entry :businessList.entrySet()){ BusinessIdentifer key = entry.getKey(); final RpcBusinessProvider<?> value = entry.getValue(); GenericService genericService = new GenericService() { @Override public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { //第一个参数类型为easytransRequest,第二个为map(业务外 框架用的元数据) Method callMethod = getMethod(value.getClass(),method,new String[]{parameterTypes[0]}); try { Object invokeResult = callMethod.invoke(value, new Object[]{args[0]}); logger.debug("EasyTrans rpc call recived, executed success:" + args[0]); return invokeResult; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { logger.info("EasyTrans rpc call recived,executed failed:" + args[0], e); throw new RuntimeException(e); } } }; ServiceConfig<GenericService> service = new ServiceConfig<GenericService>(); service.setInterface(businessInterface); service.setGroup(key.appId() + "-" + key.busCode()); service.setVersion("1.0.0"); service.setRef(genericService); service.setCluster("failfast"); int rpcTimeOut = key.rpcTimeOut(); if(rpcTimeOut != 0){ service.setTimeout(key.rpcTimeOut()); } service.setFilter("easyTransFilter"); if(applicationConfig != null) { service.setApplication(applicationConfig); } if(registryConfig != null) { service.setRegistry(registryConfig); } if(protocolConfig != null) { service.setProtocol(protocolConfig); } if(monitorConfig != null) { service.setMonitor(monitorConfig); } if(moduleConfig != null) { service.setModule(moduleConfig); } if(providerConfig != null) { service.setProvider(providerConfig); } if(customizationer != null) { customizationer.customDubboService(key,service); } service.export(); } }
Example #23
Source File: GenericServiceTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testGenericServiceException() { 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]; } if ("throwDemoException".equals(method)) { throw new GenericException(DemoException.class.getName(), "Generic"); } if ("getUsers".equals(method)) { return args[0]; } return null; } }); service.export(); try { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?generic=true"); DemoService demoService = reference.get(); try { // say name Assert.assertEquals("Generic Haha", demoService.sayName("Haha")); // get users List<User> users = new ArrayList<User>(); users.add(new User("Aaa")); users = demoService.getUsers(users); Assert.assertEquals("Aaa", users.get(0).getName()); // throw demo exception try { demoService.throwDemoException(); Assert.fail(); } catch (DemoException e) { Assert.assertEquals("Generic", e.getMessage()); } } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #24
Source File: GenericDemoService.java From dubbox with Apache License 2.0 | 4 votes |
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; }
Example #25
Source File: GenericServiceTest.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Test public void testGenericServiceException() { 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]; } if ("throwDemoException".equals(method)) { throw new GenericException(DemoException.class.getName(), "Generic"); } if ("getUsers".equals(method)) { return args[0]; } return null; } }); service.export(); try { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?generic=true&timeout=3000"); DemoService demoService = reference.get(); try { // say name Assert.assertEquals("Generic Haha", demoService.sayName("Haha")); // get users List<User> users = new ArrayList<User>(); users.add(new User("Aaa")); users = demoService.getUsers(users); Assert.assertEquals("Aaa", users.get(0).getName()); // throw demo exception try { demoService.throwDemoException(); Assert.fail(); } catch (DemoException e) { Assert.assertEquals("Generic", e.getMessage()); } } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #26
Source File: GenericDemoService.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; }
Example #27
Source File: GenericServiceTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testGenericServiceException() { 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]; } if ("throwDemoException".equals(method)) { throw new GenericException(DemoException.class.getName(), "Generic"); } if ("getUsers".equals(method)) { return args[0]; } return null; } }); service.export(); try { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?generic=true"); DemoService demoService = reference.get(); try { // say name Assert.assertEquals("Generic Haha", demoService.sayName("Haha")); // get users List<User> users = new ArrayList<User>(); users.add(new User("Aaa")); users = demoService.getUsers(users); Assert.assertEquals("Aaa", users.get(0).getName()); // throw demo exception try { demoService.throwDemoException(); Assert.fail(); } catch (DemoException e) { Assert.assertEquals("Generic", e.getMessage()); } } finally { reference.destroy(); } } finally { service.unexport(); } }