Re: Custom error result for ExceptionMappingInterceptor
Another option would be to extend the ExceptionMappingInterceptor and override the findResultFromExceptions method. In the overriden method you can do your checks and return a global result accordingly Antonios On 20 October 2012 21:35, JOSE L MARTINEZ-AVIAL jlm...@gmail.com wrote: Hi, I want to use ExceptionMappingInterceptor to manage any exception thrown while processing a request. The issue I have is that I want to map the action to diferent results depending on some parameters of the request. More specifically, the browser's client can send three diferent types of request to my app: FullScreen - It's a full navigation, i.e., the browser goes to a diferent URL. In this case all the screen is reloaded, obviously. PaneScreen - Part of the screen is updated using HTML code ( the result of a JSP). The request is done using AJAX, so there is no navigation in the formal sense. AJAX/JSON - The page retrieves some information from the server in JSON format using AJAX. There is also no navigation. The problem I have is that depending on the type of navigation (And I can know that looking at the headers and the namespace of the action request) I need to send diferent error results to the client. If it's a FullScreen request I need to send a full error page. If it's a PaneScreen request, then only a handful of HTML needs to be sent, since it only affects the pane that send the request. Last, but not least, if it is a AJAX/JSON screen I want to send a 500 error code with specific information in JSON format so a meaningful message can be shown to the user. After researching a bit, it seems my only options are to chain an HandleExceptionAction to the ExceptionMappingInterceptor result, so the action can send the correct result to the user ( http://stackoverflow.com/questions/5746941/mapping-struts-2-exception-handler-to-an-action ), or implement my own version of ExceptionMappingInterceptor. Is there any other option I am missing? thanks K:
Re: json result type not parse OGNL expressions in params
I just reviewed the code, and it seems that the HttpHeaderResult only parses the parameters headers and errorMessage, but not the parameters status or error. I think it could be a nice thing to have. my workaround is to extend JSONResult incorporating the following: public void setStatusCode(String statusCode) { ValueStack stack = ActionContext.getContext().getValueStack(); setStatusCode(Integer.parseInt(TextParseUtil.translateVariables(statusCode, stack))); } public void setErrorCode(String errorCode) { ValueStack stack = ActionContext.getContext().getValueStack(); setErrorCode(Integer.parseInt(TextParseUtil.translateVariables(errorCode, stack))); } It works fine but I think that this feature should be incorporated to all parameters. I would like to know opinions from other people before opening a jira issue for this. JL 2012/10/21 JOSE L MARTINEZ-AVIAL jlm...@gmail.com Hi, I'm using a json result type defined as follows: result-type name=json-action class=org.apache.struts2.json.JSONResult param name=ignoreHierarchyfalse/param param name=includePropertiesresultName,resultMessage,data.*,fieldErrors.*,actionErrors.*,actionMessages.*/param param name=excludeNullPropertiestrue/param param name=noCachetrue/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
Re: json result type not parse OGNL expressions in params
Hi, On Sunday 21 October 2012 03:12:07 JOSE L MARTINEZ-AVIAL wrote: Hi, I'm using a json result type defined as follows: result-type name=json-action class=org.apache.struts2.json.JSONResult param name=ignoreHierarchyfalse/param param name=includePropertiesresultName,resultMessage,data.*,fieldErrors.*,actio nErrors.*,actionMessages.*/param param name=excludeNullPropertiestrue/param param name=noCachetrue/param param name=errorCode${errorCode}/param /result-type I don't know if it makes a difference, but I use %{ } in the param tag to get the values from my actions. Regards, Pascal - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: json result type not parse OGNL expressions in params
I just tried that, but it does not make any difference. 2012/10/21 Per Pascal Grube cyber...@flightmare.net Hi, On Sunday 21 October 2012 03:12:07 JOSE L MARTINEZ-AVIAL wrote: Hi, I'm using a json result type defined as follows: result-type name=json-action class=org.apache.struts2.json.JSONResult param name=ignoreHierarchyfalse/param param name=includePropertiesresultName,resultMessage,data.*,fieldErrors.*,actio nErrors.*,actionMessages.*/param param name=excludeNullPropertiestrue/param param name=noCachetrue/param param name=errorCode${errorCode}/param /result-type I don't know if it makes a difference, but I use %{ } in the param tag to get the values from my actions. Regards, Pascal - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org