问题
In mule, the studio flight reservation example is working when I convert it in web application by using web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID">
<!--Mule configuration (Mule format)-->
<context-param>
<param-name>org.mule.config</param-name>
<param-value>flight-config.xml</param-value>
</context-param>
<listener>
<listener-class>
org.mule.config.builders.MuleXmlBuilderContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>muleServlet</servlet-name>
<servlet-class>org.mule.transport.servlet.MuleReceiverServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<!--Mule configuration ends-->
</web-app>
in mule application
<ajax:connector name="ajaxServer" serverUrl="http://0.0.0.0:9092/reservation" resourceBase="${app.home}/docroot" doc:name="Ajax"/>
The above connector was working but in web application it is showing error
HTTP ERROR 404
Problem accessing /reservation/. Reason:
NOT_FOUND
--------------------------------------------------------------------------------
Powered by Jetty://
In WebContent, I have created a folder docroot
and created the files in it accordingly, the connector I am using in web application is
<ajax:connector name="ajaxServer" serverUrl="http://0.0.0.0:9092/reservation" resourceBase="/docroot" doc:name="Ajax"/>
but this is not working. What could be the cause of this error?
回答1:
I have done it in this way:
Added a ContextListener extending MuleXmlBuilderContextListener that does the following
ServletContext context = event.getServletContext();
System.setProperty("rootPath", context.getRealPath("/"));
initialize(context);
and used this rootPath like this:
<ajax:connector name="ajaxServer" serverUrl="http://0.0.0.0:9092/reservation" resourceBase="${rootPath}WEB-INF/docroot" doc:name="Ajax"/>
now the application is working.
回答2:
The var ${app.home} is set by the mule standalone container, therefor when you run it embedded in a webapp you have two options:
- Set the variable yourself
- Change it to a path relative to your webapp location
来源:https://stackoverflow.com/questions/16035925/app-home-used-in-mule-ajax-connector-is-not-working-when-mule-project-is-convert