Thursday, October 15, 2015

Send images for REST API in WSO2 ESB

In this tutorial I will explain how to send images for REST API in WSO2 ESB from SOAP UI

1. Set up the SOAP UI to send images as multi part request (described to previous post). 
The url for endpoint is created by localhost:port/<context >/<url_mapping>  which is defined when creating the API in ESB

2. Now SOAP UI is ready to send the request.Then ESB to receive messages of the image/jpeg content type, 
add the following configurations to the 
<ESB_HOME>/repository/conf/axis2/axis2.xml file

In the Message Builders section:

<messageBuilder contentType="image/jpeg"
                        class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
In the Message Formatters section:
<messageFormatter contentType="image/jpeg"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
3. Create the API as following 

  • Go to Main->Service Bus->APIS and click ADD API
  • Then give the API name ,context and click Add Resource
  • Then Add Resource details like methods, url style, in sequence etc. and click update
  • Then go to source view and you will be able to similar API as below.
<api xmlns="http://ws.apache.org/ns/synapse" name="PublicTrafficViolationAPI" context="/dpservice/api/publictrafficviolation">
   <resource methods="POST" url-mapping="/save">
      <inSequence>
         <send>
            <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService"></address>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send></send>
      </outSequence>
   </resource>
</api>
3. Enable the wire in log4j.properties by un-commenting log4j.logger.org.apache.synapse.transport.
http.wire=DEBUG inside <ESB_HOME>/repository/conf

4. Send the http request through SOAP UI and have a look to the wso2carbon.log 
(<ESB_HOME>/repository/logs)

5. You will be able to see similar log as below. ">>" indicate the incoming request to ESB 
and "<<" indicated the outgoing request from ESB

Thanks

1 comment:

  1. Hi,
    I am also having similar use case. I need to send image to salesforce, but i don't know how to achieve this. can you give me some tips ?

    ReplyDelete

Blogger Widgets