0
votes

I have the following problem trying to insert multiple request query parameter into the URI of a REST API.

I have the following situation. Using an URL with a single query parameter (process_phase_id={process_phase_id}) it works fine, something like this:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/enutrifood/bylocation" name="ENutriFoodByLocation" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" uri-template="/{localizationId}/messages?process_phase_id={process_phase_id}">
    ...............................................................
    ...............................................................
    ...............................................................

But if I have multiple query parameter divided by the & symbol, something like this:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/enutrifood/bylocation" name="ENutriFoodByLocation" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" uri-template="/{localizationId}/messages?process_phase_id={process_phase_id}&q2={v2}">
    ...............................................................
    ...............................................................
    ...............................................................

As you can see now the resource have 2 parameters:

<resource methods="GET" uri-template="/{localizationId}/messages?process_phase_id={process_phase_id}&q2={v2}">

Now if I save my API I am obtaining this syntax error message:

enter image description here

Why? What could be the problem? What am I missing? Have I maybe to escape in some way the & character? How can I fix this problem and use multiple query parameter in my API?

1

1 Answers

2
votes

As this is an XML configuration file, you need to escape the & to &amp;.

In XML the & indicates the start of an XML entity (which is terminated by a ;). So to have an actual & in your document, you need to escape it.

As to the error, in your document, the parser see q2 as the name of the entity, but stops parsing at the = and concludes that you have a syntax error, as it didn't see a ; to end the entity.