Using a new transport in your Mule application

This post is one of the series of posts about issues that occurred when we were using Mule2 in a real life project. When you need to use a new transport in your Mule application you need to perform the following steps:

  1. declare the namespace with prefix to use in your Mule config for the transport to use
  2. add the schemaLocation for the new transport to your Mule config
  3. add the necessary dependency for the transporter to your pom


When I was copying pieces of example code from the web into my Mule config I ended up with a SAXParseException because I didn’t perform all the steps. I decided to make use of the mailing transport so I added the following pieces of code to my config:

...
 <smtp:connector name="smtpConnector" contentType="text/plain"
          		fromAddress="blog@pascalalma.net" >
    </smtp:connector>
...
 <outbound>
                <pass-through-router>
                    <smtp:outbound-endpoint host="my.mail.server"
                             from="blog@pascalalma.net" to="you@company.com" subject="Message from Mule">
                    </smtp:outbound-endpoint>
                </pass-through-router>
            </outbound>
...

When you now run a test class using this config you will receive the exception:

Caused by: org.xml.sax.SAXParseException: The prefix “smtp” for element “smtp:connector” is not bound.

As might be obvious from the errormessage the used prefix is unknown, so add the following namespace to the root element of my config (as described in step 1):

<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
   ...
   xmlns:smtp="http://www.mulesource.org/schema/mule/smtp/2.2"
   ...>

Now when the test is ran you will get:


Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element ‘smtp:connector’. One of ‘{“http://www.mulesource.org/schema/mule/core/2.2&#8221;:description, “http://www.springframework.org/schema/beans&#8221;:beans, “http://www.springframework.org/schema/beans&#8221;:bean, …’ is expected.

Ah, of course. A namespace is added, but no namespace location. So add the following location to the root element in the config file (as described in step 2):

<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
   ...
   xmlns:smtp="http://www.mulesource.org/schema/mule/smtp/2.2"
   ...
  xsi:schemaLocation="
  ...
     http://www.mulesource.org/schema/mule/smtp/2.2 http://www.mulesource.org/schema/mule/smtp/2.2/mule-smtp.xsd
   ...>

Now the config file is complete, but now you receive the following exception when the test class is executed:


Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.mulesource.org/schema/mule/smtp/2.2]

This is because step 3 has to be taken: add the mail Transport code to the classpath of the application by adding the right dependency to the pom. In this example add to the pom:

...
<dependencies>
    ...
   <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-email</artifactId>
        <version>${mule.version}</version>
    </dependency>
    ...
<dependencies>
...

And the application is up and running and ready to send e-mails.

About Pascal Alma

Pascal is a senior IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in Mule and tagged . Bookmark the permalink.

One Response to Using a new transport in your Mule application

  1. kurye says:

    Using a new transport in your Mule application | Pascal’s Blog great article thank you.

Comments are closed.