How do i retrieve the values of MULE Headers like X-MULE_ROOT_MESSAGE_ID and X-MULE_SESSION. When I try to use them from #[message.inboundProperties[X-MULE_ROOT_MESSAGE_ID] I am not able to get values. How do I also get the client IP address from Mule HTTP inbound end point?
These X- headers are extracted and set directly as message properties or a session object.
So you'll find the content of X-MULE_ROOT_MESSAGE_ID by calling getMessageRootId() on the MuleMessage and you'll get the values serialized in X-MULE_SESSION directly in the current MuleSession object.
Read this How to correctly use Mule remote client address property to learn more about the remote IP address.
#[header:INBOUND:MULE_CORRELATION_ID]
you can get like this.
if you need to retrive in the java, you can get all the inbound as map (inbound properties) from message context.
Use Mule expressions to get the mule session id
Related
I have created an API in WSO2 EI.
API is expecting the requests to be send as JSON.
If it is a malformed JSON which is sent, then I should be able to receive it and make appropriate changes to make it a proper JSON.
Any help is much appreciated.
As we are using json-eval($.) to get the message to property, it is not working for me. What else i could try instead of json-eval to get the message as string.
WSO2 EI has the property force.json.message.validation, which can be used to validate incoming JSON payload. Please refer doc to configure this property in 'passthru-http.properties' file.
Once the property is configured, if there is a malformed JSON payload in the request, the mediation flow will be directed to the fault/error sequence. So, you can define the mediation logic to make appropriate changes to the malformed content within the fault sequence of your API.
I have written a custom Anypoint connector (using devkit), and want it to set Inbound properties, much like the Mule HTTP connector does. MuleMessage however, does not seem to have facility to do this.
How does one mimic this behavior?
Inbound properties are immutable, It can be achieved via the MuleMessage https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/MuleMessage.html#setProperty(java.lang.String, java.lang.Object, org.mule.api.transport.PropertyScope)
However, unless your connector operation is a Message Source I wouldn't add inbound properties and instead use outbound properties.
You need to use
MuleMessage message = eventContext.getMessage();
message.setProperty("key","value",PropertyScope.INBOUND);
You can refer the API :-https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/MuleMessage.html#setProperty
https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/transport/PropertyScope.html
I am confused as to what are the elements that are considered necessary to retrieve data for users from an exposed Endpoint like (http://localhost/users/).
Is it http:listener-endpoint or http:listener-config or both?
The thing you're asking is explained in Mule docs
You need both - http connector and its configuration. To listen http://localhost/users/ just specify 'users' in http connector path.
In this sub-flow, how can I access from the http connector (red area) the inbound properties available at green marked area.
The scope of the inbound property is only just after the inbound endpoint or the source endpoint.
Here you should copy your inbound properties to the "flowVars" and then use it across the flow
#[flowVars.paramerterName = message.inboundProperties.'http.query.params'.parameterName]
Please make note if you want to access the HTTP properties, the syntax MEL format will be different for the Mule latest version and old version. The above one is valid for the latest Mule version and the syntax to access any property like below
#[message.inboundProperties.'http.query.params'.cityname]
where as in previous versions
#[message.inboundProperties['propertyName']].
This will depend on your inbound message source, but assuming it is an HTTP connector, use the MEL expression to access the inbound property http.query.params
#[message.inboundProperties['http.query.params']
The inbound message object is nothing but a HashMap of key-value pairs - best would be to use the debugger and select the keys you would like to access.
Here is the documentation for the Mule message, there you will find the description for the different kind of variables and properties. Inbound properties should be propagated from the main flow to the sub-flow and should still be available after the choice, excepting the case where you overwrite them or when there is an outbound-endpoint, which would overwrite them too.
I have a REST client that is preparing payload in JSON format and invoking a REST service. My job is to create the REST service in Mule. I need some information on how I can map the incoming Payload to a java object so that I can invoke the REST service component class and get the values passed in the JSON object. Does the payload after HTTP inbound endpoint already contain the JSON values sent by the client? In which case a simple JSON to Object mapper would map it as Hashmap?
You will most likely need to create a custom transformer for this use case if you have a special use case.
See: http://www.mulesoft.org/documentation/display/current/Creating+Custom+Transformer+Class
If you get sent JSON you can convert it into a custom class like this:
<json:json-to-object-transformer name="jsonToFruitCollection" returnClass="
org.mule.module.json.transformers.FruitCollection"/>
Alternatively You can also use ObjectMapper and can probably use a bean to map your JSON directly to your Java object in your Java class.
You can also use <json:json-to-object-transformer/> directly after your Http inbound endpoint, parse and get each element value in your Mule flow and store in variables. Then these variables can be passed into your Java class where you can map these to your Java object easily.
Both the approach will work fine