cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tong, Gary \(IDEAS\)" <>
Subject FW: Issue with multiple CXF servlets (and proposed fix)
Date Mon, 09 Mar 2009 11:52:55 GMT
This was actually one of the first messages I posted to the list from a while ago.

Diff was created against CXFServlet 2.1.4

The diff that I'm producing should be right, although slightly non-standard as I don't have
the whole source tree available to me.  Apply it directly to

Also have a whole suite of jetty tests that I'm working with to verify behavior in different
situations.  If you guys decide to try to get this in to CXF, I'll be happy to contrib those
as well.

Course, if you guys are busy with much more important features, I'll just continue working
on this bit.  When I get time I'll probably look into how best to change the ProviderFactory
singleton bit.


-----Original Message-----
From: Tong, Gary (FID)
Sent: 22 December 2008 15:51
Subject: Issue with multiple CXF servlets (and proposed fix)


I'm having issues with creating multiple CXFServlets.  I'm trying to insantiate 2 independent
CXF servlets and deploy them at different URLs.  The relevant part of the web.xml looks like:





This, unfortunately, doesn't work.  My test-servlet.xml file looks like:

<?xml version="1.0"?>
<beans xmlns=""

  <import resource="classpath:META-INF/cxf/cxf.xml" />
  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

  <jaxrs:server id="cxfMapping" address="/">
      <ref bean="testController"/>
      <entry key="xml" value="application/xml" />

  <bean id="testController" class="test.TestController"/>


And foo-servlet.xml looks much the same.  This configuration gives me a "No service was found."
response.  However, if I move the import statements to the base spring application context,
both the test and foo servlets end up serving up test-servlet.xml and foo-servlet.xml gets

As far as I can tell, this problem occurs because the configs specified in config-location
aren't loaded until the majority of the servlet has been initialized.  Because of this, most
of the settings in test-servlet.xml and foo-servlet.xml are ignored during initialization.

The order of initialization in CXFServlet seems to be:

1. Find the spring app context.
2. Create a new bus based on the app context.
3. Set up the servlet transport factory
4. Create the controller
5. Load the additional configuration from the config-location servlet param

My proposed fix is to change the order of initialization to:

1. Find the spring app context.
2. Load the additional configuration from the config-location servlet param
3. Create a new bus based on the new child context (or original spring app context if there
is no additional configuration)
4. Set up the servlet transport factory
5. Create the controller

The attached diff does this and fixes the problem that I have with creating two CXFServlets.
 Hopefully this is the right way to do this.


NOTICE: If received in error, please destroy and notify sender. Sender does not intend to
waive confidentiality or privilege. Use of this email is prohibited when received in error.

  • Unnamed multipart/mixed (inline, 7-Bit, 0 bytes)
View raw message