Use the HTTP Static Resource Handler to specify any HTTP static resource as an output.
Insert the HTTP Static Resource Handler into your flow and configure it per the following table.
Field | Description | Default Value | Sample XML |
---|---|---|---|
Display Name |
Name of the component as it appears in the flow. |
HTTP Static Resource Handler |
|
Resource Base |
Required. The resource folder where the html document(s) are stored. |
N/A |
|
Default File |
Required. The default main file to serve when the directory is specified. If no file is specified, index.html is used. |
index.html |
|
<http:static-resource-handler resourceBase="/myApp" doc:name="HTTP Static Resource Handler" defaultFile="index.html"/>
Element | Description |
---|---|
http:static-resource-handler |
Specify any HTTP static resource to be the output produced by this component. |
Attribute Name | Description |
---|---|
resourceBase |
Required. The resource folder where documents are stored. Type: string resourceBase="/myApp" |
defaultFile |
Required. The default main file to serve when the directory is specified. Type: string defaultFile="index.html" |
doc:name |
Customize to display a unique name for the logger in your application. Note: An attribute is not required in a Mule Standalone configuration. Type: string doc:name="HTTP Static Resource Handler" |
-
Drag an HTTP Connector into a new flow, followed by an HTTP Static Resource Handler.
-
Leave the HTTP connector with its default settings, pointing to
0.0.0.0:8081
. -
Create a new folder on your local hard drive, and place a static HTML file in it. Any HTML file works, such as:
<html> <body> <h2>Hello Mules!</h2> </body> </html>
-
Configure the HTTP Static Resource Handler to reference the folder and file. In this example, the path is /Users/me/ and the file name is mulesoft.html.
-
Save, then run your project. Right-click your project name in the Package Explorer and click Run As > Mule Application. You can also run your application from the Run menu.
-
Open any browser window, and type 0.0.0.0:8081 in the address bar.
-
Your HTML file loads, and if you have a display item like in the example, the text displays:
The payload produced by this component is the HTTP content of the mulesoft.html file. The folder specified in the Resource Base may also contain other files such as .css stylesheets or .js scripts that the main .html file can reference.
-
Create a new flow and add an HTTP inbound endpoint. Set the host to 0.0.0.0 and the port to 8081.
<flow name="Flow1" doc:name="Flow1"> <http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8081" doc:name="HTTP"/> </flow>
-
Create a new folder on your local hard drive, then place any static HTML file in that folder, for example: , such as:
<html> <body> <h2>Hello Mules!</h2> </body> </html>
In this example, the path is /Users/me/ and the file name is mulesoft.html.
-
Add a HTTP Static Resource Handler and configure it to reference this file.
<flow name="Flow1" doc:name="Flow1"> <http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8081" doc:name="HTTP"/> <http:static-resource-handler resourceBase="/Users/me" doc:name="HTTP Static Resource Handler" defaultFile="mulesoft.html"/> </flow>
-
Save, then run your project.
-
Open any browser window, then type
0.0.0.0:8081
in the address bar:The payload produced by this component is the HTTP content of the mulesoft.html file. The folder specified in the Resource Base may also contain other files such as .css stylesheets or .js scripts that the main .html file can reference.
<?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" 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="http_static_resource_handler_testFlow1" doc:name="http_static_resource_handler_testFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8081" doc:name="HTTP"/>
<http:static-resource-handler resourceBase="${app.home}/web" defaultFile="index.html" doc:name="HTTP Static Resource Handler"/>
</flow>
</mule>
Tip
|
In this example, the resource handler deals with documents in the project folder src/main/app/web , referenced dynamically through the expression ${app.home}/web . For maven projects, please use "${app.home}/classes/web" for resourceBase parameter.
|
-
Add some conditional logic to your flow routers.