0

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

2
  • Hi, can you post in what scenario you are getting SpelEvaluationException because this will occur when the expression is incorrect or making a reference of incorrect field. It would be ideal to handle this scenario in first place. Commented Mar 19, 2014 at 13:52
  • Prasad I edited the post Commented Mar 19, 2014 at 14:28

2 Answers 2

2

Instead of implementing FlowExecutionExceptionHandler, try extending TransitionExecutingFlowExecutionExceptionHandler like below:

public class PerfilExceptionHandler extends
        TransitionExecutingFlowExecutionExceptionHandler {

Also, you have given

handler.add(CustomException.class, "error");
  1. Have you defined target state id "error" in your webflow definition?
  2. Using add() inside TransitionExecutingFlowExecutionExceptionHandler.exposeException() method definition would be useful for identifying target state id for a particular exception.
Sign up to request clarification or add additional context in comments.

3 Comments

Im also facing similar issue can you guide
i have tried and failed to implement the same.
0

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.

6 Comments

Prasad, my problem doesn't the SpelEvaluationException. I don't care with what exception will be throw, but, I care with NullPointerException when I handle the flow execution after execution of method handle(FlowExecutionException,RequestControlContext). I tested setting up the request parameters on request scope, but, the problem continues
Can you check by turning on debug mode if at all the request is entering perfilServiceImpl.buscarSistemasComPefis(requestScope.identificador, requestScope.idProduto) method?
I put in debug mode, but, I didn't see anything different. I put a breakpoint and the method perfilServiceImpl.buscarSistemasComPefis(requestScope.identificador, requestScope.idProduto) didn't called. Maybe this part can be useful handling exception Exception thrown executing [AnnotatedAction@35c86c73 targetAction = [SetAction@79480d9a name = flowScope.mapSistemaPerfis, value = perfilServiceImpl.buscarSistemasComPefis(requestScope.identificador, requestScope.idProduto)], attributes = map[[empty]]] in state 'perfil' of flow 'perfil' -- action execution attributes were 'map[[empty]]'
This exception could happen in tons of ways. Remove <exception-handler bean="perfilExceptionHandler"/>, run the flow and then can you post the exception stacktrace, you are getting?
@Prasad can you guide me similar issue i also have
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.