Hi John, Can you explain bit more about your requirement ? Generally it is not a good practice to invoke a sequence flow within a custom mediator.
Thanks. On Thu, Jan 14, 2016 at 10:14 AM, Vijitha Ekanayake <[email protected]> wrote: > Hi John, > > As Harshan mentioned in above you can use a PayloadFactory Mediator[1] to > create the custom payload and the you can invoke sequence calling the > sequence you need to invoke. If you cannot achieve it using any inbuilt > mediator ships with ESB(payloadFactory, enrich, xslt) you can write a > class mediator and can call required sequence from that class mediator. You > can refer below CustomExampleMediator class[2] to how you can create a > custom payload and invoke a sequence from a class mediator. I’ve added > comments you to understand the code. > > > *[1]. **https://docs.wso2.com/display/ESB481/PayloadFactory+Mediator* > <https://docs.wso2.com/display/ESB481/PayloadFactory+Mediator> > > *[2]. * > > *public class *CustomExampleMediator *extends *AbstractMediator { > > *private *String *sequenceKey*; > > *// The sequence to be called when When Custom Payload Creation Completed > **public boolean *mediate(MessageContext context) { > > > *//Get the axis2MessageContext synapse message context > *org.apache.axis2.context.MessageContext > axis2MessageContext = ((Axis2MessageContext) context) > .getAxis2MessageContext(); > > *//Get Current Envelop *SOAPEnvelope axisMsgEnvelope = > axis2MessageContext.getEnvelope(); > > > *// Sequence you need to invoke *Mediator > sequenceMediatorToInvoke = *null*; > *if *(*sequenceKey *!= *null*) { > sequenceMediatorToInvoke = context > .getSequence(*sequenceKey*); > } *else *{ > *if *(*log*.isDebugEnabled()) { > *log*.debug(*"Sequence Key not specified."*); > } > } > > > *//Create a Custom Payload *OMElement customPayloadElement = > *null*; > > > > *//Your Custom Payload creation logic should be implemented here. > //Create the SOAPEnvelope and set it to the context. **try *{ > context.setEnvelope(createSOAPEnvelope(customPayloadElement)); > } *catch *(AxisFault e) { > e.printStackTrace(); > } > > sequenceMediatorToInvoke.mediate(context); > } > > *return true*; > } > > > *//method to create the SOAPEnvelope and append the payload as body > **private > *SOAPEnvelope createSOAPEnvelope(OMElement documentElement) { > SOAPEnvelope envelope; > SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory(); > envelope = soapFactory.getDefaultEnvelope(); > *if *(documentElement != *null*) { > envelope.getBody().addChild(documentElement); > } > *return *envelope; > } > > } > > Thanks. > > On Wed, Jan 13, 2016 at 12:00 PM, Harshan Liyanage <[email protected]> > wrote: > >> Hi John, >> >> The easiest way to achieve this would be to write a class mediator [1] >> and then using it in the synapse configuration. You can use >> a PayloadFactory Mediator [2] to create the custom payload. So there will >> be no need for creating the custom payload and invoking a sequence from >> inside the custom mediator. >> >> [1]. https://docs.wso2.com/display/ESB490/Class+Mediator >> [2]. https://docs.wso2.com/display/ESB490/PayloadFactory+Mediator >> >> Thanks, >> Harshan >> >> Harshan Liyanage >> Software Engineer >> Mobile: *+94724423048* >> Email: [email protected] >> Blog : http://harshanliyanage.blogspot.com/ >> *WSO2, Inc. :** wso2.com <http://wso2.com/>* >> lean.enterprise.middleware. >> >> On Wed, Jan 13, 2016 at 1:26 AM, John Q <[email protected]> wrote: >> >>> Hello, >>> Can any body tell me how can I create a custom payload and invoke a >>> sequence from a custom mediator? >>> >>> thanks, >>> john >>> >>> _______________________________________________ >>> Dev mailing list >>> [email protected] >>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>> >>> >> >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> >> > > > -- > Vijitha Ekanayake > Software Engineer*, *WSO2, Inc.; http://wso2.com/ > Mobile : +94 777 24 73 39 | +94 718 74 44 08 > lean.enterprise.middleware > -- *Isuru Udana* Associate Technical Lead WSO2 Inc.; http://wso2.com email: [email protected] cell: +94 77 3791887 blog: http://mytecheye.blogspot.com/
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
