replace function with get-property in wso2esb - wso2

I am trying the below option and i m getting error, can anyone suggest me the solution. I have added synapse.xpath.dom.failover.enabled=true
Code:trying to replace ~TOKEN~ with the property value
<property name="verificationLink" expression="fn:replace($ctx:reqVerifyUrl , '~TOKEN~', get-property('verification_code'))" scope="default" type="STRING" xmlns:fn="http://www.w3.org/2005/xpath-functions" />
Error:
TID: [-1234] [] [2017-02-15 00:14:19,318] ERROR {org.apache.synapse.util.xpath.SynapseXPath} - Evaluation of the XPath expression fn:replace($ctx:reqVerifyUrl , '~TOKEN~', get-property('verification_code')) resulted in an error {org.apache.synapse.util.xpath.SynapseXPath} net.sf.saxon.trans.XPathException: Unknown system function get-property()

get-property is not a standard xpath function and you must say to the xpath engine that this function comes from synapse :
<property name="verificationLink" expression="fn:replace($ctx:reqVerifyUrl , '~TOKEN~', syn:get-property('verification_code'))" scope="default" type="STRING" xmlns:fn="http://www.w3.org/2005/xpath-functions" />
You do not need to add the definition of 'syn' namespace, it is well known in your mediation (xmlns:syn="http://ws.apache.org/ns/synapse")

Two things need to be done:
A. Review this and ensure your Synapse config is set correctly. Is there any replace function in wso2esb?
B. Then you need to add prefix fn & syn if you need to use methods like get-property() with XPath 2.0. Also note, you must use (include) the following namespaces values for ‘syn’ and ‘fn’.
xmlns:syn=”http://ws.apache.org/commons/ns/payload”
xmlns:fn=”http://www.w3.org/2005/xpath-functions”
Here is a sample property mediator using replace.
<property xmlns:syn="http://ws.apache.org/commons/ns/payload" xmlns:fn="http://www.w3.org/2005/xpath-functions" name="xmlValue" expression="fn:replace(syn:get-property('textValue'), 'xmlData=', '')></property>;

Related

WSO2 Call Template Mediator how to get a variable

I'm trying to use Call Template Mediator in WSO2 and I'm trying to get a dynamic value inside function, but I don't find the way to get it.
For example:
<property expression="$ctx:variable" name="test" type="STRING"/>
<call-template target="HelloWorld_Logger">
<with-param name="message" value="VARIABLE: " expression="$ctx:test" />
</call-template>
I'm not able to get the property "test", if i remove value field the IDE reports an error.
There is some way to get a property inside <call-template> function?
The Call Template Mediator doesn't have a parameter called expression to pass dynamic values. You must pass the XPath expression within {} to the value parameter itself. In your case, the call-template will be as follows,
<call-template target="HelloWorld_Logger">
<with-param name="message" value="{$ctx:test}"/>
</call-template>
Please refer to the Call Template Mediator for more information.

WSO2 ESB 4.8.1 Switch Mediator Case matching not working

I am using WSO2 ESB 4.8.1. I need to check if a particular field exists in the Incoming Payload XML. If Iit does, a Switch Case should run, otherwise it should run a default scenario. The field on which I am checking will always have a dynamic value and it would look like following:
20000569899
I wrote following logic in ESB:
<property name="CheckIdExist" expression="//*[local-name()='Id']" scope="default" type="STRING" description="CheckIdExist"/>
<switch source="get-property('CheckIdExist')">
<case regex="[a-zA-Z0-9]">
<sequence key="SequenceA"/>
<sequence key="SequenceB"/>
<sequence key="SequenceC"/>
</case>
<default>
<log></log>
</default>
</switch>
Problem:
The problem is that Switch is able to pick a value from the property but it does not match the Case regular expression. Following are some ESB Logs Entries:
Logs Entries:
XPath : get-property('CheckIdExist') evaluates to : 20001089900
None of the switch cases matched - executing default
I checked online, this regular expression works. So what i am unable to understand is that why WSO2 ESB is not recognizing it as a valid expression. Or is there any other way to check that if a field exists in an input request then a particular switch case should work, Otherwise not.
Your regular expression lacks a quantifier + meaning 1 or more occurrences:
<case regex="[a-zA-Z0-9]+">

WSO2 ESB Collout address from Property or XPath-expression

I have the config with development and production sections. This sections contain the URLs of backends. In my inSequence i need it to Callout to these backends several times per request.
<config>
<env>prod</env>
<backend env="prod">http://localhost:1234/</backend>
<backend env="dev">http://localhost:2345/</backend>
</config>
I read this config from Local Entry (as XML) and want to set Callout's URL as an Property.
I don't want to hardcode these backends inside my code with "Switch" statement, because it's possible to use more than two environments.
Could you please show me an example?
Thank you.
You can read xml file in registry. Simply define property of OM type like this:
<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM" />
Then you can see the value by logging like this:
<log level="custom"> <property name="test.b" expression="$ctx:test//b" /> </log>
And in the xml file that you have put in the root of registry, you would fill it like:
<a>Hello<b>WSO2</b></a>
I have learned it from this link.
I found the answer. According to source of Callout mediator:
CalloutMediator.java
It uses "To" header if URL is not specified.

How to pass parameters to XSLT from JBoss Actions Pipeline

Say I have a given action:
<service category="MyService" name="MyFirstService">
<actions mep="RequestResponse">
<action class="actions.CXFListenerAction" name="CXFServiceListener"/>
<action class="org.jboss.soa.esb.actions.transformation.xslt.XsltAction" name="Transform XML">
<property name="templateFile" value="/stylesheets/transform_response.xslt"/>
<property name="failOnWarning" value="true"/>
</action>
</actions>
I am trying to figure out how to add a property name or parameter that I could then access from within the XSLT. I've tried add additional property names,
<property name="param1" value="Hey!"/>
but I'm not 100% sure if this is correct for adding parameters accessible by the XSLT.
Thanks.
The properties defined for the XsltAction class are properties specific to that action class and are not related to parameters in the template file.
So in short, it's not possible to pass parameters to the xslt from the JBoss ESB action pipeline. However, it would be possible to create a custom action that decorates your ESB message with data you define as a property in your jboss-esb.xml file and insert that before your XsltAction. That may be what you're looking for.

XQuery transformation with WSO2 ESB

I am designing a Proxy Service sequence that includes an XQuery transformation. I have a problem with referencing the registry file containing the transformation.
Here is the sequence:
<sequence name="MySequence" xmlns="http://ws.apache.org/ns/synapse" >
<xquery key="conf:/wsdl/xqueryRequest.xq"
target="..."
xmlns:ns="http://org.apache.synapse/xsd" >
<variable xmlns:ns2="http://..." name="var1" expression="..." type="ELEMENT" />
</xquery>
<send>
<endpoint>...</endpoint>
</send>
</sequence>
The file containing the XQuery transformation is uploaded in /_system/config/wsdl/xqueryRequest.xq
And this is the exception I am getting:
WARN ERROR_DETAIL : org.apache.synapse.SynapseException:
Unable to execute the query at
org.apache.synapse.mediators.xquery.XQueryMediator.handleException(XQueryMediator.java:627) at
org.apache.synapse.mediators.xquery.XQueryMediator.mediate(XQueryMediator.java:130) at
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:60) at
...
Caused by: java.lang.NullPointerException at
org.wso2.carbon.mediation.registry.WSO2Registry.lookup(WSO2Registry.java:177) at
org.apache.synapse.registry.AbstractRegistry.getResource(AbstractRegistry.java:63) at
org.apache.synapse.config.SynapseConfiguration.getEntry(SynapseConfiguration.java:693) at
org.apache.synapse.core.axis2.Axis2MessageContext.getEntry(Axis2MessageContext.java:194) at
org.apache.synapse.mediators.xquery.XQueryMediator.performQuery(XQueryMediator.java:233) at
org.apache.synapse.mediators.xquery.XQueryMediator.mediate(XQueryMediator.java:123)
... 11 more
The exception shows a NullPointer at WSO2Registry.lookup so I assume that the problem is in finding the XQuery file in the registry, this part:
key="conf:/wsdl/xqueryRequest.xq"
The documentation shows two code snippets(390 and 391) with XQuery transformation but non of them explains howto reference the XQuery file.
Question: What should be the correct value for the key parameter? Do I need to use the "Local Entry" feature? If yes, then should I define the value as "Inline XML Entry" or "Inline Text"?
UPDATE 03/23/12:
Question 2: Perhaps a simpler question: Where should I copy/upload the xqueryRequest.xq file when I set Xquery mediator's key field to key="xqueryRequest.xq"?
Can you try saving your xquery as a local entry and refer it from the XQuery mediator.
(Please have a look at local entry samples)