mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
Merge pull request #1034 from apache/feature/WW-5450-use-contstants
WW-5450 Uses existing Jakarta constants instead of free hand strings
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.struts2;
|
||||
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.FastDateFormat;
|
||||
@@ -89,7 +90,7 @@ public class RequestUtils {
|
||||
*/
|
||||
public static String getUri(HttpServletRequest request) {
|
||||
// handle http dispatcher includes.
|
||||
String uri = (String) request.getAttribute("jakarta.servlet.include.servlet_path");
|
||||
String uri = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
|
||||
if (uri != null) {
|
||||
return uri;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -100,7 +101,7 @@ public class Include extends Component {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(Include.class);
|
||||
|
||||
private static final String systemEncoding = System.getProperty("file.encoding");
|
||||
private static final String SYSTEM_ENCODING = Charset.defaultCharset().displayName();
|
||||
|
||||
protected String value;
|
||||
private final HttpServletRequest req;
|
||||
@@ -149,8 +150,7 @@ public class Include extends Component {
|
||||
String concat = "";
|
||||
|
||||
// Set parameters
|
||||
for (Object next : parameters.entrySet()) {
|
||||
Map.Entry entry = (Map.Entry) next;
|
||||
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
|
||||
Object name = entry.getKey();
|
||||
List values = (List) entry.getValue();
|
||||
|
||||
@@ -191,7 +191,7 @@ public class Include extends Component {
|
||||
} else if (!(request instanceof HttpServletRequest hrequest)) {
|
||||
returnValue = relativePath;
|
||||
} else {
|
||||
String uri = (String) request.getAttribute("jakarta.servlet.include.servlet_path");
|
||||
String uri = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
|
||||
|
||||
if (uri == null) {
|
||||
uri = RequestUtils.getServletPath(hrequest);
|
||||
@@ -203,7 +203,7 @@ public class Include extends Component {
|
||||
// .. is illegal in an absolute path according to the Servlet Spec and will cause
|
||||
// known problems on Orion application servers.
|
||||
if (returnValue.contains("..")) {
|
||||
Stack stack = new Stack();
|
||||
Stack<String> stack = new Stack<>();
|
||||
StringTokenizer pathParts = new StringTokenizer(returnValue.replace('\\', '/'), "/");
|
||||
|
||||
while (pathParts.hasMoreTokens()) {
|
||||
@@ -279,7 +279,7 @@ public class Include extends Component {
|
||||
pageResponse.getContent().writeTo(writer, encoding);
|
||||
} else {
|
||||
// Use the platform specific encoding
|
||||
pageResponse.getContent().writeTo(writer, systemEncoding);
|
||||
pageResponse.getContent().writeTo(writer, SYSTEM_ENCODING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -302,7 +303,7 @@ public class ServletUrlRenderer implements UrlRenderer {
|
||||
// Parse the query string to make sure that the parameters come from the query, and not some posted data
|
||||
String query = urlComponent.getHttpServletRequest().getQueryString();
|
||||
if (query == null) {
|
||||
query = (String) urlComponent.getHttpServletRequest().getAttribute("jakarta.servlet.forward.query_string");
|
||||
query = (String) urlComponent.getHttpServletRequest().getAttribute(RequestDispatcher.FORWARD_QUERY_STRING);
|
||||
}
|
||||
|
||||
if (query != null) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import com.opensymphony.xwork2.util.location.LocationUtils;
|
||||
import freemarker.template.Template;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -87,7 +88,7 @@ public class DefaultDispatcherErrorHandler implements DispatcherErrorHandler {
|
||||
LOG.error("Exception occurred during processing request: {}", e.getMessage(), e);
|
||||
// send a http error response to use the servlet defined error handler
|
||||
// make the exception available to the web.xml defined error page
|
||||
request.setAttribute("jakarta.servlet.error.exception", e);
|
||||
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
|
||||
|
||||
// for compatibility
|
||||
request.setAttribute("jakarta.servlet.jsp.jspException", e);
|
||||
|
||||
@@ -55,7 +55,7 @@ import java.io.Serial;
|
||||
* {@link PageContext#include(String) include} method is called.</li>
|
||||
*
|
||||
* <li>If there is no PageContext and we're not in any sort of include (there is no
|
||||
* "jakarta.servlet.include.servlet_path" in the request attributes), then a call to
|
||||
* {@link RequestDispatcher#INCLUDE_SERVLET_PATH} in the request attributes), then a call to
|
||||
* {@link RequestDispatcher#forward(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse) forward}
|
||||
* is made.</li>
|
||||
*
|
||||
@@ -125,7 +125,7 @@ public class ServletDispatcherResult extends StrutsResultSupport {
|
||||
* HTTP request.
|
||||
*/
|
||||
public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
|
||||
LOG.debug("Forwarding to location: {}", finalLocation);
|
||||
LOG.debug("Processing location: {}", finalLocation);
|
||||
|
||||
PageContext pageContext = ServletActionContext.getPageContext();
|
||||
|
||||
@@ -145,8 +145,6 @@ public class ServletDispatcherResult extends StrutsResultSupport {
|
||||
if (!queryParams.isEmpty()) {
|
||||
parameters = HttpParameters.create(queryParams.getQueryParams()).withParent(parameters).build();
|
||||
invocation.getInvocationContext().withParameters(parameters);
|
||||
// put to extraContext, see Dispatcher#createContextMap
|
||||
invocation.getInvocationContext().getContextMap().put("parameters", parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,17 +156,19 @@ public class ServletDispatcherResult extends StrutsResultSupport {
|
||||
}
|
||||
|
||||
//if we are inside an action tag, we always need to do an include
|
||||
Boolean insideActionTag = (Boolean) ObjectUtils.defaultIfNull(request.getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION), Boolean.FALSE);
|
||||
boolean insideActionTag = (Boolean) ObjectUtils.defaultIfNull(request.getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION), Boolean.FALSE);
|
||||
|
||||
// If we're included, then include the view
|
||||
// Otherwise do forward
|
||||
// This allow the page to, for example, set content type
|
||||
if (!insideActionTag && !response.isCommitted() && (request.getAttribute("jakarta.servlet.include.servlet_path") == null)) {
|
||||
if (!insideActionTag && !response.isCommitted() && (request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH) == null)) {
|
||||
LOG.debug("Forwarding to location: {}", finalLocation);
|
||||
request.setAttribute("struts.view_uri", finalLocation);
|
||||
request.setAttribute("struts.request_uri", request.getRequestURI());
|
||||
|
||||
dispatcher.forward(request, response);
|
||||
} else {
|
||||
LOG.debug("Including location: {}", finalLocation);
|
||||
dispatcher.include(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import freemarker.template.TemplateExceptionHandler;
|
||||
import freemarker.template.Version;
|
||||
import freemarker.template.utility.StringUtil;
|
||||
import jakarta.servlet.GenericServlet;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -550,7 +551,7 @@ public class FreemarkerManager {
|
||||
model.putAll(standard);
|
||||
|
||||
// support for JSP exception pages, exposing the servlet or JSP exception
|
||||
Throwable exception = (Throwable) request.getAttribute("jakarta.servlet.error.exception");
|
||||
Throwable exception = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
|
||||
|
||||
if (exception == null) {
|
||||
exception = (Throwable) request.getAttribute("jakarta.servlet.error.JspException");
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package org.apache.struts2.views.util;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -126,7 +127,7 @@ public class DefaultUrlHelper implements UrlHelper {
|
||||
|
||||
// (Applicable to Servlet 2.4 containers)
|
||||
// If the request was forwarded, the attribute below will be set with the original URL
|
||||
String uri = (String) request.getAttribute("jakarta.servlet.forward.request_uri");
|
||||
String uri = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
|
||||
|
||||
// If the attribute wasn't found, default to the value in the request object
|
||||
if (uri == null) {
|
||||
@@ -145,7 +146,7 @@ public class DefaultUrlHelper implements UrlHelper {
|
||||
// (Applicable to Servlet 2.4 containers)
|
||||
// If the request was forwarded, the attribute below will be set with the original URL
|
||||
if (requestURI == null) {
|
||||
requestURI = (String) request.getAttribute("jakarta.servlet.forward.request_uri");
|
||||
requestURI = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
|
||||
}
|
||||
|
||||
// If neither request attributes were found, default to the value in the request object
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -130,7 +129,6 @@ public class ServletDispatcherResultTest extends StrutsInternalTestCase implemen
|
||||
|
||||
assertTrue(mockActionInvocation.getInvocationContext().getParameters().contains("bar"));
|
||||
assertEquals("1", mockActionInvocation.getInvocationContext().getParameters().get("bar").getValue());
|
||||
assertEquals("1", ((HttpParameters) mockActionInvocation.getInvocationContext().getContextMap().get("parameters")).get("bar").getValue());
|
||||
dispatcherMock.verify();
|
||||
requestMock.verify();
|
||||
dispatcherMock.verify();
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.tiles.web.util;
|
||||
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tiles.api.AttributeContext;
|
||||
@@ -113,7 +114,7 @@ public class TilesDispatchServlet extends HttpServlet {
|
||||
* @return The definition name to render.
|
||||
*/
|
||||
protected String getDefinitionName(HttpServletRequest request) {
|
||||
String path = (String) request.getAttribute("jakarta.servlet.include.servlet_path");
|
||||
String path = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
|
||||
if (path == null) {
|
||||
path = request.getServletPath();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user