dev
dev

Reputation: 97

Mule Flow not able to invoke exception strategy

I have following Code for my Mule FLOW and seems like something is wrong with my code which is not allowing to invoke Catch Exception Strategy, What are the corrections required here ?

<flow name="Mule_Common_FTP_EDI_FilesProcessing_Inbound" doc:name="Mule_Common_FTP_EDI_FilesProcessing_Inbound"
        processingStrategy="synchronous">
        <quartz:inbound-endpoint cronExpression="${ftp.edi.inbound.cronExpression}" responseTimeout="${ftp.edi.inbound.root.responseTimeout}" jobName="pollingFTPFiles" doc:name="Quartz"  connector-ref="pollingFTPFilesConnector">
            <quartz:event-generator-job/>
       </quartz:inbound-endpoint>
       <set-payload value="#[[${ftp.edi.inbound.carriers.path}]]" doc:name="Set Payload"/> 
       <foreach doc:name="For Each">
            <flow-ref name="Initialise-logging-variables" doc:name="Flow Reference"/>
        <set-variable value="#[payload]" variableName="processing_folder_path" doc:name="Variable processing_folder_path" />
        <mulerequester:request config-ref="FTP_Requester" resource="ftp://${ftp.edi.inbound.root.user}:${ftp.edi.inbound.root.password}@${ftp.edi.inbound.root.host}:${ftp.edi.inbound.root.port}${ftp.edi.inbound.root.path}#[payload]" timeout="${ftp.edi.inbound.root.responseTimeout}" doc:name="Mule Requester"/>
            <choice doc:name="Choice">
                <when expression="#[message.payload != null]">
                    <set-variable variableName="careerName" value="#[groovy:String s = flowVars.processing_folder_path; s.substring(0,s.indexOf('-'))]" doc:name="Variable careerName"/>
                    <set-variable variableName="filename" value="#[variable:careerName]-_#[message.outboundProperties['originalFilename']]" doc:name="Variable filename"/>                    
                    <file:file-to-string-transformer doc:name="File to String"/>
                    <set-variable variableName="InputPayload" value="#[payload:]" doc:name="Variable InputPayload"/>
                    <choice doc:name="Choice">
                          <when expression="#[regex(app.registry.configProperties[careerName])]">
                            <scripting:component doc:name="Script">
                                <scripting:script engine="Groovy" file="generateWSRequest.groovy"/>
                            </scripting:component>
                            <message-properties-transformer doc:name="Message Properties">
                                <add-message-property key="SOAPAction" value="/ProcessService/PDoc"/>
                            </message-properties-transformer>
                            <http:outbound-endpoint exchange-pattern="request-response" host="${http.host}" port="${http.port}" path="yourservices/service.svc" responseTimeout="${http.timeout.sync}" contentType="text/xml" connector-ref="httpConnector" doc:name="HTTP"/>
                            <byte-array-to-string-transformer doc:name="Byte Array to String"/>
                            <set-variable value="#[message.payload.toString()]" variableName="OutputPayload" doc:name="Variable"/>
                            <choice doc:name="Choice">
                                <when expression="message.getInboundProperty('http.status') == '200'" evaluator="groovy">
                                    <set-payload value="#[variable:InputPayload]" doc:name="Set Payload"/>
                                    <file:outbound-endpoint path="${ftp.edi.outbound.root.success.path}" outputPattern="#[variable:filename]" responseTimeout="10000" doc:name="File"/>
                                    <set-payload value="#[variable:InputPayload]" doc:name="Set Payload"/>
                                    <ftp:outbound-endpoint host="${ftp.edi.inbound.root.host}" port="${ftp.edi.inbound.root.port}" path="${ftp.edi.elementum.copy.path}" user="${ftp.edi.inbound.root.user}" password="${ftp.edi.inbound.root.password}" outputPattern="#[message.outboundProperties['originalFilename']]" mimeType="text/plain" doc:name="FTP"/>                                    
                                </when>
                                <otherwise>
                                    <set-payload value="#[variable:InputPayload]" doc:name="Set Payload"/>
                                    <set-variable variableName="original_message" value="#[groovy:message.toString()]" doc:name="original_message" />               
                                    <set-attachment attachmentName="#[message.outboundProperties['originalFilename']]" value="#[payload]" contentType="text/xml" doc:name="originalFileAttachment"/>                
                                    <set-variable variableName="content" value="${smtp.service.failure.body}, Splunk txId=#[sessionVars.logTxid] #[System.getProperty('line.separator')] #[System.getProperty('line.separator')] #[variable:logErrmsg] #[System.getProperty('line.separator')] #[System.getProperty('line.separator')] #[variable:original_message] #[System.getProperty('line.separator')]" doc:name="EmailBodyContent" />
                                    <set-payload value="#[variable:content]" doc:name="Set Payload"/>
                                    <set-variable variableName="subjectEmail" value="${smtp.service.failure.subject}filename=#[message.outboundProperties['originalFilename']]" doc:name="Variable"/>
                                    <smtp:outbound-endpoint host="${smtp.host}"  port="${smtp.port}" to="${smtp.to}" from="${smtp.from}" subject="#[variable:subjectEmail]" responseTimeout="10000" doc:name="HTTP_EMAIL_ALERT" mimeType="text/plain"/>                                                
                                    <set-payload value="#[variable:InputPayload]" doc:name="Set Payload"/>
                                    <file:outbound-endpoint path="${ftp.edi.outbound.root.reprocesspath}" outputPattern="#[variable:filename]" responseTimeout="10000" doc:name="File"/>
                                    <set-payload value="#[variable:InputPayload]" doc:name="Set Payload"/>
                                    <ftp:outbound-endpoint host="${ftp.edi.inbound.root.host}" port="${ftp.edi.inbound.root.port}" path="${ftp.edi.elementum.copy.path}" user="${ftp.edi.inbound.root.user}" password="${ftp.edi.inbound.root.password}" outputPattern="#[message.outboundProperties['originalFilename']]" mimeType="text/plain" doc:name="FTP"/>
                                </otherwise>
                            </choice>
                        </when>
                        <otherwise>
                            <set-variable variableName="original_message" value="#[groovy:message.toString()]" doc:name="original_message" />               
                            <set-attachment attachmentName="#[message.outboundProperties['originalFilename']]" value="#[payload]" contentType="text/xml" doc:name="OriginalFileAttachment"/>                
                            <set-variable variableName="content" value="${smtp.file.not.supported.body}, Splunk txId=#[sessionVars.logTxid] #[System.getProperty('line.separator')] #[System.getProperty('line.separator')] #[variable:logErrmsg] #[System.getProperty('line.separator')] #[System.getProperty('line.separator')] #[variable:original_message] #[System.getProperty('line.separator')]" doc:name="EmailBodyContent" />
                            <set-payload value="#[variable:content]" doc:name="Set Payload"/>
                            <set-variable variableName="subjectEmail" value="${smtp.file.not.supported.subject}filename=#[message.outboundProperties['originalFilename']]" doc:name="Variable"/>
                            <smtp:outbound-endpoint host="${smtp.host}"  port="${smtp.port}" to="${smtp.to}" from="${smtp.from}" subject="#[variable:subjectEmail]" responseTimeout="10000" doc:name="REGEX_NOT_FOUND_EMAIL_ALERT" mimeType="text/plain"/>
                            <logger message="{message = Email Sent to ${smtp.to}}" level="ERROR" doc:name="Logger"/>
                            <file:outbound-endpoint path="${ftp.edi.outbound.root.failedpath}" outputPattern="#[variable:filename]" responseTimeout="10000" doc:name="File"/>
                        </otherwise>
                    </choice>
                </when>
                <otherwise>
                            <logger message="{InboundPath=#[processing_folder_path], Message= REQUEST NOT PROCESSED NO MATCHING TEXT FOUND}" level="DEBUG" doc:name="Logger"/>
                </otherwise>
            </choice>
        </foreach>
        <choice-exception-strategy doc:name="Choice Exception Strategy">
            <rollback-exception-strategy  when="exception.causedBy(java.net.ConnectException) || exception.causedBy(java.net.SocketTimeoutException) || exception.causedBy(java.net.SocketException) || exception.causedBy(java.lang.Throwable)" maxRedeliveryAttempts="4" doc:name="Rollback Exception Strategy">
                <on-redelivery-attempts-exceeded doc:name="Redelivery exhausted">
                    <set-variable variableName="errorMessage" value="{InboundPath=#[processing_folder_path], Ref= #[message.outboundProperties['originalFilename']], Content= #[groovy:payload.toString().replaceAll('\n', '')], Flow= #[variable:careerName], Message= MAXIMUM RETRIES REACHED}" doc:name="Variable"/>
                    <logger message="#[variable:errorMessage]" level="ERROR" doc:name="Logger"/>
                    <set-variable variableName="original_message" value="#[groovy:message.toString()]" doc:name="original_message" />               
                    <set-attachment attachmentName="#[message.outboundProperties['originalFilename']]" value="#[payload]" contentType="text/xml" doc:name="OriginalFileAttachment"/>                
                    <set-variable variableName="content" value="${smtp.rollback.body}, Splunk txId=#[sessionVars.logTxid] #[System.getProperty('line.separator')] #[System.getProperty('line.separator')] #[variable:logErrmsg] #[System.getProperty('line.separator')] #[System.getProperty('line.separator')] #[variable:original_message] #[System.getProperty('line.separator')]" doc:name="EmailBodyContent" />
                    <set-payload value="#[variable:content]" doc:name="Set Payload"/>
                    <set-variable variableName="subjectEmail" value="${smtp.rollback.subject}filename=#[message.outboundProperties['originalFilename']]" doc:name="Variable"/>
                    <smtp:outbound-endpoint host="${smtp.host}"  port="${smtp.port}" to="${smtp.to}" from="${smtp.from}" subject="#[variable:subjectEmail]" responseTimeout="10000" doc:name="RETRY_FAILURE_EMAIL_ALERT" mimeType="text/plain"/>            
                    <logger message="{message = Email Sent to ${smtp.to}}" level="ERROR" doc:name="Logger"/>
                    <file:file-to-string-transformer doc:name="File to String"/>
                    <file:outbound-endpoint path="${ftp.edi.outbound.root.failedpath}" responseTimeout="10000" outputPattern="#[message.outboundProperties['originalFilename']]" doc:name="File"/>                   
                </on-redelivery-attempts-exceeded>
            </rollback-exception-strategy>            
            <catch-exception-strategy when="exception.causeMatches(java.*)" doc:name="Data Errors Catch Exception Strategy">
                    <set-variable variableName="errorMessage" value="{InboundPath=#[processing_folder_path], Ref= #[message.outboundProperties['originalFilename']], Content= #[groovy:payload.toString().replaceAll('\n', '')], Flow= #[variable:careerName], Message=Common Exception Occured look at exception stackTrace for more details}" doc:name="Variable"/>
                    <logger message="#[variable:errorMessage]" level="ERROR" doc:name="Logger"/>
                    <set-variable variableName="original_message" value="#[groovy:message.toString()]" doc:name="original_message" />               
                    <set-attachment attachmentName="#[message.outboundProperties['originalFilename']]" value="#[payload]" contentType="text/xml" doc:name="OriginalFileAttachment"/>                
                    <set-variable variableName="content" value="${smtp.catch.exception.body}, Splunk txId=#[sessionVars.logTxid] #[System.getProperty('line.separator')] #[System.getProperty('line.separator')] #[variable:logErrmsg] #[System.getProperty('line.separator')] #[System.getProperty('line.separator')] #[variable:original_message] #[System.getProperty('line.separator')]" doc:name="EmailBodyContent" />
                    <set-payload value="#[variable:content]" doc:name="Set Payload"/>
                    <set-variable variableName="subjectEmail" value="${smtp.catch.exception.subject}filename=#[message.outboundProperties['originalFilename']]" doc:name="Variable"/>
                    <smtp:outbound-endpoint host="${smtp.host}"  port="${smtp.port}" to="${smtp.to}" from="${smtp.from}" subject="#[variable:subjectEmail]" responseTimeout="10000" doc:name="CATCH_EXCEPTION_EMAIL_ALERT" mimeType="text/plain"/>            
                    <logger message="{message = Email Sent to ${smtp.to}}" level="ERROR" doc:name="Logger"/>
                    <file:file-to-string-transformer doc:name="File to String"/>
                    <file:outbound-endpoint path="${ftp.edi.outbound.root.failedpath}" responseTimeout="10000" outputPattern="#[message.outboundProperties['originalFilename']]" doc:name="File"/>                   
            </catch-exception-strategy> 
        </choice-exception-strategy>        
    </flow>

I am trying to put invalid WEBSERVICE URL here which is causing this error and i want to catch those kind of errors and send out emails if service is down or configuration is wrong and not able to process the files :

What i need to change here in my code which will allow me to receive email notification about this error ? Can you please advice me what's wrong with Exception Strategy here?

INFO  2015-04-29 11:31:40,105 [scheduler-edi-ftp-file-processing-1.0.0-SNAPSHOT-v20150427-19+32_Worker-1] org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest: Content-Type not set on outgoing request, defaulting to: text/plain
ERROR 2015-04-29 11:31:40,123 [scheduler-edi-ftp-file-processing-1.0.0-SNAPSHOT-v20150427-19+32_Worker-1] org.mule.exception.DefaultSystemExceptionStrategy: 
********************************************************************************
Message               : Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=http://myservice.company.com:80/services/service.svc, connector=HttpConnector
{
  name=httpConnector
  lifecycle=start
  this=4d81bcef
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[http]
  serviceOverrides=
    session.handler=org.mule.session.NullSessionHandler
}
,  name='endpoint.http.myservice.company.com.80.services.service.svc', mep=REQUEST_RESPONSE, properties={Content-Type=text/xml}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=120000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: PostMethod
Code                  : MULE_ERROR-42999
--------------------------------------------------------------------------------
Exception stack is:
1. myservice.company.com (java.net.UnknownHostException)
  java.net.AbstractPlainSocketImpl:175 (null)
2. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=http://myservice.mycompany.com:80/services/service.svc, connector=HttpConnector
{
  name=httpConnector
  lifecycle=start
  this=4d81bcef
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[http]
  serviceOverrides=
    session.handler=org.mule.session.NullSessionHandler
}
,  name='endpoint.http.myservice.company.com.80.services.service.svc', mep=REQUEST_RESPONSE, properties={Content-Type=text/xml}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=120000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: PostMethod (org.mule.api.transport.DispatchException)
  org.mule.transport.http.HttpClientMessageDispatcher:155 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.net.UnknownHostException: myservice.company.com
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:175)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
    at java.net.Socket.connect(Socket.java:546)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

Upvotes: 0

Views: 872

Answers (1)

Alaa Abed
Alaa Abed

Reputation: 181

Either one of the following:

  1. Add "|| exception.causedBy(java.net.UnknownHostException)" to your first exception strategy to catch only unknown hosts exception.
  2. Change your second catch exception strategy into exception.causeMatches('java.net.*') to catch all network exceptions (notice the quotes).
  3. Change your second catch exception strategy into exception.causeMatches('java.*') to catch all java exceptions (notice the quotes).

Upvotes: 1

Related Questions