code: public static URI changeProtocolAndPort(String protocol, int port, HttpServletRequest request) throws URISyntaxException {
      return changeProtocolAndPort(
          protocol,
          port,
          URI.create(
              request.getRequestURL()
                  .append((StringUtils.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString()))
                  .toString()));
    }
docs: Constructs a URI for request and calls changeProtocolAndPort(String, int, URI).
  
  @param protocol the new protocol (scheme) in the resulting URI.
  @param port the new port in the resulting URI, or the default port if -1 is provided.
  @param request the request to use as the URI template.
  @return a new URI object with the updated protocol and port.
  @throws URISyntaxException