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>
Related
I have an empty OM property like so:
<property description="empty extra_data" name="extra_data" scope="default">
<extra_data xmlns=""/>
</property>
Later on, I want to add data to this XML structure.
First enriching – adding the child element works fine:
<enrich description="set URL child in extra data">
<source clone="true" type="inline">
<url />
</source>
<target action="child" xpath="$ctx:extra_data"/>
</enrich>
Next, I want to set the URL that is stored in another property ("url").
I've tried it like that but it doesn't work (invalid target):
<enrich description="set url" xmlns:ns="http://ws.apache.org/ns/synapse">
<source clone="true" property="url" type="property"/>
<target xpath="$ctx:extra_data//ns:url/text()"/>
</enrich>
Can anyone help me with that? :)
I found this solution. Set the XML tag and its content in a property and append it as a new child element.
<property description="url xml tag" expression="fn:concat('<url>', $ctx:url, '</url>')" name="url_xml" scope="default" type="OM"/>
<enrich description="set url child in extra data">
<source clone="true" property="url_xml" type="property"/>
<target action="child" property="extra_data" type="property"/>
</enrich>
I still would've liked to replace or set a value inside a node, but that works for now...
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 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>
Is it possible to enrich a specific node value with enrich mediator?
My goal is to enrich this xpath:
$ctx:OriginalPayload//Partner[identifiers/businessId = $ctx:CorrelationId]/identifiers/otherId
I have tried these examples:
$ctx:OriginalPayload//Partner/identifiers/otherId
//Partner/identifiers/otherId
//Partner/identifiers/otherId/text()
//Partner/identifiers/otherId/node()
All gave me this error:
ERROR - EnrichMediator Invalid Target object to be enrich.
I'm using this syntax:
<enrich>
<source xpath="//plat:CustomerAccountId"/>
<target xpath="//Partner/identifiers/otherId"/>
</enrich>
Below is my payload which i'm trying to enrich:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://iszkody.lsn.io/service/internal/ClaimService">
<soapenv:Header/>
<soapenv:Body>
<ns0:createClaimRequest>
<claim>
<InsClaimData VER="1">
<PartnerList>
<Partner>
<RoleList>
<Role>UBEZP</Role>
</RoleList>
<BusinessPartner>
<partnerType>person</partnerType>
<personData>
<firstName>JANUSZ</firstName>
<lastName>KOWALSKI</lastName>
<PESEL>83248328432</PESEL>
</personData>
<identifiers>
<businessId>123</businessId>
<otherId></otherId>
</identifiers>
</BusinessPartner>
</Partner>
</PartnerList>
</InsClaimData>
</claim>
</ns0:createClaimRequest>
</soapenv:Body>
</soapenv:Envelope>
It doesn't look like a problem with payload or xpath but more like the mediator doesn't implement custom type.
I just tested the following in WSO2 ESB 4.9.0 and also 4.8.1 and in both version the following proxy did work (I enrichted the otherId with the businessId):
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Test_XPath" transports="http" xmlns:avintis="http://www.avintis.com">
<target faultSequence="faultSequence">
<inSequence>
<sequence key="initSequence" />
<log level="full"></log>
<log level="custom">
<property expression="$body//businessId" name="xpath" />
</log>
<log level="custom">
<property expression="$body//Partner/BusinessPartner/identifiers/businessId" name="xpath" />
</log>
<enrich>
<source xpath="//businessId" />
<target xpath="//otherId" />
</enrich>
<log level="full" />
</inSequence>
</target>
</proxy>
As you commented that you now use the *[local-name()='BusinessPartner'] syntax, this points out to be an issue with the namespaces. Try to use the correct namespace of the BusinessParter elements.
I have the following soap:body
<soapenv:Body>
<Message>
<Context>
<id>10</id>
<subject>sub10</subject>
<body>body10</body>
</Context>
</Message>
</soapenv:Body>
But I need to insert the content inside <SendMessageRequest> tag before sending to a request:
<soapenv:Body>
<SendMessageRequest>
<Message>
<Context>
<id>10</id>
<subject>sub10</subject>
<body>body10</body>
</Context>
</Message>
</SendMessageRequest>
</soapenv:Body>
I'm using the Enrich Mediator, but not figured out how to do this...
Here the code I'm trying:
<enrich>
<source type="body"/>
<target action="child" type="custom" xpath="SendMessageRequest"/>
</enrich>
You can't directly add an intermediate element. That is one that wraps your current content. Instead you can store your content-to-be-wrapped in a property. Note the use of the $body xpath variable (courtesy of the SynapseXPath class), which refers to the soap body element regardless of used soap version.
<property name="payload" expression="$body/*[1]" type="OM"/>
Then use the PayloadFactory mediator to construct your new request stub:
<payloadFactory>
<format>
<SendMessageRequest xmlns=""/>
</format>
<args/>
</payloadFactory>
Subsequently you can enrich your former content into the newly created payload.
<enrich>
<source clone="true" property="payload" type="property"/>
<target action="child" type="custom" xpath="$body/SendMessageRequest"/>
</enrich>