问题
I'm trying to customize my application to handle an exception throwed by webflow, the exception is SpelEvaluationException an especialization of EvaluationException. According with the documentation I implemented the interface FlowExecutionExceptionHandler and stayed like below:
@Named
public class PerfilExceptionHandler implements FlowExecutionExceptionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(PerfilExceptionHandler.class);
@Override
public boolean canHandle(final FlowExecutionException exception) {
return exception.getCause() instanceof EvaluationException;
}
@Override
public void handle(final FlowExecutionException exception, final RequestControlContext context) {
LOGGER.info("handling exception {}", exception.getMessage());
TransitionExecutingFlowExecutionExceptionHandler handler = new TransitionExecutingFlowExecutionExceptionHandler();
handler.add(CustomException.class, "error");
}
}
Then I have been received a NullPoinerException, follows the stacktrace:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
br.com.company.portal.web.filter.NegarAcessoSemPerfilAtivoFilter.doFilterInternal(NegarAcessoSemPerfilAtivoFilter.java:49)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:65)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.security.config.debug.DebugFilter.invokeWithWrappedRequest(DebugFilter.java:69)
org.springframework.security.config.debug.DebugFilter.doFilter(DebugFilter.java:58)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96
If someone can help me, I'm apreciated
Edit 1
Prasad
Follows the code:
<view-state id="perfil" view="/perfil/add">
<on-entry>
<set name="flowScope.urlRedirect" value="requestParameters.url"/>
<set name="flowScope.mapSistemaPerfis" value="perfilServiceImpl.buscarSistemasComPefis(requestParameters.identificador, requestParameters.idProduto)" />
</on-entry>
<transition on="submit" to="savePerfil" />
<exception-handler bean="perfilExceptionHandler"/>
</view-state>
The error occurs when an user doesn't pass the request parameters required to call method buscarSistemasComPerfis
Tks in advance
回答1:
Instead of implementing FlowExecutionExceptionHandler, try extending TransitionExecutingFlowExecutionExceptionHandler like below:
public class PerfilExceptionHandler extends
TransitionExecutingFlowExecutionExceptionHandler {
Also, you have given
handler.add(CustomException.class, "error");
- Have you defined target state id "error" in your webflow definition?
- Using add() inside TransitionExecutingFlowExecutionExceptionHandler.exposeException() method definition would be useful for identifying target state id for a particular exception.
回答2:
Ivan,
Since requestparameters is not present, when spel parser get the expression, it will see like:
perfilServiceImpl.buscarSistemasComPefis(,);
and so you get SpelEvaluationException. The work around to handle this type of scenario is:
<view-state id="perfil" view="/perfil/add">
<on-entry>
<set name="flowScope.urlRedirect" value="requestParameters.url"/>
<set name="requestScope.identificador" value="requestParameters.identificador" type="string"/>
<set name="requestScope.idProduto" value="requestParameters.idProduto" type="string"/>
<set name="flowScope.mapSistemaPerfis" value="perfilServiceImpl.buscarSistemasComPefis(requestScope.identificador, requestScope.idProduto)" />
</on-entry>
<transition on="submit" to="savePerfil" />
<exception-handler bean="perfilExceptionHandler"/>
This way even if requestParameters is not passed, your method receives the parameters as null values, which you can handle accordingly.
来源:https://stackoverflow.com/questions/22506859/how-implement-the-interface-flowexecutionexceptionhandler