Below is my Json
{"caseType":"CashLess","claimNo":9.0}
how to get caseType value in logger.
below my config XML
<json:json-to-object-transformer doc:name="JSON to Object"/>
<logger message="#['\n JSON::\n'+ message.payload.caseType+'\n']" level="INFO" doc:name="Logger"/>
but it is giving error.
Thanks.
need to add returnClass="java.util.HashMap" in json:json-to-object-transformer
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.HashMap"/>
Related
I am trying to capture error status from one API & and send it to the calling API. In my downstream API I have the following catch exception strategy:
<catch-exception-strategy>
<set-payload value= "500" />
<logger message="***BACKEND API: #[payload]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
In my calling API I have the following:
<http:request config-ref="downstream API " path="/downstream/{id}" method="POST " doc:name="Generate "/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="PAYLOAD: #[payload]" level="INFO" doc:name="Logger"/>
However I am able to print the payload in the downstream API but not in the calling API. Am I missing something?
If your API throw http.status == 500, it should trigger this condition
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[message.inboundProperties.'http.status' == 500]" doc:name="Error 500">
<set-payload value= "500" />
<logger message="***BACKEND API: #[payload]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
I you didn't add any condition, it should be the default catch exception
everything should work properly.
I have a simple csv-to-pojo datamapper, which gets sent to two synchronous flow through an "All" flow control component. The first flow runs the payload through a Foreach, then once it is done, the second flow attempts to run the payload from the datamapper again through a different foreach, but instead I'm getting this warning message:
Splitter returned no results. If this is not expected, please check your split expression.
Furthermore, it seems that Mule only allows me to run the payload through either flow one or flow two, but not both. Again, running it trough more than one Foreach component will result in the Splitter warning.
Any help will be appreciated. Thanks in advance. Here's the setup:
<flow name="main_flow" doc:name="main_flow" initialState="started" processingStrategy="synchronous">
<data-mapper:transform config-ref="csv_to_pojo" doc:name="CSV To Pojo" stream="true"/>
<all doc:name="All">
<flow-ref name="flow1" doc:name="Flow Reference"/>
<flow-ref name="flow2" doc:name="Flow Reference"/>
</all>
</flow>
<flow name="flow1" doc:name="flow1" processingStrategy="synchronous">
<logger message="Entering flow 1" level="INFO" doc:name="Logger"/>
<foreach doc:name="For Each">
<logger message="Inside foreach of flow1 " level="INFO" doc:name="Logger"/>
</foreach>
</flow>
<flow name="flow2" doc:name="flow2" processingStrategy="synchronous">
<logger message="Entering flow2" level="INFO" doc:name="Logger"/>
<foreach doc:name="For Each">
<logger message="Inside foreach of flow2" level="INFO" doc:name="Logger"/>
</foreach>
</flow>
In my Mule app, I've configured some of the flows to use a catch exception strategy in order to do some special processing. For these cases, I want to pop the error and the original payload into an object store. Everywhere else, the default exception strategy is fine.
<flow name="saveLookup">
<vm:inbound-endpoint exchange-pattern="one-way" ref="Lookup_Save_VM" />
<component>
<spring-object bean="insertLookupMDCvalues"/>
</component>
<set-variable variableName="originalPayload" value="#[payload]"/>
<json:json-to-object-transformer returnClass="com.company.LookupData"/>
<set-variable variableName="transactionId" value="#[payload.transactionId]"/>
<transactional action="ALWAYS_BEGIN">
<logger message="${lookup.SQL}" level="INFO"/>
<jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="saveLookup" queryTimeout="-1" connector-ref="JdbcConnector" />
<foreach collection="#[payload.transactional.lookupItems.items]">
<logger message="${lookup.item.SQL}" level="INFO" />
<jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="saveLookupItem" queryTimeout="-1" connector-ref="JdbcConnector"/>
</foreach>
</transactional>
<component>
<spring-object bean="clearLookupMDCvalues"/>
</component>
<catch-exception-strategy>
<message-properties-transformer scope="invocation">
<add-message-property key="errorMap" value="#[['id' : transactionId, 'body' : originalPayload, 'error' : exception.summaryMessage]]"/>
</message-properties-transformer>
<choice>
<when expression="#[message.inboundProperties['resubmit']]">
<logger message="Resubmission of lookup data failed, saving to Dead Letter object store. ID=#[transactionId]" level="INFO"/>
<objectstore:store config-ref="lookupDeadLetterOS" key="#[transactionId]" overwrite="true" value-ref="#[errorMap]"/>
</when>
<otherwise>
<logger message="Saving lookup data failed, saving to Error object store. ID=#[transactionId]" level="INFO"/>
<objectstore:store config-ref="lookupErrorOS" key="#[transactionId]" overwrite="true" value-ref="#[errorMap]"/>
</otherwise>
</choice>
<set-payload value="Error: #[exception.summaryMessage]"/>
<component>
<spring-object bean="clearLookupMDCvalues"/>
</component>
</catch-exception-strategy>
</flow>
My problem is that when an error is encountered, let's say a Null Pointer Exception in the foreach component, I'm seeing four ERROR log statements for each event:
Exception stack is: 1. null (java.lang.NullPointerException) ...and so on. This is logged twice.
CatchMessagingExceptionStrategy - Message : Execution of the expression "payload.transactional.lookupItems.items" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: LookupData
DefaultMessagingExceptionStrategy - Message : Execution of the expression "payload.transactional.lookupItems.items" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: LookupData
I thought that a flow-specific exception strategy should override the default strategy. Why the duplicate log messages, and is there a way to shush them? I'd like to avoid having to configure the default exception strategy, as it's perfectly acceptable behavior in the majority of the flows.
The issue is that the built in exception strategies inherit from AbstractExceptionListener, and they all use the logException template method. The base implementation always logs at ERROR level, which is sometimes not appropriate for your application.
You can create a simple subclass of CatchMessagingExceptionStrategy that overrides the logException method, and logs however you want. Then, use it in your flow in place of the <catch-exception-strategy> like so:
<custom-exception-strategy class="com.mycompany.mule.QuietCatchExceptionStrategy">
<!-- your message processors here -->
</custom-exception-strategy>
I am new for MuleESB. I don't have much knowledge about flow. I couldn't find proper documentation for Mule. I am trying to fetch the data from database using below code, but I am unable fetch the data. There is no error shown, so I dont know what to do. Is my flow correct?
Here's my flow config.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<jdbc-ee:postgresql-data-source name="PostgreSQL_Data_Source" user="youtilitydba" password="Youtility11" url="jdbc:postgresql://localhost:5432/sample" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source"/>
<jdbc-ee:connector name="Database" dataSource-ref="PostgreSQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<flow name="selectfromdbFlow1" doc:name="selectfromdbFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="selectdb" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="SELECT" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc-ee:query key="SELECT" value="select firstname,lastname,id from users where id =#[message.payload.id]"/>
</jdbc-ee:outbound-endpoint>
<response>
<http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder"/>
</response>
<set-payload value="#[payload]" doc:name="Set Payload"/>
<echo-component doc:name="Echo"/>
</flow>
</mule>
I am sending request from curl client like this
curl -H "Content-Type: application/json" -d '{"id":"5"}' http://192.168.25.24:8081/selectdb
It doesn't provide and response back.
I am expecting a response like the one below.
{"Body":{"Datalist":{"firstname":"ff","lastname":"ggg","id":"5"}},"Status":"200"}}
Please help me acheive this.
Even the logger statement is not printing
<logger message="message of payload#[message.payload]" level="INFO" doc:name="Logger"/>
Appreciate any help.
You can better use <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/> after http:inbound-endpoint and make sure if you are getting the id value from request and after payload after db
Now, if you are getting the data from your db and able to print it using a logger after db using
<logger message="message of payload #[message.payload]" level="INFO" doc:name="Logger"/>
You can explicitly set your response to your client in following way :-
<http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder">
<set-payload value="#[message.payload]" doc:name="Set Payload"/>
</http:response-builder>
and you can remove the <response/> tag from your flow, as you are setting your response payload using <http:response-builder/> as above
I can't answer your question fully, but can tell you few easy ways to inspect your muleMessage.
the first and easiest way is to place a script transformer like this:
<script:transformer>
<script:script engine="groovy">
<script:text>
System.out.println(payload);
return payload;
</script:text>
</script:script>
</script:transformer>
namespace: xmlns:script="http://www.mulesoft.org/schema/mule/scripting"
schemaLocation: http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
second option and harder one would be creating custom transformer. U'll need to create a java class, extend the AbstractMessageTransformer. Then debug your project and see what's the message
hope, this will help
Couldn't get the complete issue you are facing. From the post I can see there are few changes to be made.
As you are looking for data back from Select Query change the exchange-pattern on the JBDC:Outbound to request-response
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="SELECT" queryTimeout="-1" connector-ref="Database" doc:name="Database">
Also there is no need of the <set-payload> at the end of the flow. As the payload is already available in the message, this is a redundant statement.
In the logger try using #[payload] as it is more simple to print your payload (response from JBDC query)
About documentation, MuleSoft website is the best place to find documentation about mule They have a detailed documentation for most of the things of Mule.
Mule User Guide and Documentation
Hope this helps.
I've been struggling through SO and the Mule forums but can't find a solution that works. The esb takes in a single request containing an id, which creates an XML payload that is composed a list of related ids. This XML payload is then split and sent to a transformer that takes each related id to get some meta data. The results are then supposed to be combined together to make an XML response. The problem I am having is that no matter how I transform the final result set, I always get back the document with an encapsulating string "??sr)java.util.concurrent.CopyOnWriteArrayListx]....""x
Any ideas/comments would be greatly appreciated.
Here is the mule-config I am using:
<http:connector name="HttpConnector" doc:name="HTTP\HTTPS"/>
<expression-transformer name="ExtractId" doc:name="Expression">
<return-argument evaluator="xpath" expression="//string[1]"/>
</expression-transformer>
<flow name="myFlow1" doc:name="myFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="incoming/path/" connector-ref="HttpConnector" doc:name="HTTP"/>
<custom-transformer encoding="UTF-8" class="mycomponents.transformers.SubscriberRequestTransformer" doc:name="Create Hub Id Requests"/>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<splitter evaluator="xpath" expression="//entry/list/string" enableCorrelation="ALWAYS" doc:name="Splitter"/>
<transformer ref="ExtractId" doc:name="Transformer Reference"/>
<logger message="#[payload:]" level="INFO" doc:name="Logger"/>
<custom-transformer encoding="UTF-8" class="mycomponents.transformers.HubQueryProcessor" doc:name="Create Hub Id Requests"/>
<collection-aggregator />
<component class="mycomponents.TopicResponseAggregatorComponent" doc:name="Collect requests" />
<logger message="Aggregated Content (#[groovy:payload.size()] elements): \n#[payload:]" level="INFO" doc:name="Logger"/>
<logger message="#[payload:]" level="INFO" doc:name="Logger"/>
</flow>
I've resolved the issue. Although I don't quite understand why it's different but I'm assuming it has to do with some of the mule "magic". I split up the flow into multiple flows which is what I was eventually going to do anyways. However, by doing this the problem went away.
FYI: here's the updated flow:
<flow name="myFlow1" doc:name="myFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="url/for/service/" connector-ref="HttpConnector" doc:name="HTTP"/>
<flow-ref name="createHubIdRequestsFlow" doc:name="Map To Hub Ids" doc:description="Takes in the situation id passed in by the client. Does the query lookup versus the content mapping tables. creates the correspondng requests for meta data information to the provider(s)"/>
<flow-ref name="getTopicRequests" doc:name="Process Provider Reponses" doc:description="For each JSON response returned from the provider, transform it into an XML representation of that data"/>
<flow-ref name="buildResponseFlow" doc:name="Build final response" doc:description="piece all the messages together into a single object as a string"/>
<response>
<message-properties-transformer>
<add-message-property value="text/xml" key="Content-Type" />
</message-properties-transformer>
</response>
</flow>
By default, the message properties transformer stores new properties in the "invocation" scope. You need to set the content-type on the "outbound" scope so it is used by the inbound HTTP endpoint in its response phase.
Try this:
<response>
<message-properties-transformer scope="outbound">
<add-message-property value="text/xml" key="Content-Type" />
</message-properties-transformer>
</response>