Skip to content

Spring State Machine Error Handling not working #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
CodeYogiCo opened this issue Apr 5, 2018 · 3 comments
Open

Spring State Machine Error Handling not working #548

CodeYogiCo opened this issue Apr 5, 2018 · 3 comments

Comments

@CodeYogiCo
Copy link

I am getting an exception

org.springframework.security.access.AccessDeniedException: Access is denied
	at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:84)
	at org.springframework.statemachine.security.StateMachineSecurityInterceptor.decide(StateMachineSecurityInterceptor.java:190)
	at org.springframework.statemachine.security.StateMachineSecurityInterceptor.decide(StateMachineSecurityInterceptor.java:157)
	at org.springframework.statemachine.security.StateMachineSecurityInterceptor.preTransition(StateMachineSecurityInterceptor.java:109)
	at org.springframework.statemachine.support.StateMachineInterceptorList.preTransition(StateMachineInterceptorList.java:128)
	at org.springframework.statemachine.support.DefaultStateMachineExecutor.handleTriggerTrans(DefaultStateMachineExecutor.java:266)
	at org.springframework.statemachine.support.DefaultStateMachineExecutor.handleTriggerTrans(DefaultStateMachineExecutor.java:211)
	at org.springframework.statemachine.support.DefaultStateMachineExecutor.processTriggerQueue(DefaultStateMachineExecutor.java:449)
	at org.springframework.statemachine.support.DefaultStateMachineExecutor.access$200(DefaultStateMachineExecutor.java:65)
	at org.springframework.statemachine.support.DefaultStateMachineExecutor$1.run(DefaultStateMachineExecutor.java:323)
	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
	at org.springframework.statemachine.support.DefaultStateMachineExecutor.scheduleEventQueueProcessing(DefaultStateMachineExecutor.java:352)
	at org.springframework.statemachine.support.DefaultStateMachineExecutor.execute(DefaultStateMachineExecutor.java:163)
	at org.springframework.statemachine.support.AbstractStateMachine.sendEventInternal(AbstractStateMachine.java:603)
	at org.springframework.statemachine.support.AbstractStateMachine.sendEvent(AbstractStateMachine.java:218)
	at org.springframework.statemachine.support.AbstractStateMachine.sendEvent(AbstractStateMachine.java:230)

This behavior is as expected by application based on spring security. However i want to catch this exception throw it back to my api user. For the same I have written a custom listener.

public class ErrorStateMachineListener
    extends StateMachineListenerAdapter<AgreementSubStatus, AgreementEvents> {

  @Override
  public void stateMachineError(
      StateMachine<AgreementSubStatus, AgreementEvents> stateMachine, Exception exception) {
    //System.out.println("here i am -------------");
    //throw new IllegalStateTransitionException("Illegal state transition.");
  }

 @Override
  public void stateEntered(State<AgreementSubStatus, AgreementEvents> state){
   //System.out.println("here i am 2-------------"+state.getId().name());
 }
}

And registered this listener in


    builder
                .configureConfiguration()
                .withConfiguration()
                .listener(new ErrorStateMachineListener())
                .autoStartup(true)
                .and()
                .withSecurity()
                .enabled(true);

However the control never goes to this method --public void stateMachineError

@esanchezros
Copy link

Any feedback on this issue? We are having the same problem as described here. Ideally we'd like to register a global error handler that deals with exceptions rather than littering the transition configuration with , errorAction)

@tovisofer
Copy link

Hi,
I saw similar question\bug report mentioned three times.
Is anyone handling it?

#553
#340

@banderous
Copy link

Running into this in 2020 and it's a blocker to adoption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants