transformer - Mule returning a MessageCollection from component -
i'm having difficulty returning collection of mulemessage instances component.
mule 3.3.1.
the following code works (i.e., after component, foreach component logger dumps out "abc" , "def" expect).
public object oncall( muleeventcontext eventcontext ) throws exception { mulemessage message = eventcontext.getmessage(); mulemessagecollection collection = new defaultmessagecollection( message.getmulecontext() ); string s1 = "abc"; string s2 = "def"; defaultmulemessage m1 = new defaultmulemessage( s1, message.getmulecontext() ); defaultmulemessage m2 = new defaultmulemessage( s2, message.getmulecontext() ); list<mulemessage> list = new arraylist<mulemessage>(); list.add( m1 ); list.add( m2 ); collection.addmessages( list ); return collection; }
if, however, substitute class of own in place of strings, so:
public object oncall( muleeventcontext eventcontext ) throws exception { mulemessage message = eventcontext.getmessage(); mulemessagecollection collection = new defaultmessagecollection( message.getmulecontext() ); licenserequest s1 = new licenserequest(); licenserequest s2 = new licenserequest(); defaultmulemessage m1 = new defaultmulemessage( s1, message.getmulecontext() ); defaultmulemessage m2 = new defaultmulemessage( s2, message.getmulecontext() ); list<mulemessage> list = new arraylist<mulemessage>(); list.add( m1 ); list.add( m2 ); collection.addmessages( list ); return collection; }
i exception:
org.mule.transport.http.httpsconnector work caused exception on 'workcompleted'. work being executed was: org.mule.transport.http.httpsmessagereceiver$httpsworker@7b921c57 org.mule.exception.defaultsystemexceptionstrategy caught exception in exception strategy: payload invalidated calling setpayload , message not collection anymore. java.lang.illegalstateexception: payload invalidated calling setpayload , message not collection anymore. @ org.mule.defaultmessagecollection.checkvalidpayload(defaultmessagecollection.java:107) @ org.mule.defaultmessagecollection.newthreadcopy(defaultmessagecollection.java:312) @ org.mule.defaultmuleevent.newthreadcopy(defaultmuleevent.java:779) @ org.mule.requestcontext.newevent(requestcontext.java:140) @ org.mule.requestcontext.setexceptionpayload(requestcontext.java:121) @ org.mule.exception.abstractsystemexceptionstrategy.handleexception(abstractsystemexceptionstrategy.java:54) @ org.mule.exception.abstractsystemexceptionstrategy.handleexception(abstractsystemexceptionstrategy.java:77) @ org.mule.transport.http.httpmessagereceiver$httpworker.run(httpmessagereceiver.java:220) @ org.mule.work.workercontext.run(workercontext.java:311) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1110) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:603) @ java.lang.thread.run(thread.java:722) exception in thread "[license-generation].httpsconnector.receiver.02" java.lang.illegalstateexception: payload invalidated calling setpayload , message not collection anymore. @ org.mule.defaultmessagecollection.checkvalidpayload(defaultmessagecollection.java:107) @ org.mule.defaultmessagecollection.newthreadcopy(defaultmessagecollection.java:312) @ org.mule.defaultmuleevent.newthreadcopy(defaultmuleevent.java:779) @ org.mule.requestcontext.newevent(requestcontext.java:140) @ org.mule.requestcontext.setexceptionpayload(requestcontext.java:121) @ org.mule.exception.abstractsystemexceptionstrategy.handleexception(abstractsystemexceptionstrategy.java:54) @ org.mule.exception.abstractsystemexceptionstrategy.handleexception(abstractsystemexceptionstrategy.java:77) @ org.mule.transport.abstractconnector.handleworkexception(abstractconnector.java:2099) @ org.mule.transport.abstractconnector.workcompleted(abstractconnector.java:2067) @ org.mule.work.workercontext.run(workercontext.java:338) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1110) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:603) @ java.lang.thread.run(thread.java:722)
at point in testing, licenserequest empty class tostring() method returns "ghi".
what doing wrong?
i should add goal return collection of objects created incoming payload. can iterate on objects in calling flow , take appropriate action each.
edit: appears can want in transformer, not component. why this?
i guess not required wrap each of licenserequest object mule message , adding collection. make collection directly , return oncall method.
public object oncall( muleeventcontext eventcontext ) throws exception { mulemessage message = eventcontext.getmessage(); licenserequest s1 = new licenserequest(); licenserequest s2 = new licenserequest(); list<licenserequest> list = new arraylist<licenserequest>(); list.add( s1 ); list.add( s2 ); return list; }
hope helps.
Comments
Post a Comment