wso2wso2-enterprise-integrator

How to save HTML response from API call into a property in WSO2 Integration Studio?



I am working on a WSO2 Integration Studio project where I need to call an external API that returns an HTML response. I want to save this response into a property so I can use it later in the flow (e.g., logging or processing).

Here is the relevant part of my configuration:

<resource methods="GET" uri-template="/currentsession">
   <inSequence>
      <call>
         <endpoint>
            <http method="get" uri-template="http://example.com/api">
               <suspendOnFailure>
                  <initialDuration>-1</initialDuration>
                  <progressionFactor>-1</progressionFactor>
                  <maximumDuration>0</maximumDuration>
               </suspendOnFailure>
               <markForSuspension>
                  <retriesBeforeSuspension>0</retriesBeforeSuspension>
               </markForSuspension>
               <authentication>
                  <basicAuth>
                     <username>test</username>
                     <password>test</password>
                  </basicAuth>
               </authentication>
            </http>
         </endpoint>
      </call>

      <!-- Attempt to save response -->
      <property name="response" scope="default" type="STRING" expression="$ctx:ORIGINAL_MESSAGE"/>

      <!-- Logging the saved property -->
      <log>
         <property expression="get-property('response')" name="tt"/>
      </log>

      <respond/>
   </inSequence>
   <outSequence/>
   <faultSequence/>
</resource>

However, this setup does not store the actual HTML response in the response property as expected. The log shows it as empty or null.


What I’ve tried


My questions

  1. How can I correctly capture the HTML response body from the <call> mediator and save it in a property?
  2. Is $ctx:ORIGINAL_MESSAGE the correct expression for this use case? If not, what should I use?
  3. Do I need to explicitly convert or buffer the payload to access it via a property?


Solution

  • Did you mean to do the below? I don't see you have assigned a value to ORIGINAL_MESSAGE.

    <property name="response" scope="default" type="STRING" expression="$body"/>
    <log>             
       <property expression="get-property('response')" name="tt"/>   
    </log> 
    

    Update

    Add the following to the deployment.toml. Make sure the content_type is the same as the Content-Type header that comes in the response.

    [[custom_message_builders]]
    class = "org.apache.axis2.format.PlainTextBuilder"
    content_type = "text/html"