Versions Compared

Key

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

If you have a REST front-end client, REST back-end service, or both a REST client and service, you can use a proxy service in the WSO2 Enterprise Integrator (WSO2 EI) to ESB profile to handle the communication between the front end and back end. This page describes the following scenarios:

...

In this scenario, the client sends a REST message to the EIESB profile, which transforms the message to a SOAP1.1 message and sends it to the back-end service. Once the back-end response is received, the EI sends ESB profile sends the response back to the client as a REST message.

To implement this scenario:

  1. Start WSO2 EI and the ESB profile and change the configuration as shown above.
  2. Deploy the back-end service 'SimpleStockQuoteService' and start the Axis2 server using the instructions in Starting Sample Back-End Services.
    You will now send a message to the back-end service through WSO2 EI using the ESB profile using the sample Stock Quote Client. This client can run in several modes.
  3. Run the following ant command from the <EI_HOME>/samples/axis2Client directory to trigger a sample message to the back-end service:
    ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Drest=true

...

In this scenario, the client sends a SOAP message to WSO2 EIthe ESB profile, which transforms it to a REST message and sends it to the back-end service. Once the back-end response is received, WSO2 EI sends the ESB profile sends it back to the client as a SOAP message. The filter mediator is used to identify the required service. Though this example only has one filter, there could be many filters in the real scenario. The REST_URL_POSTFIX property is a well-defined property, and its value is appended to the target URL when sending messages out in a RESTful manner. Similar to REST_URL_POSTFIX, the HTTP_METHOD property is also well-defined and sets the HTTP verb to GET.

...

To implement this scenario:

  1. Start WSO2 EI and the ESB profile and change the configuration as shown above.
  2. Build and deploy the JAX-RS Basics sample. This sample is shipped with WSO2 EI, contain . It contains a set of pure RESTful services, so we will use this as our back-end service.
  3. Send a message to the back-end service through WSO2 EI using the ESB profile using SoapUI. The service used in this scenario is the getCustomer service, which requires the customer ID to complete its task. A sample SOAP message that is used to achieve this is as follows:

    Code Block
    languagehtml/xml
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Header/> 
       <soapenv:Body>
         <getCustomer>
            <id>123</id>
         </getCustomer>
       </soapenv:Body>
    </soapenv:Envelope>

    This message simply represents the relevant method to be invoked and its associated value. Upon successful execution, SoapUI should display the following message in response.

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

...

Code Block
languagehtml/xml
<definitions xmlns="http://ws.apache.org/ns/synapse">
   <proxy name="CustomerServiceProxy"
          transports="http https"
          startOnLoad="true">
      <target>
         <inSequence>
            <property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
            <switch source="$axis2:HTTP_METHOD">
               <case regex="GET">
                  <property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
               </case>
               <case regex="POST">
                  <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
               </case>
               <default/>
            </switch>
            <send>
               <endpoint>
                  <address uri="http://localhost:8280/jaxrs_basic/services/customers/customerservice" format="pox"/>
               </endpoint>
            </send>
         </inSequence>
         <outSequence>
            <send/>
         </outSequence>
      </target>
   </proxy>
   <sequence name="fault">
      <log level="full">
         <property name="MESSAGE" value="Executing default &#34;fault&#34; 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>
</definitions>

In this scenario, WSO2 EI simply the ESB profile simply changes the message type of the client into XML and then passes it to the REST service. Once WSO2 EI has the ESB profile has received the XML message, it transforms it back into a JSON message and sends it to the client. 

...

To implement this scenario:

  1. Start WSO2 EI and the ESB profile and create a proxy service using the configuration shown above.
  2. Build and deploy JAX-RS Basic sample. This contains a set of pure RESTful services, so we will use this as our back-end service.
  3. Go to the command prompt and issue the following curl command to simulate the request of a real REST client:
    curl -v -i -H "Accept: application/json" http://localhost:8280/services/CustomerServiceProxy/customers/123

...

In this scenario, an proxy service in WSO2 EI listens the ESB profile listens to a JMS queue, picks up available messages from that queue, and delivers the messages to the REST back-end service. For the JMS front-end client, we will use the sample JMSClient that ships with the WSO2 EIthe ESB profile. For the REST back-end service, we will use the JAX-RS Basics sample service that is shipped with WSO2 EIthe ESB profile. We will use ActiveMQ as the message broker.

...

  1. Start ActiveMQ and configure the JMS transport in WSO2 EI to work with ActiveMQ .
  2. Build and deploy the JAX-RS Basics sample.
  3. Goto <EI_HOME>/samples/axis2Client and execute the following command:
    ant jmsclient -Djms_type=text -Djms_dest=dynamicQueues/JmsToRestProxy -Djms_payload="<Customer><name>WSO2</name></Customer>"
    This sends <Customer><name>WSO2</name></Customer> as the payload.

In the application server console, you will see the following line printed:

----invoking addCustomer, Customer name is: WSO2 


Excerpt
hiddentrue

Using REST with a proxy service in WSO2 EI