| 10 July 2009 |
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:
- declare the namespace with prefix to use in your Mule config for the transport to use
- add the schemaLocation for the new transport to your Mule config
- 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@redstream.nl">
-
</smtp:connector>
-
...
-
<outbound>
-
<pass-through-router>
-
<smtp:outbound-endpoint host="my.mail.server"
-
from="blog@redstream.nl"" 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":description, "http://www.springframework.org/schema/beans":beans, "http://www.springframework.org/schema/beans":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.


2 comments to 'Using a new transport in your Mule application'
15 July 2009
Using a new transport in your Mule application | Pascal's Blog great article thank you.
19 November 2009
[...] use this transport in your Mule project you need to follow the steps like I described here to add a transport to your Mule application. Here is my example mule-config.xml: PLAIN TEXT [...]