Generic Error Handling Framework

Author: Venkateshwar Reddy Guda

 

Step-1: Modify and build the project

  • Download the jar file from the C4E site > frameworks.
  • Modify the settings file in the maven/conf folder (as given at the end of the document).
  • Import the jar file into the studio as “packaged mule application (.jar).”
  • Open pom.xml, comment out logging framework dependency.

 

 

  • Under build > plugins > plugin > configuration, change classifier to “mule-plugin”.

 

 

  • Goto apisero-generic-error-handler.xml and delete the flow reference.

 

 

  • If you want to send an email when an error occurs, configure the email details in error-handler-local.yaml file. Else, delete the choice router in common-error-sub-flow.
  • You can also add new error types under global error handler flow (add it before error type: ANY)
  • Goto error-framework-global-config.xml and remove the two import elements.

 

 

  • Save all and execute mvn clean package from the project location. Build should be successful.

 

Step-2: publish to exchange as a connector

  • Goto Anypoint platform > access management > organization and click on the organization name. You can find the organization id here.
  • Now open the pom.xml file and enter organization Id in groupId.

 

 

  • Add the below tags after dependencies in the pom.xml file.

 

<distributionManagement>
  	  <repository>
    	    <id>Repository</id>
    	    <name>organization Repository</name>
    	    <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/{give organization Id here}/maven</url>
    	    <layout>default</layout>
  	  </repository>
</distributionManagement>

 

  • Add the below server details in settings.xml file in the maven/conf location.

 

<server>
  <id>Repository</id>
  <username>{Anypoint platform username}</username>
  <password>{Anypoint platform password}</password>
</server>

 

  • Save all and execute mvn clean package deploy from the project location.
  • Once the build is successful, the connector can be seen in exchange.

 

Step-3: Utilize as a connector

  • In Anypoint Studio, open the mule project where you want to use this generic error handling framework.
  • In the mule pallet, click on “search in exchange” and search for the connector. Add the connector as a dependency.

 

 

  • In global elements, import two configuration files. (apisero-generic-error-handler.xml and error-framework-global-config.xml)

 

 

  • In global elements, create configuration and make default error handler as “global_error_handler”

 

 

Note: If the global error handler is not seen in the dropdown, save it after importing and creating configuration.

  • Add the error handler configuration code under src/main/resources > properties file (as given at the end of the document).

 

Settings file code:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>C:/Users/DELL/.m2/repository</localRepository>			
    <interactiveMode>true</interactiveMode>								
    <offline>false</offline>				 
    <pluginGroups>
    </pluginGroups>
    <proxies>
    </proxies>
    <servers>
        <server>
            <id>MuleRepository</id>
            <username>apisero.nexus</username>
            <password>pWhdnHcG</password>
        </server>
    </servers>
    <mirrors>
    </mirrors>
    <profiles>
        <profile>
            <id>Mule</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>
                <repository>
                    <id>MuleRepository</id>
                    <name>MuleRepository</name>
                    <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
        <profile>
            <id>standard-repositories</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>
                <repository>
                    <id>Central</id>
                    <name>Central</name>
                    <url>http://repo1.maven.org/maven2/</url>
                    <layout>default</layout>
                </repository>
                <repository>
                    <id>anypoint-exchange</id>
                    <name>Anypoint Exchange</name>
                    <url>https://maven.anypoint.mulesoft.com/api/v1/maven</url>
                    <layout>default</layout>
                </repository>
                <repository>
                    <id>mulesoft-releases</id>
                    <name>MuleSoft Releases Repository</name>
                    <url>https://repository.mulesoft.org/releases/</url>
                    <layout>default</layout>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>mule-public</id>
                    <layout>default</layout>
                    <url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>mulesoft-release</id>
                    <name>mulesoft release repository</name>
                    <layout>default</layout>
                    <url>https://repository.mulesoft.org/nexus/content/groups/public</url>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>mulesoft-ee-release</id>
                    <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
                    <layout>default</layout>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

 

Error handler configuration code:

 

#Error handler configuration
errorCodeMessage:
  ### APIKIT Errors ###
  apikit:
    badRequest:
      code: "400"
      #description: "Request validation error"
      description: "Bad Request"
    notFound:
      code: "404"
      #description: "Resource not found"
      description: "Not Found"
    methodNotAllowed:
      code: "405"
      #description: "HTTP method not allowed"
      description: "Method Not Allowed"
    notAcceptable:
      code: "406"
      #description: "Requested content type not available"
      description: "Not Acceptable"
    unsupportedMediaType:
      code: "415"
      #description: "Payload format is in an unsupported format"
      description: "Unsupported Media Type"
    notImplemented:
      code: "501"
      #description: "Requested functionality is not supported"
      description: "Not Implemented"
      
  ### HTTP Errors ###
  http:
    connectivity:
      code: "500"
      #description: "Connectivity Error, Please try later"
      description: "Internal Server Error"
    forbidden:
      code: "403"
      #description: "Server refused to authorize the request"
      description: "Forbidden" 
    serviceUnavailable:
      code: "503"
      #description: "Server not ready to handle the request"
      description: "Service Unavailable"
    timeout:
      code: "504"
      #description: "Gateway Timeout - Server did not get a response in time"
      description: "Gateway Timeout" 
    unauthorized:
      code: "401"
      #description: "Invalid Credentials"
      description: "Unauthorized"
    badRequest:
      code: "400"
      #description: "Http bad request"
      description: "Http bad request"

 

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.