YarMessageRouter extends ProviderMessageRouter { @Override public Object handle(Channel channel, Object message) { YarRequest yarRequest = (YarRequest) message; String packagerName = yarRequest.getPackagerName(); Provider<?> provider = providerMap.get(yarRequest.getRequestPath()); if (provider == null) { throw new MotanServiceException("can not find service provider. request path:" + yarRequest.getRequestPath()); } Class<?> clazz = provider.getInterface(); Request request = YarProtocolUtil.convert(yarRequest, clazz); Response response = call(request, provider); YarResponse yarResponse = YarProtocolUtil.convert(response, packagerName); return yarResponse; } YarMessageRouter();  YarMessageRouter(URL url); @Override Object handle(Channel channel, Object message); @Override void addProvider(Provider<?> provider); @Override void removeProvider(Provider<?> provider);  }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testHandle() { response = new DefaultResponse(); response.setValue("test"); response.setProcessTime(1); Provider provider = new DefaultProvider(null, null, AnnoService.class); router.addProvider(provider); YarRequest yarRequest = new YarRequest(1, "JSON", "hello", new Object[] {"params"}); yarRequest.setRequestPath(requestPath); YarResponse yarResponse = (YarResponse) router.handle(null, yarRequest); assertEquals(YarProtocolUtil.convert(response, "JSON"), yarResponse); }