Mule Dismantle, Mule example with Logger
Join the DZone community and get the full member experience.
Join For FreeLogger and message
Create a mule flow, add an http end point with the default host and port name.
Host: localhost
Port: 8081
Note: For practicing always use an http end point as it is easy to create and test.
Then add a logger component with the message value as #[payload], followed by one more logger component with message value as #[message].
The flow will look like this:
And the xml configuration looks as below:
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:http="http://www.mulesoft.org/schema/mule/http" 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.5.0" 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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> <flow name="dismantlemuleFlow1" doc:name="dismantlemuleFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/> <logger message="#[payload]" level="INFO" doc:name="Logger"/> <logger message="#[message]" level="INFO" doc:name="Logger"/> </flow> </mule>
Run the application and hit the url with http://localhost:8081/testdata and you will get the following output in the console.
I
NFO 2015-01-28 08:30:10,677 [[dismantlemule].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: /testdata INFO 2015-01-28 08:30:10,692 [[dismantlemule].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: org.mule.DefaultMuleMessage { id=c5cde650-a699-11e4-8792-a0d3c169f60f payload=java.lang.String correlationId=<not set> correlationGroup=-1 correlationSeq=-1 encoding=UTF-8 exceptionPayload=<not set> Message properties: INVOCATION scoped properties: INBOUND scoped properties: Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding=gzip, deflate Accept-Language=en-US,en;q=0.5 Connection=true Host=localhost:8081 Keep-Alive=true MULE_ORIGINATING_ENDPOINT=endpoint.http.localhost.8081 MULE_REMOTE_CLIENT_ADDRESS=/127.0.0.1:50584 User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0 http.context.path=/ http.context.uri=http://localhost:8081 http.headers={Keep-Alive=true, Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, Connection=true, User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0, Host=localhost:8081, Accept-Encoding=gzip, deflate, Accept-Language=en-US,en;q=0.5} http.method=GET http.query.params={} http.query.string= http.relative.path=testdata http.request=/testdata http.request.path=/testdata http.version=HTTP/1.1 OUTBOUND scoped properties: MULE_ENCODING=UTF-8 SESSION scoped properties: }
The first line Is the output of the #[payload] mule expression, which as the name suggest prints the payload.
INFO 2015-01-28 08:30:10,677 [[dismantlemule].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: /testdata
And rest are the output of #[message] which gives the complete information of the message.
Note: Logging output of the payload will be very useful in debugging, like system.out.println in java. As it gives the clear information of how the payload looks at different stage of the flow.
Opinions expressed by DZone contributors are their own.
Comments