diff --git a/spring-web/src/main/java/org/springframework/web/util/WebUtils.java b/spring-web/src/main/java/org/springframework/web/util/WebUtils.java index c7acf09502..71f834b87f 100644 --- a/spring-web/src/main/java/org/springframework/web/util/WebUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/WebUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -428,27 +428,6 @@ public abstract class WebUtils { return (request.getAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE) != null); } - /** - * Expose the current request URI and paths as {@link javax.servlet.http.HttpServletRequest} - * attributes under the keys defined in the Servlet 2.4 specification, - * for containers that implement 2.3 or an earlier version of the Servlet API: - * {@code javax.servlet.forward.request_uri}, - * {@code javax.servlet.forward.context_path}, - * {@code javax.servlet.forward.servlet_path}, - * {@code javax.servlet.forward.path_info}, - * {@code javax.servlet.forward.query_string}. - *
Does not override values if already present, to not cause conflicts - * with the attributes exposed by Servlet 2.4+ containers themselves. - * @param request current servlet request - */ - public static void exposeForwardRequestAttributes(HttpServletRequest request) { - exposeRequestAttributeIfNotPresent(request, FORWARD_REQUEST_URI_ATTRIBUTE, request.getRequestURI()); - exposeRequestAttributeIfNotPresent(request, FORWARD_CONTEXT_PATH_ATTRIBUTE, request.getContextPath()); - exposeRequestAttributeIfNotPresent(request, FORWARD_SERVLET_PATH_ATTRIBUTE, request.getServletPath()); - exposeRequestAttributeIfNotPresent(request, FORWARD_PATH_INFO_ATTRIBUTE, request.getPathInfo()); - exposeRequestAttributeIfNotPresent(request, FORWARD_QUERY_STRING_ATTRIBUTE, request.getQueryString()); - } - /** * Expose the Servlet spec's error attributes as {@link javax.servlet.http.HttpServletRequest} * attributes under the keys defined in the Servlet 2.3 specification, for error pages that diff --git a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesView.java b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesView.java index 67dec59124..1ce5c9af22 100644 --- a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesView.java +++ b/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/TilesView.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.servlet.view.tiles3; import java.util.Locale; import java.util.Map; - -import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,6 +29,7 @@ import org.apache.tiles.request.Request; import org.apache.tiles.request.render.Renderer; import org.apache.tiles.request.servlet.ServletRequest; import org.apache.tiles.request.servlet.ServletUtil; + import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -37,7 +37,6 @@ import org.springframework.web.servlet.support.JstlUtils; import org.springframework.web.servlet.support.RequestContext; import org.springframework.web.servlet.support.RequestContextUtils; import org.springframework.web.servlet.view.AbstractUrlBasedView; -import org.springframework.web.util.WebUtils; /** * {@link org.springframework.web.servlet.View} implementation that renders @@ -53,8 +52,6 @@ public class TilesView extends AbstractUrlBasedView { private Renderer renderer; - private boolean exposeForwardAttributes = false; - private boolean exposeJstlAttributes = true; private ApplicationContext applicationContext; @@ -76,32 +73,24 @@ public class TilesView extends AbstractUrlBasedView { this.exposeJstlAttributes = exposeJstlAttributes; } - @Override - protected void initServletContext(ServletContext servletContext) { - super.initServletContext(servletContext); - if (servletContext.getMajorVersion() == 2 && servletContext.getMinorVersion() < 5) { - this.exposeForwardAttributes = true; - } - } - @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); this.applicationContext = ServletUtil.getApplicationContext(getServletContext()); - if (this.renderer == null) { TilesContainer container = TilesAccess.getContainer(this.applicationContext); this.renderer = new DefinitionRenderer(container); } } + @Override public boolean checkResource(final Locale locale) throws Exception { HttpServletRequest servletRequest = null; RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); - if(requestAttributes != null && requestAttributes instanceof ServletRequestAttributes) { - servletRequest = ((ServletRequestAttributes)requestAttributes).getRequest(); + if (requestAttributes instanceof ServletRequestAttributes) { + servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest(); } Request request = new ServletRequest(this.applicationContext, servletRequest, null) { @Override @@ -117,28 +106,8 @@ public class TilesView extends AbstractUrlBasedView { HttpServletResponse response) throws Exception { exposeModelAsRequestAttributes(model, request); - if (this.exposeJstlAttributes) { - ServletContext servletContext = getServletContext(); - JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext)); - } - - if (!response.isCommitted()) { - // Tiles is going to use a forward, but some web containers (e.g. - // OC4J 10.1.3) - // do not properly expose the Servlet 2.4 forward request - // attributes... However, - // must not do this on Servlet 2.5 or above, mainly for GlassFish - // compatibility. - if (this.exposeForwardAttributes) { - try { - WebUtils.exposeForwardRequestAttributes(request); - } catch (Exception ex) { - // Servlet container rejected to set internal attributes, - // e.g. on TriFork. - this.exposeForwardAttributes = false; - } - } + JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext())); } Request tilesRequest = createTilesRequest(request, response); @@ -146,9 +115,8 @@ public class TilesView extends AbstractUrlBasedView { } /** - * Create a Tiles {@link Request}. This implementation creates a - * {@link ServletRequest}. - * + * Create a Tiles {@link Request}. + *
This implementation creates a {@link ServletRequest}.
* @param request the current request
* @param response the current response
* @return the Tiles request
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java
index 83c2bb55c2..580536ca53 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/InternalResourceView.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -69,8 +68,6 @@ public class InternalResourceView extends AbstractUrlBasedView {
private boolean alwaysInclude = false;
- private volatile Boolean exposeForwardAttributes;
-
private boolean exposeContextBeansAsAttributes = false;
private Set Default is "true" on Servlet containers up until 2.4, and "false" for
- * Servlet 2.5 and above. Note that Servlet containers at 2.4 level and above
- * should expose those attributes automatically! This InternalResourceView
- * feature exists for Servlet 2.3 containers and misbehaving 2.4 containers.
- */
- public void setExposeForwardAttributes(boolean exposeForwardAttributes) {
- this.exposeForwardAttributes = exposeForwardAttributes;
- }
-
/**
* Set whether to make all Spring beans in the application context accessible
* as request attributes, through lazy checking once an attribute gets accessed.
@@ -179,19 +164,6 @@ public class InternalResourceView extends AbstractUrlBasedView {
return false;
}
- /**
- * Checks whether we need to explicitly expose the Servlet 2.4 request attributes
- * by default.
- * @see #setExposeForwardAttributes
- * @see #exposeForwardRequestAttributes(javax.servlet.http.HttpServletRequest)
- */
- @Override
- protected void initServletContext(ServletContext sc) {
- if (this.exposeForwardAttributes == null && sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
- this.exposeForwardAttributes = Boolean.TRUE;
- }
- }
-
/**
* Render the internal resource given the specified model.
@@ -231,7 +203,6 @@ public class InternalResourceView extends AbstractUrlBasedView {
else {
// Note: The forwarded resource is supposed to determine the content type itself.
- exposeForwardRequestAttributes(requestToExpose);
if (logger.isDebugEnabled()) {
logger.debug("Forwarding to resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'");
}
@@ -328,28 +299,4 @@ public class InternalResourceView extends AbstractUrlBasedView {
return (this.alwaysInclude || WebUtils.isIncludeRequest(request) || response.isCommitted());
}
- /**
- * Expose the current request URI and paths as {@link HttpServletRequest}
- * attributes under the keys defined in the Servlet 2.4 specification,
- * for Servlet 2.3 containers as well as misbehaving Servlet 2.4 containers
- * (such as OC4J).
- * Does not expose the attributes on Servlet 2.5 or above, mainly for
- * GlassFish compatibility (GlassFish gets confused by pre-exposed attributes).
- * In any case, Servlet 2.5 containers should finally properly support
- * Servlet 2.4 features, shouldn't they...
- * @param request current HTTP request
- * @see org.springframework.web.util.WebUtils#exposeForwardRequestAttributes
- */
- protected void exposeForwardRequestAttributes(HttpServletRequest request) {
- if (this.exposeForwardAttributes != null && this.exposeForwardAttributes) {
- try {
- WebUtils.exposeForwardRequestAttributes(request);
- }
- catch (Exception ex) {
- // Servlet container rejected to set internal attributes, e.g. on TriFork.
- this.exposeForwardAttributes = Boolean.FALSE;
- }
- }
- }
-
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java
index 3fad8fa775..70fba26b1d 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,25 +55,6 @@ import org.springframework.web.util.WebUtils;
*/
public class TilesView extends AbstractUrlBasedView {
- private volatile boolean exposeForwardAttributes = false;
-
-
- /**
- * Checks whether we need to explicitly expose the Servlet 2.4 request attributes
- * by default.
- * This will be done by default on Servlet containers up until 2.4, and skipped
- * for Servlet 2.5 and above. Note that Servlet containers at 2.4 level and above
- * should expose those attributes automatically! This feature exists for
- * Servlet 2.3 containers and misbehaving 2.4 containers only.
- */
- @Override
- protected void initServletContext(ServletContext sc) {
- if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
- this.exposeForwardAttributes = true;
- }
- }
-
-
@Override
public boolean checkResource(final Locale locale) throws Exception {
TilesContainer container = ServletUtil.getContainer(getServletContext());
@@ -105,22 +86,6 @@ public class TilesView extends AbstractUrlBasedView {
exposeModelAsRequestAttributes(model, request);
JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext));
-
- if (!response.isCommitted()) {
- // Tiles is going to use a forward, but some web containers (e.g. OC4J 10.1.3)
- // do not properly expose the Servlet 2.4 forward request attributes... However,
- // must not do this on Servlet 2.5 or above, mainly for GlassFish compatibility.
- if (this.exposeForwardAttributes) {
- try {
- WebUtils.exposeForwardRequestAttributes(request);
- }
- catch (Exception ex) {
- // Servlet container rejected to set internal attributes, e.g. on TriFork.
- this.exposeForwardAttributes = false;
- }
- }
- }
-
container.render(getUrl(), request, response);
}
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java
index 3a9531b7d0..e29e4555ec 100644
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java
@@ -17,9 +17,7 @@
package org.springframework.web.servlet.view;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Set;
-
import javax.servlet.http.HttpServletRequest;
import junit.framework.TestCase;
@@ -55,7 +53,7 @@ public class InternalResourceViewTests extends TestCase {
public void testForward() throws Exception {
HashMap