Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mule - How can I use set-session-variable in http:listener?

I have a composite-source consist of two http:listener in Mule;

I want to set a variable based on each of the listeners after receive requests from these listeners ;

but this error occurs while deploys in mule 3.6.0:

org.mule.module.launcher.DeploymentInitException: SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'set-session-variable'. One of '{"http://www.mulesoft.org/schema/mule/core":annotations, "http://www.mulesoft.org/schema/mule/http":response-builder, "http://www.mulesoft.org/schema/mule/http":error-response-builder}' is expected.

What should I do??

Here is my code:

<composite-source doc:name="Composite Source">
  <http:listener config-ref="HTTP_Listener_Configuration_Source1"
    path="/" doc:name="HTTP">
        <set-session-variable doc:name="Session Variable" value="#[x]" variableName="x" />
  </http:listener>
  <http:listener config-ref="HTTP_Listener_Configuration_Source2"
                path="/" doc:name="HTTP">
        <set-session-variable doc:name="Session Variable" value="#[y]" variableName="x" />
  </http:listener>
</composite-source>

P.S. I have done it with http:inbound-endpoint

like image 597
Mojtaba Avatar asked May 24 '15 14:05

Mojtaba


People also ask

How do I set session variables in Mule 4?

There is only one type of variable in mule 4. It's scope is same as session variable. You can use set variable component for setting the variable and then fetch it using # [vars. variableName] in dataweave language.

What is the use of set variable in Mulesoft?

The Set Variable ( set-variable ) component is for creating or updating a Mule variable to store values for use within the flow of a Mule app. A Mule variable is part of the Mule event. You can store simple literal values such as strings or messages, message payloads, or attribute objects.

How do you set a flow variable in Mule?

Flow variables are set or removed using a Variable transformer and cannot cross the transport barriers. Flow Variables can pass from one Flow to another only when using a flow reference component. Syntax to access flow variable is :#[flowVars. Code], where Code is the name of the flow variable.

What base path value should be set in an http listener config element so that?

What base path value should be set in an HTTP Listener config element so that it can be used to configure both HTTP Listeners? D) /apis/? The correct answer to this question is C. Each HTTP Listener has an HTTP Listener configuration.


1 Answers

It's illegal to put a set-session-variable there: the Mule schema does not allow it.

The reason is that http:listener is not a regular endpoint, like http:inbound-endpoint is, thus doesn't support this kind of nesting, like all other endpoints do.

This is unfortunate and hopefully something that will get fixed eventually. In the meantime, you need to find another way to discriminate requests coming between these two listeners.

For this I recommend you check all the inbound message properties they created, looking for a differentiator. I'm expecting a MULE_ property to be usable here but you'll have to check in your particular context, with the specific HTTP_Listener configurations you are using.

like image 188
David Dossot Avatar answered Oct 13 '22 21:10

David Dossot