RestProtocol extends AbstractProxyProtocol { @Override public void destroy() { super.destroy(); if (connectionMonitor != null) { connectionMonitor.shutdown(); } for (Map.Entry<String, ProtocolServer> entry : serverMap.entrySet()) { try { if (logger.isInfoEnabled()) { logger.info("Closing the rest server at " + entry.getKey()); } entry.getValue().close(); } catch (Throwable t) { logger.warn("Error closing rest server", t); } } serverMap.clear(); if (logger.isInfoEnabled()) { logger.info("Closing rest clients"); } for (ResteasyClient client : clients) { try { client.close(); } catch (Throwable t) { logger.warn("Error closing rest client", t); } } clients.clear(); } RestProtocol(); void setHttpBinder(HttpBinder httpBinder); @Override int getDefaultPort(); @Override void destroy();  }
@Test public void testRestProtocolWithContextPath() { DemoServiceImpl server = new DemoServiceImpl(); Assertions.assertFalse(server.isCalled()); int port = NetUtils.getAvailablePort(); URL url = URL.valueOf("rest: this.registerProvider(url, server, DemoService.class); ServiceDescriptor serviceDescriptor = repository.registerService(DemoService.class); repository.registerProvider( url.getPathKey(), server, serviceDescriptor, null, null ); Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, url)); url = URL.valueOf("rest: Invoker<DemoService> invoker = protocol.refer(DemoService.class, url); DemoService client = proxy.getProxy(invoker); String result = client.sayHello("haha"); Assertions.assertTrue(server.isCalled()); Assertions.assertEquals("Hello, haha", result); invoker.destroy(); exporter.unexport(); }
@Test public void testRemoteApplicationName() { URL url = URL.valueOf("rest: DemoServiceImpl server = new DemoServiceImpl(); this.registerProvider(url, server, DemoService.class); Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, url)); Invoker<DemoService> invoker = protocol.refer(DemoService.class, url); DemoService client = proxy.getProxy(invoker); String result = client.getRemoteApplicationName(); Assertions.assertEquals("consumer", result); invoker.destroy(); exporter.unexport(); }