/** * Whether to propagate the query parameters of the current request through * to the target redirect URL. * <p>Default is {@code false}. */ public RedirectViewControllerRegistration setKeepQueryParams(boolean propagate) { this.redirectView.setPropagateQueryParams(propagate); return this; }
/** * Whether to propagate the query parameters of the current request through * to the target redirect URL. * <p>Default is {@code false}. */ public RedirectViewControllerRegistration setKeepQueryParams(boolean propagate) { this.redirectView.setPropagateQueryParams(propagate); return this; }
/** * Registers a new {@link User} for the data provided by the given {@link UserForm}. Note, how an interface is used to * bind request parameters. * * @param userForm the request data bound to the {@link UserForm} instance. * @param binding the result of the binding operation. * @param model the Spring MVC {@link Model}. * @return */ @RequestMapping(method = RequestMethod.POST) public Object register(UserForm userForm, BindingResult binding, Model model) { userForm.validate(binding, userManagement); if (binding.hasErrors()) { return "users"; } userManagement.register(new Username(userForm.getUsername()), Password.raw(userForm.getPassword())); RedirectView redirectView = new RedirectView("redirect:/users"); redirectView.setPropagateQueryParams(true); return redirectView; }
@Test public void propagateQueryParams() throws Exception { RedirectView rv = new RedirectView(); rv.setPropagateQueryParams(true); rv.setUrl("http://url.somewhere.com?foo=bar#bazz"); request.setQueryString("a=b&c=d"); rv.render(new HashMap<>(), request, response); assertEquals(302, response.getStatus()); assertEquals("http://url.somewhere.com?foo=bar&a=b&c=d#bazz", response.getHeader("Location")); }
/** * Whether to propagate the query parameters of the current request through * to the target redirect URL. * <p>Default is {@code false}. */ public RedirectViewControllerRegistration setKeepQueryParams(boolean propagate) { this.redirectView.setPropagateQueryParams(propagate); return this; }
private RedirectView redirectViewWithQuery(String redirectUri, String state, String query) { try { if (!Strings.isNullOrEmpty(state)) { query += "&state=" + state; } String encoded = UriUtils.encodeQuery(query, Charsets.UTF_8.name()); String locationUri = redirectUri; if (redirectUri.contains("?")) { locationUri += "&" + encoded; } else { locationUri += "?" + encoded; } RedirectView redirectView = new RedirectView(locationUri); redirectView.setStatusCode(HttpStatus.FOUND); redirectView.setExposeModelAttributes(false); redirectView.setPropagateQueryParams(false); return redirectView; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
private Object resolveZone(HttpServletRequest request, String decodedRawZone, Function<ZoneInfo, ModelAndView> onZoneInfo) { // note that decodedRawZone already do http url decode, and PathVariable already trim() // space of value return Zone.tryFallback(decodedRawZone).map(zone -> { if (!zone.value().equals(decodedRawZone)) { String orgUrl = request.getRequestURL().toString(); // replace pattern is combine of fallback pattern and valid pattern // TODO refactor replace rule to Zone String location = orgUrl.replaceFirst("/z/[a-zA-Z0-9_\\-]+", "/z/" + zone); //check if fallback success, this prevent infinite redirect loop if (!location.equals(orgUrl)) { RedirectView redirectView = new RedirectView(location); redirectView.setPropagateQueryParams(true); redirectView.setExpandUriTemplateVariables(false); redirectView.setExposeModelAttributes(false); redirectView.setExposeContextBeansAsAttributes(false); redirectView.setExposePathVariables(false); redirectView.setContextRelative(true); redirectView.setStatusCode(HttpStatus.PERMANENT_REDIRECT); return redirectView; } } return onZoneInfo.apply(zoneService.loadZone(zone)); }).orElseThrow(() -> new EmptyResultDataAccessException("no such zone: " + decodedRawZone, 1)); }