List of usage examples for org.springframework.web.servlet.support ServletUriComponentsBuilder replacePath
@Override
public UriComponentsBuilder replacePath(@Nullable String path)
From source file:org.moserp.infrastructure.gateway.filter.ResponseLinksMapper.java
Object fixLink(Object value) {
if (!(value instanceof String)) {
return value;
}//w ww . j a va 2s . c o m
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;
}