HTTP Static Resource Handler in Mule | Load Static File in Mule

HTTP Static Resource Handler in Mule | Load Static File in Mule

We can configure the HTTP connector to load a static resource, such as your home page or a script. You set the path and file name of a resource to load. You optionally set the name of another file in the same directory as the resource to use in case of failure.

flow of HTTP Static Resource Handler : 

In above flow we are loading a static html file demo.html kept in src/main resources and will display static content : Hi everyone...

HTTP Static Resource Handler Configuration :

URL : http://localhost:8085/api/static Method : GET

Output :

XML project code : 

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="" xmlns:s3="" xmlns:anypoint-mq="" xmlns:http="" xmlns:ajax="" xmlns="" xmlns:doc=""
    <http:listener-config name="HTTP_Listener_Configuration" host="" port="8085" basePath="/api" doc:name="HTTP Listener Configuration"/>
    <flow name="test_staticresourcehandler">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/static" doc:name="HTTP"/>
        <http:static-resource-handler resourceBase="src/main/resources/demo.html" defaultFile="src/main/resources/demo.html" doc:name="HTTP Static Resource Handler"/>
        <logger message="Completed............" level="INFO" doc:name="Logger"/>