Announcement Announcement Module
Collapse
No announcement yet.
trouble persisting flow execution in DB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • trouble persisting flow execution in DB

    The first evident way is to inherit from one of existing repositories, overriding methods, storing and restoring execution. FlowExecution successfully stores as blob and restores too, but exception occurs when accessing flow scope (mapping flow output params). May be overriding 2 methods is not enough?
    Code, schema and stack trace look as following:

    public class MyFlowExecutionRepository extends DefaultFlowExecutionRepository {

    private MyFlowExecutionRepository(FlowExecutionRepositoryS ervices arg0) {
    super(arg0);
    }

    public void putFlowExecution(FlowExecutionKey key, FlowExecution flowExecution){
    Connection con = ....;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(asImpl(flowExecution));

    // serialize the employee object into a byte array
    byte[] flowAsBytes = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(flowAsBytes);

    // Insert into DB
    PreparedStatement pstmt = con
    .prepareStatement("INSERT INTO flow_repository(flow_key, flow) VALUES(?, ?)");
    pstmt.setString(1, key.toString());
    pstmt.setBinaryStream(2, bais, flowAsBytes.length);

    pstmt.executeUpdate();
    pstmt.close();
    }

    public FlowExecution getFlowExecution(FlowExecutionKey key){
    FlowExecution flow = null;
    Statement stmt;
    ResultSet rs;
    Connection con = ...;

    stmt = con.createStatement();
    rs = stmt
    .executeQuery("SELECT flow FROM flow_repository WHERE flow_key = '"
    + key.toString() + "'");

    while (rs.next()) {
    Blob blb = rs.getBlob("flow");
    InputStream baip = blb.getBinaryStream();
    ObjectInputStream ois = new ObjectInputStream(baip);
    // re-create the object
    flow = rehydrate((FlowExecution) ois.readObject(), key);
    }
    return flow;
    }


    public static MyFlowExecutionRepository getInstance(FlowLocator locator){
    if(instance == null){
    instance = new MyFlowExecutionRepository(new FlowExecutionRepositoryServices(locator));
    }

    return instance;
    }

    private static MyFlowExecutionRepository instance = null;
    }

    <flow start-state="displayClientForm">
    <view-state id="displayClientForm" view="IdentifyClient.jsp">
    <transition on="submit" to="storeClient">
    <action bean="clientFormAction" method="bindAndValidate"/>
    </transition>
    </view-state>

    <action-state id="storeClient">
    <action bean="clientFormAction" method="storeClient"/>
    <transition to="finish"/>
    </action-state>

    <end-state id="finish">
    <output-mapper>
    <mapping source="${flowScope.clientId}" target="clientId"/>
    </output-mapper>
    </end-state>
    </flow>

    java.lang.NullPointerException
    org.springframework.webflow.execution.impl.Request ControlContextImpl.getModel(RequestControlContextI mpl.java:153)
    org.springframework.webflow.support.ApplicationVie wSelector.createApplicationView(ApplicationViewSel ector.java:123)
    org.springframework.webflow.support.ApplicationVie wSelector.makeRefreshSelection(ApplicationViewSele ctor.java:104)
    org.springframework.webflow.support.ApplicationVie wSelector.makeSelection(ApplicationViewSelector.ja va:95)
    org.springframework.webflow.ViewState.doEnter(View State.java:89)
    org.springframework.webflow.State.enter(State.java :194)
    org.springframework.webflow.Transition.execute(Tra nsition.java:220)
    org.springframework.webflow.TransitionableState.on Event(TransitionableState.java:102)
    org.springframework.webflow.Flow.onEvent(Flow.java :603)
    org.springframework.webflow.execution.impl.Request ControlContextImpl.signalEvent(RequestControlConte xtImpl.java:199)
    org.springframework.webflow.ActionState.doEnter(Ac tionState.java:180)
    org.springframework.webflow.State.enter(State.java :194)
    org.springframework.webflow.Flow.start(Flow.java:5 88)
    org.springframework.webflow.execution.impl.Request ControlContextImpl.start(RequestControlContextImpl .java:187)
    org.springframework.webflow.SubflowState.doEnter(S ubflowState.java:116)
    org.springframework.webflow.State.enter(State.java :194)
    org.springframework.webflow.Transition.execute(Tra nsition.java:220)
    org.springframework.webflow.TransitionableState.on Event(TransitionableState.java:102)

    as i suppose, the problem is that getConversationScope() call inside getModel() returns null. But why it return null?
    If i remove output param mapping, flow ends successfully.

    Help please, if anybeody have idea =)
    Last edited by tort; Jul 18th, 2006, 09:56 AM. Reason: title was not clear enough

  • #2
    solved

    problem solved.
    the key point was ConversationScope of FlowExecution is transient and is null after rehydration. But if you use input-output mapping, Web Flow accesses it and throws NullPointerException.

    Comment

    Working...
    X