0

I am pretty new to mule and am working on a dynamic routing using mule. At run time I am getting the port number where my service is hosted.

Please find my code below:

  <script:component doc:name="Script">
    <script:script engine="groovy">
      <![CDATA[
        String endpnt = reqUrl.prepareFile(requestUrl);
        message.setProperty('port', reqUrl.getPort(),org.mule.api.transport.PropertyScope.INVOCATION);

       ]]>
    </script:script>
  </script:component>

<logger message="#[flowVars['port']]" level="INFO" doc:name="port" />

        <http:request config-ref="FlowRef"
                    path="/subflow" method="GET" doc:name="Invoke Dynamic service" />

The above script returns me the port number on which the service is hosted and am invoking the same using

<flow name="testFlow1">
    <http:listener config-ref="BaseRef" path="/subflow"
        doc:name="Eval" />
    <logger message="calling testFlow1 service" level="INFO" doc:name="Logger" />

    <http:request config-ref="ServiceMonProxy1" path="/"
        method="GET" doc:name="Credit validation"/>
</flow>

The problem is "#[flowVars['port']]" is not getting resolved at runtime and mule is throwing me an exception which says improper port

Please assist.

Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57

2 Answers2

0

Try to return the message in your script :

<script:component doc:name="Script">
<script:script engine="groovy">
  <![CDATA[
    String endpnt = reqUrl.prepareFile(requestUrl);
    message.setProperty('port', reqUrl.getPort(),org.mule.api.transport.PropertyScope.INVOCATION);
    return message;
   ]]>
</script:script>

Hope it helps.

/Tony

Tony K
  • 128
  • 12
0

Found an answer. Please find the below code

just replaced

<http:request config-ref="FlowRef"
               path="/subflow" method="GET" doc:name="Invoke Dynamic service" />

with

<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="#[flowVars['port']]" path="a" doc:name="HTTP"/>

and it worked.

Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57