URL parameter wso2esb

302 views Asked by At

I have created an API in esb like this snippet:

<api xmlns="http://ws.apache.org/ns/synapse" name="contact_v1" 
   <resource methods="GET" uri-template="/contact-by-email?email={query.param.email}" inSequence="crm_contact-by-email_v1" outSequence="crm_contact-by-email_v1" faultSequence="crm_contact-by-email-error_v1"/>
</api>

In my sequence I retrieve the request param, email, like that

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="crm_contact-by-email_v1" xmlns="http://ws.apache.org/ns/synapse">
    <in>

        <script language="js"><![CDATA[try {
                    var randomnumber1=Math.floor((Math.random() * 10000) + 1);
                    mc.setProperty("sessionnumber", randomnumber1.toString());
                } catch(e) {
                }]]></script>

        <property expression="$axis2:REST_URL_POSTFIX" name="myURL"
            scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
        <script language="js"><![CDATA[try {
            var log = mc.getServiceLog();
            var email = mc.getProperty('query.param.email');
            log.info("emailxxxxxx "+email);

            } catch(e) {}]]></script>

    </in>
    <out>
        <send/>
        <drop/>
    </out>
</sequence>

When I make a request with an encoding email like that

test%40test.com

it works witout problem.

But when I make a request with

[email protected]

it display this error

<tp:fault xmlns:tp="https://xxxxxxx.com/"><tp:code>404</tp:code><tp:type>Status report</tp:type><tp:message>Not Found</tp:message><tp:description>The requested resource (//[email protected]) is not available.</tp:description></tp:fault>

Would you have any idea

Best regards

1

There are 1 answers

0
maheeka On BEST ANSWER

Characters as @ are reserved characters for delimiters in the RFC specification for URI-Templates (I can explain more if you are interested). Therefore, in order to allow @ as the value for email parameter, define the uri-template with {+query.param.email} as below.

<api xmlns="http://ws.apache.org/ns/synapse" name="contact_v1" 
   <resource methods="GET" uri-template="/contact-by-email?email={+query.param.email}" inSequence="crm_contact-by-email_v1" outSequence="crm_contact-by-email_v1" faultSequence="crm_contact-by-email-error_v1"/>
</api>