I am trying to access the _clienName from the invocation properties. I tried the below one, but doesnt help. any thoughts ? Is it really possible to access invocation property in a mule flow ?
#[message.invocationProperties['_clientName']]
Message properties:
INVOCATION scoped properties:
__httpEvent=HttpEvent #188...9{apiName=.....95574017,something=99034}
_clientId=680.....81d97344
_clientName=abcd-app
INBOUND scoped properties:
Invocation Properties can be accessed via flowVars: #[flowVars['_clientName']] or #[flowVars._clientName]
Post Mule EE 3.4 there has been a naming change on all the invocation property as FlowVariables . Even now the invocation properties will work if you try using #[flowVars.name] . In the Message properties transformer you have option to set only as invocation properties but it can be accessed as flowVars in rest of the flow.
In mule invocation scoped properties are nothing but flowVars. So you can access them by using the following mule expression
#[flowVars.'_clientName']
in the above expression no need to wrap the _clientName in square brackets, just quote them as I did.
FYI
Session scoped properties are nothing but sessionVars. So you can access them by using #[sessionVars.'_clientName'].
Though you have not asked about session scoped properties, I have answered it because by reading your question I came to know that you are asking the question by seeing the logs in the console caused by the Logger Component of Mule.
The logger, not only logs Invocation scoped properties but also session scoped properties as well. So I guess you might get a question in your mind about what are Session scoped properties, so answered it.
Related
I have a properties file shared on several apps. To access this properties into one app, I use this tag:
<context:property-placeholder location="classpath:br/com/empresa/configuracao/mule-apps.properties"/>
On several Mule components, like database attributes connections, I use the following expression to access the properties, p.e.: ${db.user}. It works!
But on Java Transformer, how I access the properties?
I tried the following instructions, but returned null:
System.getProperty("db.user");
message.getInboundProperty("db.user");
message.getOutboundProperty("db.user");
message.getInvocationProperty("db.user");
Is there a way to access properties into Mule Java Transformer?
This question has been answered for components here: How to get property from context property placeholder tag inside custom java component The exact same logic applies to transformers.
Use property injection:
<custom-transformer class="org.myCompany.CustomTransformer">
<property name="dbUser" value="${db.user}" />
</custom-transformer>
Don't forget to add setDbUser on your custom component!
You could use the old way of retrieving a property:
#Value("${db.user")
private String dbUser;
Context for the question is that: When I use set-variable, then the datamapper recognizes and shows the variable in drop-down but it never shows up when invocation variable is set using Message Properties transformer.
Is this normal?
No it is not normal.
Make sure to use the invocation scope on the message properties transformer.
Message Properties Transformer is the old way of adding variables/properties of different scope to message.
Mule refined the message-properties-transformer and split that into <set-variable>, <set-property> and <set-session-variable> transformers.
Apart from the clear seperation of functionality, this makes the flow more readable and understandable when looking at a flow diagram.
Point to remember is, Message Properties by default adds the property to outbound scope. If you want to add it to invocation scope that have to be mentioned in the scope attribute.
<message-properties-transformer scope="invocation">
<add-message-property key="someKey" value="someValue"/>
</message-properties-transformer>
Hope this helps.
I am using the NamedScoped Ninject extension in an attempt to create object graphs that are constructed everytime a command handler is constructed by the container. In other words, I want a fresh object graph for every command that might get processed by its corresponding handler.
I have used the .DefinesNamedScope("TopLevelOrhcestrator") binding when registering my "command handlers" as they are the top level for command processing.
A type in this named scope needs to be injected with the result of a method call on a type already registered in this named scope. I thought the best way to do this would be with a ninject provider.
Inside the provider I attempt to resolve the type in hopes I can call a method on it to pass into another object I am creating within this named scope. The problem I'm having is that when I ask the IContext for the instance inside the customer provider I get an exception that says "No matching scopes are available, and the type is declared InNamedScope(TopLevelOrchestrator).
context.Kernel.Get<TypeAlreadyRegisteredInScope>().MethodThatGetsAnotherDependency()
Is it possible to get types from the container inside a Ninject provider when they are registered inside a named scope?
EDIT
I apologize if the use case seems a bit odd, I am experimenting with some ideas about how to manage my units of work and other services/managers that may need a handle to the uow to complete a business usecase. I know its common for the unit of work to be "started" and then passed into all dependencies that may need to take part in a larger process. I was thinking I'd rather let my orchestrator take a unit of work factory so that it could deterministically destroy the UOW and it would be clear who the owner of a usecase is. What would get supplied to the managers/services would be a proxy to the unit of work that would be null until a real unit of work was started by the orchestrator. That's why I was attempting to link the proxy from the already registered type in my provider. This is all very experimental at this point and was testing some ideas.
I'd be happy to hear any further thoughts.
For MethodThatGetsAnotherDependency() to be able to .Get<>() an instance that is bound .InNamedScope(...) you will need to add the Context Preservation Extension.
This is because NamedScope is adding a parameter to the request context of the binding that has .DefinesNamedScope(...). As soon as that request is over, that context and it's parameters are forgotten. Now with the ContextPreservation extension the context is kept and reused for late / factory creations (Func<>, interface factory with .ToFactory() binding...). It think it should also work with providers.
If not, just switch to a factory instead of a provider.
However i have to admit that i don't fully understand why/what you are trying to achieve. There might be simpler ways.
How can I access Spring properties defined in app.properties from Mule FuncionalTestCase?
For example, in my production config I have a ${sessionExpiresInSecondsValue} passed in to a bean property. What I want to do is get this value and use it with the FunctionalTestComponent to wait for the same amount of time as that value and I don't want to harcode so the test go out of sync with the value.
The easiest is to get this bean that receives ${sessionExpiresInSecondsValue} from the registry, via MuleContext, and call getSessionExpiresInSecondsValue() on it.
After go through some guides about Mule, I have a question about the component, as it is said in mule documentation,
A simple POJO (Plain Old Java Object) component that will be invoked
by Mule when a message is received. The class or object instance to be
used can be specified using a child object factory element, or via the
'class' attribute. If the 'class' attribute is used, an object
factory cannot be configured as well. Using the 'class' attribute is
equivilant to using the propotype object factory ('prototype-object'
child element).
in this documentation just said the component will be invoked by Mule when a message is received, but a problem is Mule how to know how many methods the component have, and which method should be invoked? or there must one method in the component and no matter the method name? and also mule how to deal with the parameters the method have?
Alternatively, you can use:
<invoke object-ref="..." method="..." methodArguments="..." />
which is way more convenient than configuring entry point resolvers.
yes, I got the answer, the answer is using mule entry point