Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

REST clients use query parameters to provide inputs for the relevant operation. These query parameters may be required to carry out the back-end operations either in a REST service or a proxy service. Let’s take a sample request that is sent to the SimpleStockQuoteService, and see how these parameters can be set in the outgoing message.

Code Block
languagenone
curl -v -H "Content-Type: application/xml" -d "<Customer><id>123</id><name>John</name></Customer>" X GET "http://localhost:82828280/stockquote/view/IBM?param1=value1&param2=value2"

In this request, there are two query parameters (customer name and ID) that must be set in the outgoing message from the WSO2 Enterprise Integrator (WSO2 EI). We can configure the API to set those parameters as follows:

Code Block
languagexml
<definitions>
<api xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteAPI" context="/stockquote">
   <resource methods="GET" uri-template="/view/{symbol}" methods="GET>
      <inSequence>
         <payloadFactory media-type="xml">
    <inSequence>        <payloadFactory><format>
       <format>        <m0:getQuote xmlns:m0="http://services.samples">
                  <m0:request>
                     <m0:symbol>$1</m0:symbol>
                     <m0:customerName>$2</m0:customerName>
                     <m0:customerId>$3</m0:customerId>
                  </m0:request>
               </m0:getQuote>
            </format>
            <args>
               <arg evaluator="xml" expression="get-property('uri.var.symbol')"/>
               <arg evaluator="xml" expression="get-property('query.param.param1')"/>
               <arg evaluator="xml" expression="get-property('query.param.param2')"/>/>
            </args>
         </payloadFactory>
         <send>
  </args>     </payloadFactory>     <send><endpoint>
       <endpoint>        <address uri=" http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
               <property name="SOAPAction" value="getQuote" scope="transport"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </resource>
</api>
</definitions>                  


The query parameter values can be accessed through the "get-property" function by specifying the parameter number as highlighted in the above request.  

...

For this sample, we use ActiveMQ 5.5.1 as the message broker. Start ActiveMQ and configure the JMS transport in WSO2 EI to work with ActiveMQ before you proceed.

...

curl -v -d @addClient.xml -H "Content-type: applicationtext/xml" http://localhost:8280/clientservice/clients 

...

curl -v -d @updateClient.xml -X PUT -H "Content-type: applicationtext/xml" http://localhost:8280/clientservice/clients

...

Code Block
languagexml
curl -X GET GEThttphttp://localhost:8280/jaxrs/customers-wrong/123

...