/** * Return a context-aware URl for the given relative URL. * @param relativeUrl the relative URL part * @return a URL that points back to the current web application with an * absolute path also URL-encoded accordingly */ public String getContextUrl(String relativeUrl) { String url = getContextPath() + relativeUrl; return getExchange().getResponse().encodeUrl(url); }
/** * Send a redirect back to the HTTP client * @param targetUrl the target URL to redirect to * @param exchange current exchange */ protected Mono<Void> sendRedirect(String targetUrl, ServerWebExchange exchange) { ServerHttpResponse response = exchange.getResponse(); String encodedURL = (isRemoteHost(targetUrl) ? targetUrl : response.encodeUrl(targetUrl)); response.getHeaders().setLocation(URI.create(encodedURL)); response.setStatusCode(getStatusCode()); return Mono.empty(); }
/** * Return a context-aware URl for the given relative URL with placeholders -- * named keys with braces {@code {}}. For example, send in a relative URL * {@code foo/{bar}?spam={spam}} and a parameter map {@code {bar=baz,spam=nuts}} * and the result will be {@code [contextpath]/foo/baz?spam=nuts}. * @param relativeUrl the relative URL part * @param params a map of parameters to insert as placeholders in the url * @return a URL that points back to the current web application with an * absolute path also URL-encoded accordingly */ public String getContextUrl(String relativeUrl, Map<String, ?> params) { String url = getContextPath() + relativeUrl; UriTemplate template = new UriTemplate(url); url = template.expand(params).toASCIIString(); return getExchange().getResponse().encodeUrl(url); }