ResponseLinksMapper { Object fixLink(Object value) { if (!(value instanceof String)) { return value; } String href = (String) value; Matcher urlWithServiceNameMatcher = urlWithServiceNamePattern.matcher(href); Matcher standardUrlMatcher = standardUrlPattern.matcher(href); if (!standardUrlMatcher.matches() && urlWithServiceNameMatcher.matches()) { String possibleServiceName = urlWithServiceNameMatcher.group(1); log.debug("Possible service name: " + possibleServiceName); if (services.contains(possibleServiceName)) { log.debug("Service found"); String gatewayPath = serviceRouteMapper.apply(possibleServiceName); String originalRestPath = urlWithServiceNameMatcher.group(2); ServletUriComponentsBuilder servletUriComponentsBuilder = ServletUriComponentsBuilder.fromCurrentRequest(); UriComponents uriComponents = servletUriComponentsBuilder.replacePath(gatewayPath).path(originalRestPath).build(); log.debug("Mapping " + value + " to " + uriComponents); return uriComponents.toString(); } } return href; } @Autowired  ResponseLinksMapper(ServiceRouteMapper serviceRouteMapper, DiscoveryClient discoveryClient); @PostConstruct void fillServices(); void fixFor(Map<String, Object> node); static final List<String> NODE_NAMES; }
@Test public void testFixLink() throws Exception { ServiceRouteMapper mapper = new ModuleServiceMapper(); DiscoveryClient discoveryClient = mock(DiscoveryClient.class); ResponseLinksMapper responseLinksMapper = new ResponseLinksMapper(mapper, discoveryClient); when(discoveryClient.getServices()).thenReturn(Collections.singletonList("service-module")); responseLinksMapper.fillServices(); assertEquals("http: }