app.home used in mule ajax connector is not working when mule project is converted to web application

南笙酒味 提交于 2019-12-13 04:00:30

问题


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:

  1. Set the variable yourself
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!