Can I Construct a complete soap message using mule message enricher? - wso2

Using wso2 esb i can construct a complete soap message like this:
<enrich>
<source type="inline" clone="true">
<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>IBM</m0:symbol>
</m0:request>
</m0:getQuote>
</source>
<target type="body" />
</enrich>
I've read http://www.mulesoft.org/documentation/display/MULE3USER/Message+Enricher
<enricher target="#[variable:state]">
<outbound-endpoint ref="stateLookup"/>
</enricher>
I want to know how to configure to ref a inline payload or a jaxb object.
Can I ref a custom component which return a jaxb object?

If you want to replace the current message payload with a new payload coming from the result of a custom component, then just use a component not an enricher.

The syntax is something similar to below.
<enrich>
<source [clone=true|false] [type=custom|envelope|body|property|inline] xpath="" property="" />
<target [action=replace|child|sibiling] [type=custom|envelope|body|property|inline] xpath="" property="" />
</enrich>
This http://wso2.org/project/esb/java/4.0.2/docs/mediators/enrich.html will guide you further.
--
Thilini

Related

In wso2 esb how to store a multipart/form data request payload and use later in the sequene

In wso2 ESB I'm having the below request payload of multipart/formdata.
key: file value(file): image
key: data value(text): {"a":"b","c":"d"}
But first I want to store this and later I want to use this payload. How to achive this. I mean after storing this multipart/formadata request, I am doing some other processing, then at the end I am giving response as same as the request that I've stored earlier.
I tried with property but as it stores as String it while processing afterwards multipart/formadata treats it as text(encoding as UTF-8 or text),So image will
be treated as text.
I Solved the above question by first setting the property using enrich mediator and then use that property afterwards using enrich mediator. Thus it preserves the format, if we store the property using the property mediator we have to store as string or OM. So , the format will not be preserved and while running it considers image encoding also as text.
<enrich>
<source clone="false" type="body"/>
<target type="property" property="inputpayload"/>
</enrich>
.
.
.
<enrich xmlns="http://ws.apache.org/ns/synapse">
<source clone="false" property="inputpayload"/>
<target action="replace" type="body"/>
</enrich>

Eclipse removes drop mediator after send

I tried to implement a validation with FAULT in it something like this
<on-fail>
<makefault version="soap11">
<code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
<reason value="Invalid Request!!!"/>
<role/>
</makefault>
<log level="full"/>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<send/>
<drop/>
</on-fail>
therefore I added DROP after SEND what function just as I wanted (without DROP I just recived FAULT message but the process did not stop what resulted into invoking some End points with incorrect inputs)
Then I needed to check on something and I open the same sequence in Eclipse and discovered that DROP got removed.
I tried to drag and drop DROP but got an error message that the SEND mediator cannot be followed by another mediator.
why?
do you happen to know a better way how to implement SEND + DROP so there is not a risk that I lose this when I open it in Eclipse?
thx a lot!
You do not need to add a Drop Mediator after a Send. It is invalid to add any mediators after the Send mediator, since the message context will be dropped after the send. May be instead of a SEND mediator you can try adding a Respond Mediator. Your use case is not so clear.
In Eclipse Developer Studio, we cannot specify any mediator after SEND mediator/ RESPOND mediator/ DROP mediator. This is because, ideally mediation flow should not continue after those mediators.
For your case, can you try CALL mediator[1] instead of SEND mediator followed by DROP mediator as follows
<on-fail>
<makefault version="soap11">
<code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
<reason value="Invalid Request!!!"/>
<role/>
</makefault>
<log level="full"/>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<call/>
<drop/>
</on-fail>
https://docs.wso2.com/display/ESB490/Call+Mediator

Rebuilding the initial message using the payload factory mediator

I'm involved in a proxy service development using WSO2.
In my sequence I've saved the initial current message in a property using the following:
<property name="InitialMessage" expression="$body" scope="default" type="STRING"/>
and now I need to rebuild the initial message using the payload factory mediator. Am I right? What are some considerable alternatives?
Could someone show me the right syntax in this case?
yes your method is correct, But I would suggest you to save only the required properties from your incoming message and use them in building the new message. Sample Syntax is given below
<payloadfactory>
<format>
<m:checkpriceresponse xmlns:m="http://services.samples/xsd">
<m:code>$1</m:code>
<m:price>$2</m:price>
</m:checkpriceresponse>
</format>
<args>
<arg expression="//m0:symbol" xmlns:m0="http://services.samples/xsd">
<arg expression="//m0:last" xmlns:m0="http://services.samples/xsd">
</arg></arg></args>
</payloadfactory>
I've solved my problem using the enrich mediator: Here you are how ...
I've saved my initial message in a property InitialMessage in this manner ...
<property name="InitialMessage" expression="$body" scope="default" type="STRING"/>
and after I've used the enrich mediator in this manner
<enrich>
<source type="property" clone="true" property="InitialMessage"/>
<target type="body"/>
</enrich>
It's working ...
I hope this could be useful ...

Out Sequence -- Enrich mediator is not working as expected

I trying to build a application which includes service chaining. When i try to merge the responses and do the extra transformation on the merged response.. i see unintended response.I see the response i merged along with my xslt transformation outcome
For example:
If i have added "abc" to my existing outcome using enrich -> sibling to body option, after i do transformation, i still see "abc" getting appended.
Please see my code below
<enrich>
<source clone="false" type="custom" xpath="get-property('poecResp')"/>
<target action="sibling" type="body"/>
</enrich>
<log category="INFO" level="full" separator=","/>
<xslt key="conf:Response_V1.xslt"/>
<log category="INFO" level="full" separator=","/>
in the last log i print i see the sibling i added still remains.
I see the issue is with xslt. i should choose the "Source XPATH". But not sure still why my Enrich component is not working.

wso2: Looking for XSLT transformation working example

Can some one point me to a working example of xsl transformation using the proxy services xslt mediator option.
Basically, my requirement is, i will have a request where i will get some data which determines the routing and after that from other elements of requested data i have to re frame soap request to trigger another bpel service.
Please let me know the better approach to this.
You can very well use XSLT transformation in your sequence, using XSLT Mediator.
In your sequence file you can specify the XSLT file to tranform the request. Sample sequence code snippet:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="SampleInterceptorSequence">
<in>
<log level="full" category="DEBUG">
<property name="sequence" value="inSequence-Request Before XSLT" />
</log>
<xslt key="RequestTranformerXSLT" />
<log level="full" category="DEBUG">
<property name="sequence" value="inSequence-Request After XSLT" />
</log>
<send>
<endpoint key="MyActualServiceEPR" />
</send>
</in>
Your xslt would contain the style for the actual request to be formed for hitting the end point reference.
Further if you can check this nice article of web service chaining to get a real time idea of xslt mediation.
Web Service Chaining from WSO2 ESB Developers
Hope this helps.
Thanks.
Find the sample below..
http://wso2.org/project/esb/java/4.0.0/docs/samples/message_mediation_samples.html#Sample8