struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JOSE L MARTINEZ-AVIAL <jlm...@gmail.com>
Subject json result type not parse OGNL expressions in params
Date Sun, 21 Oct 2012 07:12:07 GMT
Hi,
I'm using a json result type defined as follows:

<result-type name="json-action" class="org.apache.struts2.json.JSONResult">
<param name="ignoreHierarchy">false</param>
<param
name="includeProperties">resultName,resultMessage,data.*,fieldErrors.*,actionErrors.*,actionMessages.*</param>
<param name="excludeNullProperties">true</param>
<param name="noCache">true</param>
<param name="errorCode">${errorCode}</param>
</result-type>

Everything works great, except the parameter errorCode. I populated the
errorCode in the ValueStack doing:

invocation.getStack().set("errorCode", errorCode);

where errorCode is an int. But the errorcode is not been setup in the
response, and in fact I can see the following stacktrace:
2012-10-21 02:54:01,060 INFO  com.opensymphony.xwork2.ObjectFactory  -
Exception
Caught OgnlException while setting property 'errorCode' on type
'org.apache.struts2.json.JSONResult'. - Class: ognl.OgnlRuntime
File: OgnlRuntime.java
Method: callAppropriateMethod
Line: 1226 - ognl/OgnlRuntime.java:1226:-1
        at
com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:412)
        at
com.opensymphony.xwork2.ognl.OgnlUtil.setProperty(OgnlUtil.java:160)
        at
com.opensymphony.xwork2.ognl.OgnlReflectionProvider.setProperty(OgnlReflectionProvider.java:91)
        at
com.opensymphony.xwork2.ObjectFactory.buildResult(ObjectFactory.java:243)
        at
com.opensymphony.xwork2.DefaultActionInvocation.createResult(DefaultActionInvocation.java:223)
        at
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:372)
        at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:282)
        at
com.spb.mvc.security.authentication.web.RedirectToLoginInterceptor.intercept(RedirectToLoginInterceptor.java:28)
        at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
        at
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
        at
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498)
        at
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
        at
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
        at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
        at
com.spb.eco.security.auditory.web.Log4jSessionIdFilter.doFilter(Log4jSessionIdFilter.java:47)
        at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
        at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
        at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(Unknown Source)
        at
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
        at
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
        at
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: java.lang.NoSuchMethodException:
org.apache.struts2.json.JSONResult.setErrorCode(java.lang.String)
        at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1226)
        at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1474)
        at
ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85)
        at
ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162)
        at
com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27)
        at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2245)
        at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
        at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
        at ognl.SimpleNode.setValue(SimpleNode.java:301)
        at ognl.Ognl.setValue(Ognl.java:737)
        at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:209)
        at
com.opensymphony.xwork2.ognl.OgnlUtil.internalSetProperty(OgnlUtil.java:405)

So it seems it is trying to setup the errorCode with the string
${errorCode}, instead of parsing the OGNL expression. I found a similar
question on StackOverflow
http://stackoverflow.com/questions/4372498/dynamic-wrapprefix-for-json-result-type-in-struts2,
where somebody sees that the jsonResult does not parse the parameters. But
for example the result type httpheader does parse OGNL expression, so is
there any way I can get the json type to parse the parameter value?

Thanjks

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message