WSO2 ESB setting soap envelope from property - wso2

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')

Related

WSO2 ESB 5.0.0 - How to check API response is in JSON format or not

How to validate the API response is in JSON or in HTML format using outsequence in wso2 ESB 5.0.0
I want to alter the response code if response is in HTML format.
You can try use switchMediator with something like that below.
But be aware and dont try to use <log level =" full "> on HTML, unless you have proper messageBuilder and messageFormater for that content type. In default WSO2 ESB tryes to convert using xml builder, and it will ended with error. I tried this on wso2ei 6.5.0 but i believe it should work on esb 5.0.0.
<switch source="$trp:Content-Type">
<case regex="^(application\/(json|x-javascript))(;.*)?$">
<log>
<property name="Looks like Json format" expression="$trp:Content-type"/>
</log>
</case>
<case regex="^(text\/html)(;.*)?$">
<!--Don't log full, unless you have proper axis2.xml configuration for that contentType-->
<log level="custom">
<property name="Looks like HTML format" expression="$trp:Content-type"/>
</log>
</case>
<default>
<log level="custom">
<property name="Unknown format" expression="$trp:Content-type"/>
</log>
</default>
</switch>

How to use enrich mediator to add header part in wso2 esb

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.

How to enrich a node value in OM property?

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.

How to insert soap:Body content as a child to another tag

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>

Default namespace and prefix in Proxy Service WSO2 ESB

I am developing a proxy service in WSO2 ESB.
With this configuration, I retrieve the xml web service response. The response uses a default namespace as shown:
<enrich>
<source type="body" clone="true" />
<target type="property" property="soapXmlResponseReadCahceDataService" />
</enrich>
This is the xml response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<cacheServices **xmlns="http://cache.services"**>
<cacheService>
<id>1</id>
<xmlrequesthash>b1e97b67-1226-4b1d-9081-b2a140690efd</xmlrequesthash>
<xmlrequestpayload>c</xmlrequestpayload>
<xmlresponsepayload>d</xmlresponsepayload>
<quantity>1</quantity>
</cacheService>
</cacheServices>
</soapenv:Body> </soapenv:Envelope>
thereafter I need get the element quantity:
<property xmlns="http://cache.services" name="count" expression="//cacheServices/cacheService/quantity" />
WSO2 ESB does not allow you to place a namespace without a prefix, and I can not obtain this value. I can do to obtain this value, since the xml response has no namespace prefix?
Can you try this xpath in property mediator ?
<property name="count" expression="//*[name()='cacheServices']/*[name()='cacheService']/*[name()='quantity']" scope="default" type="STRING"/>
Alternatively you can use this by adding any namespace prefix since you are using default namespace.
<property xmlns:ns1="http://cache.services" name="count" expression="//ns1:cacheServices/ns1:cacheService/ns1:quantity" scope="default" type="STRING"/>