You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/07/02 11:42:22 UTC

[1/2] git commit: WICKET-4634 UrlRenderer / Problem with rendering of relative URLs on error page

Updated Branches:
  refs/heads/wicket-1.5.x a1c2814e0 -> d5041e2f6


WICKET-4634 UrlRenderer / Problem with rendering of relative URLs on error page

Cut the leading filter prefix for dispatched request uri


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d5041e2f
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d5041e2f
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d5041e2f

Branch: refs/heads/wicket-1.5.x
Commit: d5041e2f61722d290ae865aec8ce4576a3142795
Parents: e10055a
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Jul 2 11:40:38 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Jul 2 11:40:38 2012 +0200

----------------------------------------------------------------------
 .../http/servlet/DispatchedRequestUtils.java       |   61 +++++++++++++++
 .../protocol/http/servlet/ErrorAttributes.java     |    4 +-
 .../protocol/http/servlet/ForwardAttributes.java   |    4 +-
 .../protocol/http/servlet/ServletWebRequest.java   |    4 +-
 4 files changed, 67 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/d5041e2f/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/DispatchedRequestUtils.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/DispatchedRequestUtils.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/DispatchedRequestUtils.java
new file mode 100644
index 0000000..83d9ae7
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/DispatchedRequestUtils.java
@@ -0,0 +1,61 @@
+/*
+ * 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 javax.servlet.http.HttpServletRequest;
+
+import org.apache.wicket.util.string.Strings;
+
+/**
+ * Common utils for dispatched (error, forward and include) requests.
+ *
+ * @since 1.5.8
+ */
+class DispatchedRequestUtils
+{
+	/**
+	 * Extracts the request uri for a dispatched request (error or forward) and removes the leading
+	 * {@code filterPrefix} from it if it is there.
+	 *
+	 * @param request
+	 *      the dispatched request
+	 * @param attributeName
+	 *      the name of the requets attribute in which the original request uri is stored
+	 * @param filterPrefix
+	 *      the configured filter prefix for WicketFilter
+	 * @return the uri of the dispatched request without the leading filterPrefix
+	 */
+	static String getRequestUri(final HttpServletRequest request, final String attributeName, String filterPrefix)
+	{
+		if (filterPrefix == null)
+		{
+			filterPrefix = "";
+		}
+
+		if (Strings.isEmpty(filterPrefix) == false && filterPrefix.startsWith("/") == false)
+		{
+			filterPrefix = '/' + filterPrefix;
+		}
+
+		String uri = (String)request.getAttribute(attributeName);
+		if (uri != null && uri.startsWith(filterPrefix) && "/".equals(filterPrefix) == false) {
+			uri = uri.substring(filterPrefix.length());
+		}
+
+		return uri;
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/d5041e2f/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ErrorAttributes.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ErrorAttributes.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ErrorAttributes.java
index 7204eb0..874af09 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ErrorAttributes.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ErrorAttributes.java
@@ -141,12 +141,12 @@ public class ErrorAttributes
 	 * @param request
 	 * @return instance of request contains error attributes or {@code null} if it does not.
 	 */
-	public static ErrorAttributes of(HttpServletRequest request)
+	public static ErrorAttributes of(HttpServletRequest request, String filterPrefix)
 	{
 		Args.notNull(request, "request");
 		Integer code = (Integer)request.getAttribute("javax.servlet.error.status_code");
 		String message = (String)request.getAttribute("javax.servlet.error.message");
-		String uri = (String)request.getAttribute("javax.servlet.error.request_uri");
+		String uri = DispatchedRequestUtils.getRequestUri(request, "javax.servlet.error.request_uri", filterPrefix);
 		String servlet = (String)request.getAttribute("javax.servlet.error.servlet_name");
 		@SuppressWarnings("unchecked")
 		Class<? extends Throwable> type = (Class<? extends Throwable>)request.getAttribute("javax.servlet.error.exception_type");

http://git-wip-us.apache.org/repos/asf/wicket/blob/d5041e2f/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ForwardAttributes.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ForwardAttributes.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ForwardAttributes.java
index 45c3389..9741b32 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ForwardAttributes.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ForwardAttributes.java
@@ -115,11 +115,11 @@ public class ForwardAttributes
 	 * @param request
 	 * @return instance of request contains forward attributes or {@code null} if it does not.
 	 */
-	public static ForwardAttributes of(HttpServletRequest request)
+	public static ForwardAttributes of(HttpServletRequest request, String filterPrefix)
 	{
 		Args.notNull(request, "request");
 
-		final String requestUri = (String)request.getAttribute("javax.servlet.forward.request_uri");
+		final String requestUri = DispatchedRequestUtils.getRequestUri(request, "javax.servlet.forward.request_uri", filterPrefix);
 		final String servletPath = (String)request.getAttribute("javax.servlet.forward.servlet_path");
 		final String contextPath = (String)request.getAttribute("javax.servlet.forward.context_path");
 		final String queryString = (String)request.getAttribute("javax.servlet.forward.query_string");

http://git-wip-us.apache.org/repos/asf/wicket/blob/d5041e2f/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
index 851d215..b2069b4 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
@@ -97,9 +97,9 @@ public class ServletWebRequest extends WebRequest
 
 		this.httpServletRequest = httpServletRequest;
 
-		errorAttributes = ErrorAttributes.of(httpServletRequest);
+		errorAttributes = ErrorAttributes.of(httpServletRequest, filterPrefix);
 
-		forwardAttributes = ForwardAttributes.of(httpServletRequest);
+		forwardAttributes = ForwardAttributes.of(httpServletRequest, filterPrefix);
 
 		if (forwardAttributes != null || errorAttributes != null)
 		{