Пример #1
0
 private String getReverseRoute(RouteRedirectView viewResult, Route route) {
   try {
     return route.getReverseRoute(viewResult.getPathVariables());
   } catch (ReverseRouteException e) {
     throw new ViewResolutionException(
         e, "Failed to redirect to route '%s': %s", route.getRoute(), e.getMessage());
   }
 }
Пример #2
0
 @Override
 public void resolve(
     HttpServletRequest req, HttpServletResponse resp, RouteRedirectView viewResult) {
   String routeName = viewResult.getRoute();
   Route route = this.router.getNamedRoute(routeName);
   if (route == null) {
     throw new ViewResolutionException(
         "Cannot redirect to the route named '%s': no route with this name exists", routeName);
   }
   String reverseRoute = getReverseRoute(viewResult, route);
   String queryString = URLEncoder.encodeQueryString(viewResult.getQueryParameters());
   reverseRoute += queryString;
   try {
     resp.sendRedirect(reverseRoute);
   } catch (IOException e) {
     throw new ViewResolutionException(
         e, "Failed to redirect to route '%s' (%s): %s", routeName, reverseRoute, e.getMessage());
   }
 }