diff --git a/core/src/main/java/org/apache/struts2/util/StrutsUtil.java b/core/src/main/java/org/apache/struts2/util/StrutsUtil.java index 727d67a26..c693599e7 100644 --- a/core/src/main/java/org/apache/struts2/util/StrutsUtil.java +++ b/core/src/main/java/org/apache/struts2/util/StrutsUtil.java @@ -18,13 +18,10 @@ */ package org.apache.struts2.util; -import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ObjectFactory; -import com.opensymphony.xwork2.ognl.OgnlUtil; import com.opensymphony.xwork2.util.ClassLoaderUtil; import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; -import ognl.OgnlException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.StrutsException; @@ -62,7 +59,6 @@ public class StrutsUtil { protected HttpServletRequest request; protected HttpServletResponse response; protected Map> classes = new HashMap<>(); - protected OgnlUtil ognl; protected ValueStack stack; private final UrlHelper urlHelper; @@ -72,7 +68,6 @@ public class StrutsUtil { this.stack = stack; this.request = request; this.response = response; - this.ognl = stack.getActionContext().getContainer().getInstance(OgnlUtil.class); this.urlHelper = stack.getActionContext().getContainer().getInstance(UrlHelper.class); this.objectFactory = stack.getActionContext().getContainer().getInstance(ObjectFactory.class); } @@ -124,13 +119,11 @@ public class StrutsUtil { } public Object findValue(String expr, Object context) { + stack.push(context); try { - return ognl.getValue(expr, ActionContext.getContext().getContextMap(), context); - } catch (OgnlException e) { - if (e.getReason() instanceof SecurityException) { - LOG.error(format("Could not evaluate this expression due to security constraints: [{0}]", expr), e); - } - return null; + return stack.findValue(expr, true); + } finally { + stack.pop(); } } diff --git a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java index 7d594569b..4b7fd4bc0 100644 --- a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java +++ b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java @@ -33,7 +33,6 @@ import freemarker.template.TemplateModelException; import org.apache.commons.lang3.ObjectUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsStatics; import org.apache.struts2.result.StrutsResultSupport; @@ -207,7 +206,7 @@ public class FreemarkerResult extends StrutsResultSupport { * @throws TemplateException in case of freemarker configuration errors */ protected Configuration getConfiguration() throws TemplateException { - return freemarkerManager.getConfiguration(ServletActionContext.getServletContext()); + return freemarkerManager.getConfiguration(ActionContext.getContext().getServletContext()); } /** @@ -244,7 +243,7 @@ public class FreemarkerResult extends StrutsResultSupport { if (writer != null) { return writer; } - return ServletActionContext.getResponse().getWriter(); + return ActionContext.getContext().getServletResponse().getWriter(); } /** @@ -261,7 +260,6 @@ public class FreemarkerResult extends StrutsResultSupport { *
  • request - the HttpServletRequst object for direct access *
  • response - the HttpServletResponse object for direct access *
  • stack - the OgnLValueStack instance for direct access - *
  • ognl - the instance of the OgnlTool *
  • action - the action itself *
  • exception - optional : the JSP or Servlet exception as per the servlet spec (for JSP Exception pages) *
  • struts - instance of the StrutsUtil class @@ -271,9 +269,9 @@ public class FreemarkerResult extends StrutsResultSupport { * @throws TemplateModelException in case of errors during creating the model */ protected TemplateModel createModel() throws TemplateModelException { - ServletContext servletContext = ServletActionContext.getServletContext(); - HttpServletRequest request = ServletActionContext.getRequest(); - HttpServletResponse response = ServletActionContext.getResponse(); + ServletContext servletContext = ActionContext.getContext().getServletContext(); + HttpServletRequest request = ActionContext.getContext().getServletRequest(); + HttpServletResponse response = ActionContext.getContext().getServletResponse(); ValueStack stack = ActionContext.getContext().getValueStack(); Object action = null; @@ -321,7 +319,7 @@ public class FreemarkerResult extends StrutsResultSupport { protected boolean preTemplateProcess(Template template, TemplateModel model) throws IOException { Object attrContentType = template.getCustomAttribute("content_type"); - HttpServletResponse response = ServletActionContext.getResponse(); + HttpServletResponse response = ActionContext.getContext().getServletResponse(); if (response.getContentType() == null) { if (attrContentType != null) { response.setContentType(attrContentType.toString()); @@ -349,7 +347,7 @@ public class FreemarkerResult extends StrutsResultSupport { } private boolean isInsideActionTag() { - Object attribute = ServletActionContext.getRequest().getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION); + Object attribute = ActionContext.getContext().getServletRequest().getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION); return (Boolean) ObjectUtils.defaultIfNull(attribute, Boolean.FALSE); } diff --git a/core/src/main/java/org/apache/struts2/views/jsp/ui/OgnlTool.java b/core/src/main/java/org/apache/struts2/views/jsp/ui/OgnlTool.java deleted file mode 100644 index bb9d2b5b8..000000000 --- a/core/src/main/java/org/apache/struts2/views/jsp/ui/OgnlTool.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.struts2.views.jsp.ui; - -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.ognl.OgnlUtil; -import ognl.OgnlException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * @deprecated since 6.3.0. Use {@link org.apache.struts2.util.StrutsUtil} instead. - */ -@Deprecated -public class OgnlTool { - - private static final Logger LOG = LogManager.getLogger(OgnlTool.class); - - private OgnlUtil ognlUtil; - - public OgnlTool() { - } - - @Inject - public void setOgnlUtil(OgnlUtil ognlUtil) { - this.ognlUtil = ognlUtil; - } - - /** - * @deprecated since 6.3.0. Use {@link org.apache.struts2.util.StrutsUtil#findValue(String, Object)} instead. - */ - @Deprecated - public Object findValue(String expr, Object context) { - try { - return ognlUtil.getValue(expr, ActionContext.getContext().getContextMap(), context); - } catch (OgnlException e) { - if (e.getReason() instanceof SecurityException) { - LOG.error("Could not evaluate this expression due to security constraints: [{}]", expr, e); - } - return null; - } - } -} diff --git a/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java b/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java index 97c148f37..4ab3c2786 100644 --- a/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java +++ b/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java @@ -36,7 +36,6 @@ public class ContextUtil { public static final String SESSION = "session"; public static final String BASE = "base"; public static final String STACK = "stack"; - public static final String OGNL = "ognl"; public static final String STRUTS = "struts"; public static final String ACTION = "action"; @@ -49,7 +48,6 @@ public class ContextUtil { map.put(STACK, stack); StrutsUtil util = new StrutsUtil(stack, req, res); map.put(STRUTS, util); - map.put(OGNL, util); // Deprecated since 6.3.0 ActionInvocation invocation = stack.getActionContext().getActionInvocation(); if (invocation != null) { diff --git a/core/src/main/resources/struts-beans.xml b/core/src/main/resources/struts-beans.xml index 3dcd60197..91fb65db7 100644 --- a/core/src/main/resources/struts-beans.xml +++ b/core/src/main/resources/struts-beans.xml @@ -200,9 +200,6 @@ - - - request - the HttpServletRequst object for direct access *
  • response - the HttpServletResponse object for direct access *
  • stack - the OgnLValueStack instance for direct access - *
  • ognl - the instance of the OgnlTool *
  • action - the action itself *
  • exception - optional : the JSP or Servlet exception as per the * servlet spec (for JSP Exception pages) @@ -255,11 +254,10 @@ public class PortletFreemarkerResult extends StrutsResultSupport { * @throws TemplateModelException in case of template model errors */ protected TemplateModel createModel() throws TemplateModelException { - ServletContext servletContext = ServletActionContext - .getServletContext(); + ServletContext servletContext = ServletActionContext.getServletContext(); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); - ValueStack stack = ServletActionContext.getContext().getValueStack(); + ValueStack stack = ServletActionContext.getActionContext().getValueStack(); return freemarkerManager.buildTemplateModel(stack, invocation.getAction(), servletContext, request, response, wrapper); } diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java index 7acb9bdc1..2b9e00191 100644 --- a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java +++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java @@ -57,7 +57,6 @@ import static java.lang.String.format; import static java.util.Collections.emptyList; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; -import static org.apache.struts2.views.util.ContextUtil.OGNL; import static org.apache.struts2.views.util.ContextUtil.STRUTS; /** @@ -133,7 +132,6 @@ public class VelocityManager { ContextUtil.getStandardContext(stack, req, res).forEach(context::put); VelocityStrutsUtil util = new VelocityStrutsUtil(velocityEngine, context, stack, req, res); context.put(STRUTS, util); - context.put(OGNL, util); // Deprecated since 6.3.0 return context; } diff --git a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java index b86ff2eec..4ff6079b4 100644 --- a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java +++ b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/VelocityManagerTest.java @@ -94,7 +94,6 @@ public class VelocityManagerTest extends StrutsJUnit4TestCase { assertNotNull(context); assertThat(context.get("struts")).isInstanceOf(VelocityStrutsUtil.class); - assertThat(context.get("ognl")).isInstanceOf(VelocityStrutsUtil.class); // Deprecated since 6.3.0 assertThat(context.get("stack")).isInstanceOf(ValueStack.class); assertThat(context.get("request")).isInstanceOf(HttpServletRequest.class); assertThat(context.get("response")).isInstanceOf(HttpServletResponse.class);