Rajesh
Rajesh

Reputation: 3034

How to Start Mule in Tomcat?

I am new to mule and trying to orchestrate webservices using mule. I have written a simple webservice,but when I am trying to deploy mule web project in tomcat,I get this log statement I get.

21 Dec, 2012 2:44:59 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_27\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;;C:\Program Files\Dell\DW WLAN Card;.
21 Dec, 2012 2:45:00 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:PosMuleService' did not find a matching property.
21 Dec, 2012 2:45:00 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
21 Dec, 2012 2:45:00 AM org.apache.coyote.ajp.AjpProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
21 Dec, 2012 2:45:00 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 770 ms
21 Dec, 2012 2:45:00 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
21 Dec, 2012 2:45:00 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.4
21 Dec, 2012 2:45:13 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
21 Dec, 2012 2:45:13 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
21 Dec, 2012 2:45:13 AM org.apache.coyote.ajp.AjpProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
21 Dec, 2012 2:45:13 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 13237 ms

This is my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"  metadata-complete="true">
  <display-name>PosMuleService</display-name>

  <context-param>
    <param-name>org.mule.config</param-name>
    <param-value>/WEB-INF/spring-servlet.xml,/WEB-INF/maf_services.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
  </listener>

</web-app>

This is my spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
</beans>

This is my maf_services.xml

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:spring="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/3.4/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.4/mule-http.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.4/mule.xsd">

  <flow name="helloService">
    <http:inbound-endpoint address="http://localhost:8080/PosMuleService/hello" exchange-pattern="request-response">
        <cxf:simple-service serviceClass="org.example.HelloWorld"/>
    </http:inbound-endpoint>
    <component class="org.example.HelloWorldImpl" /> 
  </flow>
  </mule>

This is my HelloWorld Impl

/**
 * 
 */
package org.example;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

/**
 * @author 
 *
 */
@WebService(endpointInterface = "org.example.HelloWorld",
serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    /* (non-Javadoc)
     * @see org.example.HelloWorld#sayHi(java.lang.String)
     */
    @WebMethod(operationName="sayHi")
    public @WebResult(name="sayHiResult")String sayHi(@WebParam(name="text")String text) {
        // TODO Auto-generated method stub
        return "Hi "+text;
    }

}

This is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>PosMuleService</groupId>
  <artifactId>PosMuleService</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>PosMuleService Maven Webapp</name>
  <url>http://maven.apache.org</url>
<dependencies>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>1.8.1</version>
    </dependency>


    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-builders</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule</groupId>
        <artifactId>mule-core</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-scripting</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-vm</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-servlet</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-stdio</artifactId>
        <version>3.4-M1</version>
    </dependency>
    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm-commons</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>
</dependencies>

  <repositories>
    <repository>
      <id>mule-deps</id>
      <name>Mule Dependencies</name>
      <url>http://dist.codehaus.org/mule/dependencies/maven2</url>
    </repository>
  </repositories>
  <build>
    <finalName>PosMuleService</finalName>
  </build>
</project>

I am using tomcat7.0 and eclipse juno.. any idea why my mule is not starting up properly..I can neither see services nor wsdl.. getting 404 for URL

http://localhost:8080/PosMuleService/hello

Note in server log I am getting this line:INFO: No Spring WebApplicationInitializer types detected on classpath but I have added spring-servlet.xml file in WEB-INF ,tried with context loader as well but no luck.

Upvotes: 1

Views: 2433

Answers (3)

Mathias G.
Mathias G.

Reputation: 5105

I can confirm the application you want to deploy on tomcat works.

Next to the changes David proposes I changed the flow definition as follows:

<flow name="helloService">
    <servlet:inbound-endpoint path="hello" />
    <component class="org.example.HelloWorldImpl" />
</flow>

Here you don't need any Spring. If you want to use Spring, define the following component in your mule configuration:

<spring:beans>
    <spring:import resource="classpath:applicationContext.xml"/>
</spring:beans>

Make sure your Spring applicationContext is on your classpath. (in a maven file structure, put your applicationContext in src/main/resources/ for example)

Upvotes: 0

Rajesh
Rajesh

Reputation: 3034

Ya I made it work but following a different approach. I was not able to do it using tomcat. probably we should not run mule on tomcat as we have to depend on servlet thread for processing which I think decreases performance. Please correct me If I am wrong. I read this somewhere.. I have installed mule studio and created a mule project Added the maf_Services.xml and webservices code to mule studio project and executed the project as mule application. In production environment I will be exporting my mule project using mule studio and deploying my application using mule standalone server.

Upvotes: 0

David Dossot
David Dossot

Reputation: 33413

Several issues:

  • Do not load Spring config files with Mule: remove /WEB-INF/spring-servlet.xml from param-value
  • Do not use HTTP inbound endpoints when running in a web container: Mule will attempt to start a web server on this port. Instead use servlet inbound endpoints so Mule listens though a servlet handled by the web container.

In your case use:

<servlet:inbound-endpoint path="hello" />
  • Add the Mule servlet to your web.xml.

Like this:

<servlet>
    <servlet-name>muleServlet</servlet-name>
    <servlet-class>org.mule.transport.servlet.MuleReceiverServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>muleServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

Upvotes: 2

Related Questions