| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Grails
Revision: 7283
Author: graeme
Date: 21 Aug 2008 11:48:58
Changes:fix for GRAILS-3131
Files:| ... | ...@@ -21,6 +21,7 @@ | |
| 21 | 21 | import org.codehaus.groovy.grails.web.util.WebUtils; |
| 22 | 22 | import org.codehaus.groovy.runtime.DefaultGroovyMethods; |
| 23 | 23 | import org.springframework.web.context.request.RequestContextHolder; |
| 24 | import org.apache.commons.lang.StringUtils; | |
| 24 | 25 | |
| 25 | 26 | import javax.servlet.http.HttpServletRequest; |
| 26 | 27 | import java.io.UnsupportedEncodingException; |
| ... | ...@@ -46,7 +47,7 @@ | |
| 46 | 47 | private static final String ID_PARAM = "id"; |
| 47 | 48 | private UrlMappingData urlData; |
| 48 | 49 | private Object viewName; |
| 49 | private URLDecoder decoder; | |
| 50 | ||
| 50 | 51 | |
| 51 | 52 | private DefaultUrlMappingInfo(Map params, UrlMappingData urlData) { |
| 52 | 53 | this.params = Collections.unmodifiableMap(params); |
| ... | ...@@ -79,10 +80,14 @@ | |
| 79 | 80 | /** |
| 80 | 81 | * Populates request parameters for the given UrlMappingInfo instance using the GrailsWebRequest |
| 81 | 82 | * |
| 82 | * @param dispatchParams The Map instance | |
| 83 | * @param webRequest The Map instance | |
| 83 | 84 | * @see org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest |
| 84 | 85 | */ |
| 85 | protected void populateParamsForMapping(Map dispatchParams) { | |
| 86 | protected void populateParamsForMapping(GrailsWebRequest webRequest) { | |
| 87 | Map dispatchParams = webRequest.getParams(); | |
| 88 | String encoding = webRequest.getRequest().getCharacterEncoding(); | |
| 89 | if(encoding == null) encoding = "UTF-8"; | |
| 90 | ||
| 86 | 91 | Collection keys = this.params.keySet(); |
| 87 | 92 | keys = DefaultGroovyMethods.toList(keys); |
| 88 | 93 | Collections.sort((List) keys, new Comparator() { |
| ... | ...@@ -107,14 +112,28 @@ | |
| 107 | 112 | } |
| 108 | 113 | if (param instanceof String) { |
| 109 | 114 | try { |
| 110 | param = decoder.decode((String) param, "UTF-8"); | |
| 115 | param = URLDecoder.decode((String) param, encoding); | |
| 111 | 116 | } catch (UnsupportedEncodingException e) { |
| 112 | 117 | param = evaluateNameForValue(param); |
| 113 | 118 | } |
| 114 | 119 | } |
| 115 | 120 | dispatchParams.put(name, param); |
| 121 | } | |
| 122 | ||
| 123 | final String viewName = getViewName(); | |
| 116 | 124 | |
| 125 | if (viewName == null) { | |
| 126 | webRequest.setControllerName(getControllerName()); | |
| 127 | webRequest.setActionName(getActionName()); | |
| 117 | 128 | } |
| 129 | ||
| 130 | String id = getId(); | |
| 131 | if(!StringUtils.isBlank(id)) try { | |
| 132 | dispatchParams.put(GrailsWebRequest.ID_PARAMETER, URLDecoder.decode(id, encoding)); | |
| 133 | } catch (UnsupportedEncodingException e) { | |
| 134 | dispatchParams.put(GrailsWebRequest.ID_PARAMETER, id); | |
| 135 | } | |
| 136 | ||
| 118 | 137 | } |
| 119 | 138 | |
| 120 | 139 | public Map getParameters() { |
| ... | ...@@ -122,7 +141,7 @@ | |
| 122 | 141 | } |
| 123 | 142 | |
| 124 | 143 | public void configure(GrailsWebRequest webRequest) { |
| 125 | populateParamsForMapping(webRequest.getParams()); | |
| 144 | populateParamsForMapping(webRequest); | |
| 126 | 145 | } |
| 127 | 146 | |
| 128 | 147 | public String getControllerName() { |
| ... | ...@@ -167,22 +167,6 @@ | |
| 167 | 167 | return forwardUrl.toString(); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | private static void populateWebRequestWithInfo(GrailsWebRequest webRequest, UrlMappingInfo info) { | |
| 171 | if(webRequest != null) { | |
| 172 | final String viewName = info.getViewName(); | |
| 173 | ||
| 174 | if (viewName == null) { | |
| 175 | webRequest.setControllerName(info.getControllerName()); | |
| 176 | webRequest.setActionName(info.getActionName()); | |
| 177 | } | |
| 178 | ||
| 179 | String id = info.getId(); | |
| 180 | if(!StringUtils.isBlank(id))webRequest.getParams().put(GrailsWebRequest.ID_PARAMETER, id); | |
| 181 | ||
| 182 | // Add all the parameters from the URL mapping. | |
| 183 | webRequest.getParams().putAll(info.getParameters()); | |
| 184 | } | |
| 185 | } | |
| 186 | 170 | |
| 187 | 171 | |
| 188 | 172 | public static String forwardRequestForUrlMappingInfo(HttpServletRequest request, HttpServletResponse response, UrlMappingInfo info) throws ServletException, IOException { |
| ... | ...@@ -190,12 +174,10 @@ | |
| 190 | 174 | } |
| 191 | 175 | |
| 192 | 176 | public static String forwardRequestForUrlMappingInfo(HttpServletRequest request, HttpServletResponse response, UrlMappingInfo info, Map model) throws ServletException, IOException { |
| 193 | GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.currentRequestAttributes(); | |
| 194 | 177 | String forwardUrl = buildDispatchUrlForMapping(info); |
| 195 | 178 | |
| 196 | 179 | //populateParamsForMapping(info); |
| 197 | 180 | RequestDispatcher dispatcher = request.getRequestDispatcher(forwardUrl); |
| 198 | populateWebRequestWithInfo(webRequest, info); | |
| 199 | 181 | |
| 200 | 182 | exposeForwardRequestAttributes(request); |
| 201 | 183 | exposeRequestAttributes(request, model); |
| ... | ...@@ -83,6 +83,7 @@ | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | if(!response.isCommitted()) { |
| 86 | info.configure(WebUtils.retrieveGrailsWebRequest()); | |
| 86 | 87 | String forwardUrl = WebUtils.forwardRequestForUrlMappingInfo(request, response, info, mv.getModel()); |
| 87 | 88 | if(LOG.isDebugEnabled()) { |
| 88 | 89 | LOG.debug("Matched URI ["+uri+"] to URL mapping ["+info+"], forwarding to ["+forwardUrl+"] with response ["+response.getClass()+"]"); |