XmlRpcProtocol extends AbstractProxyProtocol { @Override public void destroy() { super.destroy(); for (String key : new ArrayList<>(serverMap.keySet())) { ProtocolServer server = serverMap.remove(key); if (server != null) { try { if (logger.isInfoEnabled()) { logger.info("Close xml server " + server.getUrl()); } server.close(); } catch (Throwable t) { logger.warn(t.getMessage(), t); } } } } XmlRpcProtocol(); void setHttpBinder(HttpBinder httpBinder); @Override int getDefaultPort(); @Override void destroy(); static final String ACCESS_CONTROL_ALLOW_ORIGIN_HEADER; static final String ACCESS_CONTROL_ALLOW_METHODS_HEADER; static final String ACCESS_CONTROL_ALLOW_HEADERS_HEADER; }
@Test public void testXmlRpcProtocolForServerJetty9() { XmlRpcServiceImpl server = new XmlRpcServiceImpl(); Assertions.assertFalse(server.isCalled()); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); int port = NetUtils.getAvailablePort(); URL url = URL.valueOf("xmlrpc: Exporter<XmlRpcService> exporter = protocol.export(proxyFactory.getInvoker(server, XmlRpcService.class, url)); Invoker<XmlRpcService> invoker = protocol.refer(XmlRpcService.class, url); XmlRpcService client = proxyFactory.getProxy(invoker); String result = client.sayHello("haha"); Assertions.assertTrue(server.isCalled()); Assertions.assertEquals("Hello, haha", result); invoker.destroy(); exporter.unexport(); }
@Test @Disabled public void testCustomException() { XmlRpcServiceImpl server = new XmlRpcServiceImpl(); ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); int port = NetUtils.getAvailablePort(); URL url = URL.valueOf("xmlrpc: XmlRpcService.class.getName() + "?version=1.0.0&server=jetty9"); Exporter<XmlRpcService> exporter = protocol.export(proxyFactory.getInvoker(server, XmlRpcService.class, url)); Invoker<XmlRpcService> invoker = protocol.refer(XmlRpcService.class, url); XmlRpcService client = proxyFactory.getProxy(invoker); try { client.customException(); Assertions.fail(); } catch (XmlRpcServiceImpl.MyException expected) { } invoker.destroy(); exporter.unexport(); }