1

I need to redirect to a flow from a @Controller, but am not sure how to go about this. I need to either continue with MVC under a certain condition, or go into my flow under another condition. Here's the final line of my /auth method:

return new ModelAndView(isFlowProtected(getClientId(sessionDataPayloadJSON)) ?
    "redirect:/login-flow" :
    LoginConstants.LOGIN);

Essentially, I have two login flows, one through normal Spring MVC, one under webflow. Here's how I configured my flow:

@Bean
public FlowDefinitionRegistry flowRegistry() {
    return getFlowDefinitionRegistryBuilder().addFlowLocation("/webflow/login-flow.xml","login-flow"
            .setFlowBuilderServices(this.flowBuilderServices())
            .build();
}

@Bean
public FlowExecutor flowExecutor() {
    return getFlowExecutorBuilder(this.flowRegistry())
            .build();
}

@Bean
public FlowBuilderServices flowBuilderServices() {
    return getFlowBuilderServicesBuilder()
            .setViewFactoryCreator(this.mvcViewFactoryCreator()) // Important!
            .setValidator(this.localValidatorFactoryBean).build();
}

@Bean
public FlowHandlerMapping flowHandlerMapping() {
    FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
    handlerMapping.setOrder(-1);
    handlerMapping.setFlowRegistry(this.flowRegistry());
    return handlerMapping;
}

@Bean
public FlowHandlerAdapter flowHandlerAdapter() {
    FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter();
    handlerAdapter.setFlowExecutor(this.flowExecutor());
    handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true);
    return handlerAdapter;
}

@Bean
public ViewFactoryCreator mvcViewFactoryCreator() {
    MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
    factoryCreator.setUseSpringBeanBinding(true);
    return factoryCreator;
}

Assuming my path to my flow is correct, what am I doing wrong here? How can I redirect to the login-flow from my /auth endpoint when needed? I'm getting the following error currently:

java.io.FileNotFoundException: Could not open ServletContext resource [/webflow/login-flow.xml]

So maybe my path is wrong? The flow is inside of resources/webflow, so I think it's right, but maybe not?

Bill L
  • 2,576
  • 4
  • 28
  • 55

1 Answers1

0

Do you have a /webflow/login-flow.xml file in your WAR root directory? I think that's what that error indicates, that it can't find that file. I believe your redirect is working correctly, and your WebFlow configuration expects to find a flow configuration file at the location you specified, but it isn't finding it there.

I haven't used Java-based WebFlow configuration before, so I could be misunderstanding this, but best I read this, I think you might still need Flow xml files even when you do the rest of the configuration in Java.

See Configure Spring Web Flow with Java configuration

dbreaux
  • 4,982
  • 1
  • 25
  • 64
  • 1
    I do have that `login-flow.xml` inside the `webflow` directory, which is why I'm so confused as well. It's giving me the path I expect to see, but for some reason doesn't seem to be able to find it. – Bill L Dec 10 '18 at 17:55
  • `webflow` directory under where? You earlier said `resources/webflow`. What's the full path of the file, starting from the root of the war? – dbreaux Dec 18 '18 at 04:18