Versions Compared

Key

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

...

Typically, POST is used to send a message that has data enclosed as a payload inside an HTML body. However, you can also use POST without a payload. WSO2 ESB Enterprise Integrator (WSO2 EI) treats it as a normal message and forwards it to the endpoint without any extra configuration.  

The following diagram depicts a scenario where a REST client communicates with a REST service using WSO2 ESBEI. Apache Tcpmon is used solely for monitoring the communication between the ESB WSO2 EI and the back-end service and has no impact on the messages passed between the ESB and back-end service. For this particular scenario, the cURL client is used as the REST client, and the basic JAX-RS sample (available with WSO2 Application Server) is  is used as the back-end REST service.

...

  1. Configure and deploy the JAX-RS Basics sample by following the instructions for building and running the sample on the JAX-RS Basics page.
  2. Since we are going to run both WSO2 ESB and the WSO2 Application Server on the same machine, offset the ports of the application server by changing the offset value to 1 in <AS_HOME>/repository/conf/carbon.xml.
  3. Start the ESB and change the configuration as follows:
    Code Block
    languagehtml/xml
    <definitions xmlns="http://ws.apache.org/ns/synapse">
       <sequence name="fault">
          <log level="full">
             <property name="MESSAGE" value="Executing default sequence"/>
             <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
             <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
          </log>
          <drop/>
       </sequence>
       <sequence name="main">
          <log/>
          <drop/>
       </sequence>
       <api name="testAPI" context="/customerservice">
          <resource methods="POST" url-mapping="/customers">
             <inSequence>
                <send>
                   <endpoint>
                      <address uri="http://localhost:82828280/jaxrs_basic/services/customers/customerservice"/>
                   </endpoint>
                </send>
             </inSequence>
             <outSequence>
                <send/>
             </outSequence>
          </resource>
       </api>
    </definitions>

    In this proxy configuration, testAPI intercepts messages that are sent to the relative URL /customerservice/customers and sends them to the relevant endpoint by appending the url-mapping of the resource tag to the end of the endpoint URL.

  4. Start tcpmon and make it listen to port 8282 8280 of your local machine. It is also important to set the target host name and the port as required.
    We will now test the connection by sending a POST message that includes a payload inside an HTML body.

  5. Go to the terminal and issue the following command:
    curl -v -H "Content-Type: application/xml" -d "<Customer><id>123</id><name>John</name></Customer>" http://localhost:8280/customerservice/customers

  6. The following reply message appears in the console:

    Code Block
    languagehtml/xml
    <Customer>
       <id>132</id>
       <name>John</name>
    </Customer>

     

  7. Now send the same POST message but without the enclosed data:
    curl -v -H "Content-Type: application/xml" -d "" http://localhost:8280/customerservice/customer

...