Как программно загрузить поток веб-потока Spring и получить его содержимое

Мне нужно программно загрузить существующий поток Spring-webflow в JAVA, чтобы проверить его защищенный тег.

Моя цель - проверить защищенный тег после определенных событий.

Здесь используется Spring-webflow 2.4. Мой поток выглядит примерно так:

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:ns0="http://www.w3.org/2001/XMLSchema-instance"
ns0:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">


<secured attributes="RIGHT_1,RIGHT_2" />

<view-state id="someViewState">
[...]
</view-state>

[...]

</flow>

Итак, как я могу получить «содержимое» этого потока через Spring API? Я пытался найти свой путь через классы пакета org.springframework.webflow.config, но я не нашел иголку в сене. Мне даже не удается успешно загрузить поток.

Я некоторое время работал с потоками, но мне никогда не приходилось обращаться к ним в Java Code.

Спасибо за любые подсказки.


person mondjunge    schedule 16.03.2017    source источник


Ответы (1)


Я получил это сам:

в классе, который расширяет org.springframework.web.servlet.mvc.AbstractController, вы можете сделать это:

// get the application Context
ApplicationContext context = getApplicationContext();
// get webflowController, must be configured in your webflowConfig file
FlowController controller = (FlowController)context.getBean("flowController");
FlowExecutorImpl flowExecutorImpl = (FlowExecutorImpl)controller.getFlowExecutor();
FlowDefinitionRegistryImpl flowDefinitionRegistryImpl = (FlowDefinitionRegistryImpl)flowExecutorImpl.getDefinitionLocator();

// flowId is the id of the flow you want to check
FlowDefinition flowDefinition = flowDefinitionRegistryImpl.getFlowDefinition(flowId);

MutableAttributeMap<Object> attributes = flowDefinition.getAttributes();

// finally the SecurityRule Object that you can pass to a specific AccessDecisionManager
SecurityRule securityRule = (SecurityRule)attributes.get("secured");
person mondjunge    schedule 16.03.2017
comment
вы можете использовать FlowExecutionListener - person rptmat57; 17.03.2017