I'm using WSO2 to expose APIs internally. The API works as a pass-through proxy (or gateway) that forwoard the request to a back-end-service and adding just some headers.
Now, i want to hide some information when intercepting the response from the back-end plateform.
I tried filter mediator but i'm not sure that i'm on the right way.
Below an example of what i want to do.
Actual response (as-is):
<member>
<name>ABC</name>
<value>abc</value>
</member>
<member>
<name>XYZ</name>
<value>xyz</value>
</member>
Wished response (to be sent to the client after remove/hide actions):
<member>
<name>ABC</name>
<value>abc</value>
</member>
Any help please?
You can try using the Enrich mediator to modify the body.
As per your code snippet enrich mediator can be as below and can be added right after calling the endpoint.
<enrich>
<source clone="true" xpath="$body//member[1]"/>
<target type="body"/>
</enrich>
In the above enrich mediator, it will retrieve the first member tag of the response body and it will be set as the body.
You can refer the Enrich mediator documentation [1] for further reference.
[1] https://docs.wso2.com/display/EI610/Enrich+Mediator
It worked me thank you. But can i do the same action by refering to the value of the member? in other words, can i put this code:
<enrich>
<source clone="true" xpath="$body//name[ABC]"/>
<target type="body"/>
</enrich>
Related
I am reading some values from source table and writing to a target table.Since the fields are different in names and some values , i am using XSLT mediator in WSO2 ESB.
After the xslt mediator , i want to inject few more values into the payload.Say some variables which i have previously store. I cant do it xslt because these values are in some variables.
So below is my code.What should be the code the dashed lines?
<enrich>
<source clone="true" property="SOURCE_TABLE_PAYLOAD" type="property"/>
<target type="body"/>
</enrich>
<xslt key="gov:/bcogc/transformation/SourcetoTargetTransformation.xslt"/>
----------------ADD SOME MORE VALUES HERE to the payload------------------
<header name="Action" scope="default" value="urn:inserttotargettable"/>
<call>
<endpoint key="gov:/endpoints/INSERT_DataService_EP.xml"/>
</call>
Please throw some lights
You can again use an enrich mediator for example ,
<property name="orderID" scope="default" description="orderID">
<orderID xmlns="">2</orderID>
</property>
<enrich>
<source clone="true" xpath="$ctx:orderID"/>
<target action="sibling" xpath="//orders"/>
</enrich>
Here the orderID property is defined , so now you can add that property as a sibling with you request coming out of XSLT, so the request will look like below after enriching
<orders>
<order>
<price>50.00</price>
<quantity>500</quantity>
<symbol>IBM</symbol>
<comment>REF 10053</comment>
</order>
<order>
<price>18.00</price>
<quantity>500</quantity>
<symbol>MSFT</symbol>
<comment>ref 20088398289</comment>
</order>
</orders>
<orderID>2</OrderID>
This is existing header
<s:Header>
<ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="10018d27-2573-4d6b-8bcb-b49f6c686f1a">5d827c1d-bd7b-437f-904f-5f82c9844022</ActivityId>
</s:Header>
I need to add following security in header part using enrich mediator
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken u:Id="uuid-05a278f7-0f00-4710-b81c-4401fd280d6d-3">
<o:Username>FISEPAY_DEV</o:Username>
<o:Password>RaDrup5E4awreP</o:Password>
</o:UsernameToken>
</o:Security>
So how i need to add using enrich mediator
Try using the below code.
<enrich>
<source type="inline" clone="true">
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken u:Id="uuid-05a278f7-0f00-4710-b81c-4401fd280d6d-3">
<o:Username>FISEPAY_DEV</o:Username>
<o:Password>RaDrup5E4awreP</o:Password>
</o:UsernameToken>
</o:Security>
</source>
<target xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xpath="//<s:Header>"/>
</enrich>
<log level="full"/>
Use the property mediator as below ,
<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM" />
conf:/test.xml should be the path where your xml is stored.
Now this variable "test" can be used in enrich mediator.
I am absolutly new in WSO2 and I have the following doubt about an ESB project on which I am working on.
I have to iterate on each <Sample>...</Sample> element of the following XML document (coming from a DSS service):
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<Samples xmlns="http://ws.wso2.org/dataservice">
<Sample>
<sample_id>XXX00001</sample_id>
<processed>n</processed><sample_doi>sampleid001</sample_doi><date>2000-01-01</date><hold_wiews>hold_wiews-0001</hold_wiews><hold_pid>hold_pid-001</hold_pid><hold_name>hold_name-001</hold_name><hold_address>hold_address-001</hold_address><hold_country>001</hold_country><hold_lat>hold_lat-1</hold_lat><hold_lon>hold_lon-1</hold_lon><method>acqu</method><genus>genus-001</genus><species>species-001</species><sp_auth>sp_auth-001</sp_auth><subtaxa>subtaxa-001</subtaxa><st_auth>st_auth-001</st_auth><bio_status>001</bio_status><mls_status>01</mls_status><prov_sid>prov_sid-001</prov_sid><provenance>pr1</provenance><coll_sid>coll_sid-001</coll_sid><coll_miss_id>coll_miss_id-001</coll_miss_id><coll_site>coll_site-001</coll_site><coll_lat>coll_lat-1</coll_lat><coll_lon>coll_lon-1</coll_lon><coll_uncert>coll_uncert-001</coll_uncert><coll_datum>coll_datum-001</coll_datum><coll_georef>coll_georef-001</coll_georef><coll_elevation>1</coll_elevation><coll_date>2001-01-01</coll_date><coll_source>s1</coll_source><ancestry>ancestry-001</ancestry>
</Sample>
<Sample>
<sample_id>XXX00002</sample_id>
<processed>n</processed><sample_doi>sampleid002</sample_doi><date>2000-01-02</date><hold_wiews>hold_wiews-0002</hold_wiews><hold_pid>hold_pid-002</hold_pid><hold_name>hold_name-002</hold_name><hold_address>hold_address-002</hold_address><hold_country>002</hold_country><hold_lat>hold_lat-2</hold_lat><hold_lon>hold_lon-2</hold_lon><method>acqu</method><genus>genus-002</genus><species>species-002</species><sp_auth>sp_auth-002</sp_auth><subtaxa>subtaxa-002</subtaxa><st_auth>st_auth-002</st_auth><bio_status>002</bio_status><mls_status>02</mls_status><prov_sid>prov_sid-002</prov_sid><provenance>pr2</provenance><coll_sid>coll_sid-002</coll_sid><coll_miss_id>coll_miss_id-002</coll_miss_id><coll_site>coll_site-002</coll_site><coll_lat>coll_lat-2</coll_lat><coll_lon>coll_lon-2</coll_lon><coll_uncert>coll_uncert-002</coll_uncert><coll_datum>coll_datum-002</coll_datum><coll_georef>coll_georef-002</coll_georef><coll_elevation>2</coll_elevation><coll_date>2001-01-02</coll_date><coll_source>s2</coll_source><ancestry>ancestry-002</ancestry>
</Sample>
<Sample>
<sample_id>XXX00003</sample_id>
<processed>n</processed><sample_doi>sampleid003</sample_doi><date>2000-01-03</date><hold_wiews>hold_wiews-0003</hold_wiews><hold_pid>hold_pid-003</hold_pid><hold_name>hold_name-003</hold_name><hold_address>hold_address-003</hold_address><hold_country>003</hold_country><hold_lat>hold_lat-3</hold_lat><hold_lon>hold_lon-3</hold_lon><method>acqu</method><genus>genus-003</genus><species>species-003</species><sp_auth>sp_auth-003</sp_auth><subtaxa>subtaxa-003</subtaxa><st_auth>st_auth-003</st_auth><bio_status>003</bio_status><mls_status>03</mls_status><prov_sid>prov_sid-003</prov_sid><provenance>pr3</provenance><coll_sid>coll_sid-003</coll_sid><coll_miss_id>coll_miss_id-003</coll_miss_id><coll_site>coll_site-003</coll_site><coll_lat>coll_lat-3</coll_lat><coll_lon>coll_lon-3</coll_lon><coll_uncert>coll_uncert-003</coll_uncert><coll_datum>coll_datum-003</coll_datum><coll_georef>coll_georef-003</coll_georef><coll_elevation>3</coll_elevation><coll_date>2001-01-03</coll_date><coll_source>s3</coll_source><ancestry>ancestry-003</ancestry>
</Sample>
</Samples>
</soapenv:Body>
</soapenv:Envelope>
To do it I am using the iterate mediator (it is working pretty fine), something like this:
<iterate expression="$body//ds:Sample" id="ITR_AGG" xmlns:ds="http://ws.wso2.org/dataservice">
<target>
<sequence>
<enrich>
<source clone="true" type="envelope"/>
<target property="sampleData" type="property"/>
</enrich>
<!-- Log Sample Data -->
<log level="custom">
<property expression="$ctx:sampleData" name="sample data"/>
</log>
...........................................................
...........................................................
DO SOME OTHER STUFF
...........................................................
...........................................................
</sequence>
</target>
</iterate>
It works fine but I have some doubts, I try to explain these doubts.
The iterate mediator implements the Splitter enterprise integration pattern **, it is used to splits the message into a number of different messages derived from the parent message**.
Ok, so I am splitting the original message that basically is contained into the <soapenv:Body>---</soapenv:Body> container into the 3 <Sample>...</Sample> separated message.
It works but why the iterate expression defined into the iterator mediator:
<iterate expression="$body//ds:Sample" id="ITR_AGG" xmlns:ds="http://ws.wso2.org/dataservice">
is $body//ds:Sample?
Ok so I think that I have to use the ds: prefix because it is coming from a data service (tell me if I am doing wronga assertion). But what exactly represent the $body "variable"? (is it something like a variable?)
Is it representing the <soapenv:Body> element in which have to be searched the <Sample> element that have to be iterated? Or what? In case my assumption is correct how the <soapenv:Body> is associated to the $body "variable"?
The second doubt is related to the use of the enrich mediator contained at the begining of the iterate mediator:
<enrich>
<source clone="true" type="envelope"/>
<target property="sampleData" type="property"/>
</enrich>
What exactly does? It seems to me that it is copying the current element on which is iterating into a new property named sampleData, infact after this mediator the sampleData property is logged by a logger and it is printed something like this:
sample data =
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<Sample xmlns="http://ws.wso2.org/dataservice">
<sample_id>XXX00001</sample_id>
<processed>n</processed><sample_doi>sampleid001</sample_doi><date>2000-01-01</date><hold_wiews>hold_wiews-0001</hold_wiews><hold_pid>hold_pid-001</hold_pid><hold_name>hold_name-001</hold_name><hold_address>hold_address-001</hold_address><hold_country>001</hold_country><hold_lat>hold_lat-1</hold_lat><hold_lon>hold_lon-1</hold_lon><method>acqu</method><genus>genus-001</genus><species>species-001</species><sp_auth>sp_auth-001</sp_auth><subtaxa>subtaxa-001</subtaxa><st_auth>st_auth-001</st_auth><bio_status>001</bio_status><mls_status>01</mls_status><prov_sid>prov_sid-001</prov_sid><provenance>pr1</provenance><coll_sid>coll_sid-001</coll_sid><coll_miss_id>coll_miss_id-001</coll_miss_id><coll_site>coll_site-001</coll_site><coll_lat>coll_lat-1</coll_lat><coll_lon>coll_lon-1</coll_lon><coll_uncert>coll_uncert-001</coll_uncert><coll_datum>coll_datum-001</coll_datum><coll_georef>coll_georef-001</coll_georef><coll_elevation>1</coll_elevation><coll_date>2001-01-01</coll_date><coll_source>s1</coll_source><ancestry>ancestry-001</ancestry>
</Sample>
</soapenv:Body>
</soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
that represents the current element on which I am iterating. Is it my reasoning correct?
You can use any string for the prefix, just be sure to use the same string after xmlns:
xmlns:ds="http://ws.wso2.org/dataservice"
Ex:
<iterate expression="$body//mypref:Sample" id="ITR_AGG" xmlns:mypref="http://ws.wso2.org/dataservice">
$body is a predefined xpath expression for synapse that represent the body message:
https://docs.wso2.com/display/ESB500/Synapse+XPath+Variables#SynapseXPathVariables-$body
The enrich mediator:
<enrich>
<source clone="true" type="envelope"/>
<target property="sampleData" type="property"/>
</enrich>
Just copy the content of the incoming message, the entire payload including the soapevelop inside a property called sampleData.
I am absolutly new in WSO2 project and I have the following problem. I am working on an Enterprise Intergrator project (that involves ESB and DSS components).
I am generating an XML document starting from data contained into some database tables. These data are aggregate using a pretty complex logic.
My problem is the following one:
into my ESB flow I have these chained enrich mediator used a create this section of the final XML document, this is the code:
<!-- add placeholders for additional <sampleid> and <provenance> tags -->
<enrich>
<source clone="true" type="inline">
<parent xmlns="http://ws.wso2.org/dataservice">
<sampleid>[pgrfas.prov_sid]</sampleid>
<provenance>[pgrfas.provenance]</provenance>
</parent>
</source>
<target property="moreValues" type="property"/>
</enrich>
<!-- Copy values for <sampleid> and <provenance> tags -->
<enrich>
<source clone="true" xmlns:ns="http://org.apache.synapse/xsd" xpath="$ctx:moreValues/child::*"/>
<target action="child" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xpath="$ctx:serviceCall//ds:register/ds:acquisition"/>
</enrich>
<enrich>
<source clone="true" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xpath="$ctx:sampleData//ds:Sample/ds:prov_sid/text()"/>
<target action="child" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xpath="$ctx:serviceCall//ds:register/ds:acquisition/ds:sampleid/text()"/>
</enrich>
As you can see in the first mediator definition I am defining 2 XML element ( and ) by:
<parent xmlns="http://ws.wso2.org/dataservice">
<sampleid>[pgrfas.prov_sid]</sampleid>
<provenance>[pgrfas.provenance]</provenance>
</parent>
Ad I am define 2 placeholder that should be replace with the data obtained from the DB by this chained following mediators:
<enrich>
<source clone="true" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xpath="$ctx:sampleData//ds:Sample/ds:prov_sid/text()"/>
<target action="child" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xpath="$ctx:serviceCall//ds:register/ds:acquisition/ds:sampleid/text()"/>
</enrich>
<enrich>
<source clone="true" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xpath="$ctx:sampleData//ds:Sample/ds:provenance"/>
<target xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xpath="$ctx:serviceCall//ds:register/ds:acquisition/ds:provenance"/>
</enrich>
This is the related section in the final XML document generated by this EXB application:
<sampleid>coll_sid-001</sampleid>
<missid>coll_miss_id-001</missid>
Where coll_sid-001 and coll_miss_id-001 are retrieved from the database by the DSS service (previously putted into the $ctx:sampleData property).
If into the database table on which the DSS query is perfromed there are the value related to the XML and field it works fine and I obtain the previous output.
If this table contains null value for these fields I obtain this output into the generated XML:
<sampleid>[pgrfas.coll_sid]</sampleid>
<missid>[pgrfas.coll_miss_id]</missid>
As you can see, if it can't find the related value on the DB table it put the defined placeholder into the generated XML.
This is not good for my purpose. If into the DB table are present null values I want obtain an empty tag into my generated XML document, something like this:
<sampleid />
<missid />
How can I fix this issue? Exist some simple workaround to obtain empty tag in this situation?
Try it create your enrich in this way
<enrich>
<source clone="true" type="inline">
<parent xmlns="http://ws.wso2.org/dataservice">
<sampleid/>
<provenance/>
</parent>
</source>
<target property="moreValues" type="property"/>
</enrich>
I have to set the soap envolope from a OM property populated with xml content. I use the enrich mediator to do this with the following code:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="envelope" expression="$ctx:mensaje" />
</log>
<enrich>
<source xmlns:ns="http://org.apache.synapse/xsd" clone="false" type="property" property="mensaje" />
<target action="replace" type="envelope" xpath="" property="" />
</enrich>
The log instruction shows a correct soap envelope but the system log stops with
08:12:26,997 [-] [HttpServerWorker-8] INFO Start : Enrich mediator
and I get this soap fault:
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>Index: 0, Size: 0</faultstring>
<detail/>
</soapenv:Fault>
Any help?
You are trying to get property from message context..Use like this in your source configuration..
get-property('mensaje')