AndreaNobili
AndreaNobili

Reputation: 43077

Why I can't retrieve a local registry entry value from a WSO2 ESB API?

I am trying to use the WSO2 Local Registry into an ESB project.

So in my EI project I have added this env.xml file into the local-entries folder (and then I have add it to Maven to be included in the project):

<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="env" xmlns="http://ws.apache.org/ns/synapse">TEST</localEntry>

So in theory I am defining a locaEntry having key="env" and the textual strin TEST as value.

Now I am trying to retrieve it into an ESB REST API, following the official documentation (https://docs.wso2.com/display/ESB481/Local+Registry+Entries) I am trying to retrieve it with the get-property(prop-name) function (where prop-name should be the defined key: env in my case).

Into my API code I have this:

<inSequence>
    <log level="full"/>
    <property expression="get-property('uri.var.countryId')" name="countryId" scope="default" type="STRING"/>
    <property expression="get-property('uri.var.lang_id')" name="lang_id" scope="default" type="STRING"/>

    <log level="custom">
        <property expression="$ctx:countryId" name="Country ID"/>
        <property expression="$ctx:lang_id" name="Lang ID"/>
        <property expression="$ctx:env" name="env"/>
    </log>
    .........................................................................
    .........................................................................
    .........................................................................

As you can see I am trying to retrieve and log the content of my env local entry but this is waht I am obtaining into the WSO2 log:

TID: [-1234] [] [2018-07-05 12:36:44,055]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  
Country ID = 1, 
Lang ID = 1, 
env = <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}

Why? What is wrong? What am I missing? How can I fix this issue?

Upvotes: 0

Views: 1218

Answers (1)

amg_amit
amg_amit

Reputation: 495

In Local Entries there are two types which you can mention

1. Inline Text

2. Inline XML.

As i see that you are using inline XML as it's ending with .xml(While creating XML can needn't have to specify the extension .xml as you will already be selecting inline XML), if this is the case then use the below property

 <property
        expression="get-property('env')"
        name="Indexing" scope="default" type="OM" xmlns:ns="http://org.apache.synapse/xsd"/>.

So your local entry should look like

<ROOT_ELEMENT>
Test
</ROOT_ELEMENT>

After this in your sequence use log mediator for the property $ctx:indexing

Upvotes: 1

Related Questions