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.
Related
I have a requirement to parse JSON response which contain array of products(P1,P2,P3,etc.). Each product contains multiple information like name, type, cost, etc.
I need to read each product one by one and append additional data got from the another service into an new JSON output. I am thinking of using ForEach component of WSO2 ESB to iterate each product one by one.
Problem is that ForEach component uses ForEachExpression which expects XML expression in the configuration.
Please suggest on the method to parse array of JSON response one by one in WSO2 ESB.
/Abhishek
Can use both Iterate or ForEach mediator for iterating the JSON array, since both are content aware mediators and support JSON.
Which one to use depends upon the specific usecase as Iterate provides the capability to use call / callout / send mediators in the sequence whereas ForEach doesn´t allow it.
For the below given sample JSON request, the following iteration works and the JSON array and objects can be referred like the same.
{
"products":[
{
"product":{
"id":"1234",
"size":"20",
"quantity":"1",
"price":"990",
"type":"Electronics",
"store":{
"id":"001"
}
}
}
]
}
<iterate expression="//products" id="PRD_ITR">
<target>
<sequence>
<sequence key="Product_Enrich_Sequence_s"/>
<!-- For example, Switching sequence based on the product type -->
<switch source="//products/product/type">
<case regex="Computer">
<sequence key="Computer_Product_Enrich_Sequence_s"/>
</case>
<case regex="Mobile">
<sequence key="Mobile_Product_Enrich_Sequence_s"/>
</case>
<case regex="Grocery">
<sequence key="GR_Product_Enrich_Sequence_s"/>
</case>
<default>
<!-- default stuff --!>
</default>
</switch>
</sequence>
</target>
</iterate>
FYR
https://docs.wso2.com/display/ESB490/Iterate+Mediator
https://docs.wso2.com/display/ESB490/ForEach+Mediator
Note: tested in WSO2 ESB 4.9.0
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
I am using the inline javascript prototype feature in the WSO2 API manager and I'm trying to set different HTTP response statuses. Is this possible? If so how is it done?
So far I have tried setting the HTTP_SC property but this doesn't seem to have any effect.
mc.setProperty('HTTP_SC', "404");
I had the same requirement and after much exploring under the hood was able to find a workable solution.
The reason why setting the property:
mc.setProperty('HTTP_SC', "404");
didn't work is that the property needs to be set in the axis2 scope (as Abimaran said). mc.setProperty doesn't set it on that scope. Moreover, the MessageContext object doesn't provide a way to set the scope.
The 'Deploy as Prototype' action actually creates the API definition file by merging the specified in-line script into the a velocity template and storing the resulting API definition into a file.
Template: ./repository/resources/api_templates/prototype_template.xml
Output location: repository/deployment/server/synapse-configs/default/api/
The output file will have a name in the format:
provider--API Name-vVERSION.xml
where provider appears to be the username of the API creator.
What I did was add a filter to the template:
<filter source="boolean(get-property('HTTP_SC'))" regex="false">
<then>
<property name="HTTP_SC" value="200" scope="axis2"/>
</then>
<else>
<property name="HTTP_SC" expression="get-property('HTTP_SC')" scope="axis2"/>
</else>
</filter>
I added it immediately after a similar block (for handling CONTENT_TYPE) at the start of the inSequence element.
You need to add following properties before <send/> mediator
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<property name="HTTP_SC" value="403" scope="axis2"/>
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
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