Mule ESB 提供像 CSS 这样的静态文件

Mule ESB serving static files like CSS

在 Mule ESB 项目中,我尝试使用静态资源处理程序结合 http:listener 提供 HTML 文件以外的文件。我有一个包含表单的简单 HTML 文件,它指向同一目录中的 CSS 文件。如果我转到 http://localhost:8000,则会提供 index.html 文件。但是 .css 文件未提供 (404),即使它与 HTML 文件位于同一目录中。放置在同一目录中的其他 HTML 个文件也不会得到服务。

请注意,这适用于 http-inbound-endpoint。

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

新的 httpListener 方法还没有准备好迎接黄金时段吗?

相关代码如下:

表格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>

相关MULE代码:

<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>

以下是出现的相关错误消息:

找不到请求的侦听器:(GET)/uploadform.css 可用的侦听器是:[([post])/submitform/, ([get])/]

似乎是通过使用通配符来实现的。来自 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.

您需要在 http:listener 中使用通配符,例如 path="/*"

示例 Mule 代码:

<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>