code: private Link recursiveResolveLink(Page redirectPage, Link link) {
  
      // set link reference to content resource of redirect page, keep other parameters
      LinkRequest linkRequest = link.getLinkRequest();
      LinkRequest redirectLinkRequest = new LinkRequest(
          redirectPage.getContentResource(),
          null,
          linkRequest.getLinkArgs());
  
      // check of maximum recursive calls via threadlocal to avoid endless loops, return invalid link if one is detected
      LinkResolveCounter linkResolveCounter = LinkResolveCounter.get();
      try {
        linkResolveCounter.increaseCount();
  
        if (linkResolveCounter.isMaximumReached()) {
          // endless loop detected - set link to invalid link
          link.setUrl(null);
          return link;
        }
  
        // resolve link by recursive call to link handler, track recursion count
        return linkHandler.get(redirectLinkRequest).build();
      }
      finally {
        linkResolveCounter.decreaseCount();
      }
    }
docs: Resolves link of redirect or integrator page. Those pages contain the link reference information in their
  content resource (jcr:content node). This information is used to resolve the link.
  @param redirectPage Redirect or integrator page
  @param link Link metadata
  @return Link metadata