Removed Servlet 2.4 forward attribute support in InternalResourceView and TilesView

This commit is contained in:
Juergen Hoeller
2013-03-19 14:26:56 +01:00
parent 0f0c93a559
commit a03d125b4e
5 changed files with 19 additions and 218 deletions

View File

@@ -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<String> exposedContextBeanNames;
@@ -118,18 +115,6 @@ public class InternalResourceView extends AbstractUrlBasedView {
this.alwaysInclude = alwaysInclude;
}
/**
* Set whether to explictly expose the Servlet 2.4 forward request attributes
* when forwarding to the underlying view resource.
* <p>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).
* <p>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;
}
}
}
}

View File

@@ -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.
* <p>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);
}