Jetty in Mule only works in earlier version of Stu

2020-02-15 05:35发布

问题:

I'm having problems using the Jetty connectors in Mule.

Within my mule configuration:

<jetty:connector name="JettyRest" configFile="jetty-rest.xml" doc:name="Jetty" />
<jetty:connector name="JettySoap" configFile="jetty-soap.xml" doc:name="Jetty" />

There is no problem at all when running in Mule Studio (using Mule Server Runtime 3.4.0 CE). However, after importing the project to and running in Anypoint Studio (using Mule Server Runtime 3.5.0 CE), I get the following error:

Cannot load class 'org.mortbay.jetty.Server'

Even if I manually include the Jetty JAR from here to the build path, I get this error:

Object of class 'org.eclipse.jetty.server.Server' is not of type 'org.mortbay.jetty.Server'. Object Class and type Class are from different loaders.

The same issue is present when running with Mule standalone 3.4.0 CE vs 3.5.0 CE.

In jetty-rest.xml:

<Configure id="Server" class="org.mortbay.jetty.Server">

In jetty-soap.xml:

<Configure id="ServerForSlow" class="org.mortbay.jetty.Server">

What am I missing or doing wrong?

回答1:

You should not need to add the Jetty JAR yourself: they should be brought in your project as part of the Mule Jetty Transport, which is very much an officially supported core transport:

  • http://www.mulesoft.org/documentation/display/current/Jetty+Transport+Reference
  • https://github.com/mulesoft/mule/tree/mule-3.x/transports/jetty

Was the Jetty transport added to your build path / POM file by Studio?



回答2:

I managed to discover what causes the issue. The Mule 3.5.0 CE Jetty transport now uses Jetty 8, and I was previously using Jetty 6 with Mule 3.4.0 CE.

Within MIGRATION.txt:

MULE-7061: Jetty transport is now using Jetty 8. Applications using a custom jetty.xml configuration file must update the Jetty classes referenced in this file due to package names changed from version 6 to 7, as explained here: http://wiki.eclipse.org/Jetty/Starting/Porting_to_Jetty_7/Packages_and_Classes

After following the instructions in the link provided I converted my files to use Jetty 8.