0

I'm trying to leverage the callout mediator to call a REST endpoint.

But I need to send the contents of a received HTTP header.

I tried:

    <callout passHeaders="false">
        <endpoint>
            <address uri="http://localhost:8888/test"></address>
        </endpoint>
        
        <source xpath="$trp:X-custom-header" />
    </callout>

But this failed with:

 ERROR - CalloutMediator The evaluation of the XPath expression : $trp:X-custom-header did not result in an OMElement

Is it even possible?

rslemos
  • 2,454
  • 22
  • 32
  • What is the reason not to use the mediator? I am asking because: "the Call mediator leverages the non-blocking transports for much greater performance than the Callout mediator, so you should use the Call mediator in most cases." – tmoasz Feb 10 '21 at 08:49
  • I can't find anything about this `` mediator. Perhaps it is not available in WSO2 2.6 (which uses Apache Synapse 2.1.7). Also, performance is not really a concern right now. Feasibility is. Moreover, if by "non-blocking" it means that the call and the remaining chain go in parallel, then it is not what I want... I actually need to wait the call to complete, and augment the original message with its answer. – rslemos Feb 10 '21 at 13:39
  • So, for clarification, what you mean for: "WSO2 2.6" ? WSO2 API Manager 2.6 ?? This product use synapse libraries: 2.1.7-wso2v80 (which is WSO2 fork, not the Apache). If, yes i see in source [CallMediator](https://github.com/wso2/wso2-synapse/blob/v2.1.7-wso2v80/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CallMediator.java) You can also read something in [wso2ei](https://docs.wso2.com/display/EI620/WSO2+EI+Best+Practices#WSO2EIBestPractices-UsingtheCallvs.Calloutvs.Sendmediators) docs. They both uses wso2-synapse – tmoasz Feb 10 '21 at 15:21
  • @tmoasz It looks promising... Thank you for pointing out the `CallMediator`. – rslemos Feb 11 '21 at 14:12

1 Answers1

0

If your header is already available via the $trp scope it should be sent to your endpoint just fine.

If it's not set yet your can set it via the header mediator or the property mediator like so:

<property name="transportHeaderName" value="something" scope="transport"/>

If you need form data like mentioned below you will need to use the payload mediator to create a payload and set the messagetype to multipart/form-data (You might need to enable an extra formatter in the axis2.xml for this)

Payload:

     <payloadFactory media-type="xml">
        <format>
           <root>
              <x-custom-field>text</x-custom-field>
           </root>
        </format>
        <args>
           <arg evaluator="xml" expression="$trp:x-custom-header"/>
        </args>
     </payloadFactory>


<property name="messageType" value="multipart/form-data" scope="axis2"/>
Novren
  • 69
  • 6
  • The header is available in the `$trp` scope.... but the called endpoint does not understand it this way (and I have no control over that). So I must transform a specific header into a form field (the called endpoint expects form data). – rslemos Feb 17 '21 at 15:33
  • Added some additional information that might help. – Novren Feb 19 '21 at 07:06