Author: mgrigorov
Date: Sat Apr  9 16:26:02 2011
New Revision: 1090625

URL: http://svn.apache.org/viewvc?rev=1090625&view=rev
Log:
WICKET-3599 When resource responds with 404 custom error page rendering fails

Ignore the query string when the current http request is to an error page.


Added:
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java?rev=1090625&r1=1090624&r2=1090625&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
 Sat Apr  9 16:26:02 2011
@@ -93,6 +93,8 @@ public class ServletWebRequest extends W
                this.httpServletRequest = httpServletRequest;
                this.filterPrefix = filterPrefix;
 
+               errorAttributes = ErrorAttributes.of(httpServletRequest);
+
                if (url != null)
                {
                        this.url = url;
@@ -101,8 +103,6 @@ public class ServletWebRequest extends W
                {
                        this.url = getUrl(httpServletRequest, filterPrefix);
                }
-
-               errorAttributes = ErrorAttributes.of(httpServletRequest);
        }
 
        /**
@@ -168,11 +168,14 @@ public class ServletWebRequest extends W
                final int start = request.getContextPath().length() + 
filterPrefix.length() + 1;
                url.append(uri.substring(start));
 
-               String query = request.getQueryString();
-               if (!Strings.isEmpty(query))
+               if (errorAttributes == null)
                {
-                       url.append("?");
-                       url.append(query);
+                       String query = request.getQueryString();
+                       if (!Strings.isEmpty(query))
+                       {
+                               url.append('?');
+                               url.append(query);
+                       }
                }
 
                return setParameters(Url.parse(url.toString(), getCharset()));

Added: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java?rev=1090625&view=auto
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
 (added)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java
 Sat Apr  9 16:26:02 2011
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.protocol.http.servlet;
+
+import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
+import org.apache.wicket.request.Url;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests for {@link ServletWebRequest}
+ */
+public class ServletWebRequestTest
+{
+
+       /**
+        * Tests that {@link ServletWebRequest#getClientUrl()} returns the 
current url + the query
+        * string when this is not error dispatched request. When the request 
is error dispatched it
+        * returns just the request uri to the error page without the query 
string
+        */
+       @Test
+       public void wicket3599()
+       {
+               MockHttpServletRequest httpRequest = new 
MockHttpServletRequest(null, null, null);
+               httpRequest.setURL("/" + httpRequest.getContextPath() + 
"/request/Uri");
+               httpRequest.setParameter("some", "parameter");
+
+               ServletWebRequest webRequest = new 
ServletWebRequest(httpRequest, "/");
+               Url clientUrl = webRequest.getClientUrl();
+               Assert.assertEquals("request/Uri?some=parameter", 
clientUrl.toString());
+
+               // error dispatched
+               httpRequest.setAttribute("javax.servlet.error.request_uri", 
"/some/error/url");
+               ServletWebRequest errorWebRequest = new 
ServletWebRequest(httpRequest, "/");
+               Url errorClientUrl = errorWebRequest.getClientUrl();
+
+               Assert.assertEquals("/some/error/url", 
errorClientUrl.toString());
+       }
+}


Reply via email to