为要由Mule客户端发送的消息设置会话属性

时间:2014-05-01 23:04:28

标签: mule

我正在尝试在FunctionalTestCase方法中的DefaultMuleMessage上设置会话属性,如下所示:

    @Test
public void ProcessActivityTest() throws Exception{

    MuleClient client = new MuleClient(muleContext);

    Activity activity = new Activity(EdusTestService.buildActivity().toString());

    DefaultMuleMessage message = new DefaultMuleMessage(activity, muleContext);
    message.setSessionProperty("edusKey", "1234567890");

    MuleMessage result = client.send("vm://processActivity?connector=inMemoryVMQueue",  message);

    System.out.println(result.getPayload().getClass().toString());
    System.out.println(result.getPayloadAsString());
    System.out.println(result.getExceptionPayload().getException().getMessage());

    assertEquals("{\"activity\":{}}", result.getPayloadAsString());

}

但是,我一直收到以下IllegalStateException:

java.lang.IllegalStateException: Detected an attempt to set a invocation 
or session property, but a MuleEvent hasn't been created using this message 
yet. Key/value: edusKey=1234567890

如何设置要在此FunctionalTestCase方法中使用的Session属性?

2 个答案:

答案 0 :(得分:1)

您可以使用测试事件并使用您的流程处理:

DefaultMuleMessage message = new DefaultMuleMessage(activity, muleContext);
MuleEvent event = getTestEvent(message);
event.setSessionVariable("edusKey", "1234567890");
Flow flow = (Flow) getFlowConstruct("my-flow");
MuleEvent responseEvent = flow.process(event);
responseEvent.getMessageAsString();

答案 1 :(得分:0)

SESSION作用域属性旨在内部使用Mule流,而不是通过客户端在外部使用。通过将属性范围设置为OUTBOUND,Mule将在收到消息后将该属性复制到消息的INBOUND属性。

HTH