AlexGad
AlexGad

Reputation: 6692

Mule ESB serving static files like CSS

In a Mule ESB project, I am trying to serve up files other than an HTML file using the static resource handler in combination with the http:listener. I have a simple HTML file that contains a form and it points to a CSS file in the same directory. If I go to http://localhost:8000 the index.html file is served. But the .css file is not served (404) even though it is placed in the same directory as the HTML file. Other HTML files placed in the same directory also do not get served.

Note that this works fine with the http-inbound-endpoint.

<http:inbound-endpoint exchange-pattern="request-response" host="${server.address}" port="${server.port}" doc:name="HTTP"/>

Is the new httpListener approach not ready for prime time?

Here is the relevant code:

Form HTML (/index.html):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="http://localhost:8081/uploadform.css">
</head>
<body>
   <form action="http://localhost:8081/submitform" enctype="multipart/form-data" method="post">
   <p>
     Type a file title:<br>
     <input type="text" name="title" size="30">
   </p>
   <p>
     Please specify a file to upload:<br>
     <input type="file" name="datafile" size="40">
   </p>
   <div>
     <input type="submit" value="Send">
   </div>
   </form>
 </body>

Relevant MULE code:

<http:listener-config name="HTTP_Listener_Configuration" host="${server.address}" port="${server.port}" doc:name="HTTP Listener Configuration"/>
<flow name="HTTP_FORM" initialState="started">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="GET" doc:name="HTTP"/>
    <http:static-resource-handler resourceBase="${app.home}/web" defaultFile="index.html" doc:name="HTTP Static Resource Handler"/>
</flow>

Here are the relevant error messages that appear:

No listener found for request: (GET)/uploadform.css Available listeners are: [([post])/submitform/, ([get])/]

Upvotes: 1

Views: 861

Answers (2)

You need to use wildcards in your http:listener such as path="/*"

Example Mule Code:

<http:listener-config name="HTTP_Listener_Configuration" post="${server.address}" port="${server.port}" doc:name="HTTP Listener Configuration"/>
<flow name="HTTP_FORM" initialState="started">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/*" allowedMethods="GET" doc:name="HTTP"/>
    <http:static-resource-handler resourceBase="${app.home}/web" defaultFile="index.html" doc:name="HTTP Static Resource Handler"/>
</flow>

Upvotes: 3

AlexGad
AlexGad

Reputation: 6692

Seems as though the way to do this is through the use of wildcards. From the current documentation:

You can also use * as a wildcard path, to listen for all incoming requests done to any path within the specified base path. You can also specify a partial path that ends in , such as mypath/, pointing to any path that begins as defined but that could also be extended with anything else.

Upvotes: 2

Related Questions