如何实现FlowExecutionExceptionHandler接口

时间:2014-03-19 13:08:31

标签: spring spring-webflow

我试图自定义我的应用程序来处理Webflow抛出的异常,例外是 SpelEvaluationException EvaluationException 的特殊化。根据文档,我实现了接口 FlowExecutionExceptionHandler ,并保持如下:

@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");
}

}

然后我收到了一个N​​ullPoinerException,跟随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

如果有人可以帮助我,我就是apreciated

修改1

普拉萨德

遵循以下代码:

<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>

当用户未传递调用方法 buscarSistemasComPerfis

所需的请求参数时,会发生错误

事先提前

2 个答案:

答案 0 :(得分:2)

不要实现FlowExecutionExceptionHandler,而是尝试扩展TransitionExecutingFlowExecutionExceptionHandler,如下所示:

public class PerfilExceptionHandler extends
        TransitionExecutingFlowExecutionExceptionHandler {

另外,你已经给出了

handler.add(CustomException.class, "error");
  1. 您是否定义了目标州ID&#34; 错误&#34;在您的Webflow定义中?
  2. 在TransitionExecutingFlowExecutionExceptionHandler中使用add()。 exposeException()方法定义对于识别特定异常的目标状态ID非常有用。

答案 1 :(得分:0)

伊万,

由于请求参数不存在,当spel解析器获得表达式时,它将看起来像:

     perfilServiceImpl.buscarSistemasComPefis(,);

所以你得到了SpelEvaluationException。 处理这种情况的工作是:

<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"/>

这种方式即使未传递requestParameters,您的方法也会将参数作为空值接收,您可以相应地处理这些参数。