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 
CXFServlet.java.

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.

Cheers,
Gary

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

Hello,

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:

  <servlet>
    <servlet-name>test</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
      <param-name>config-location</param-name>
      <param-value>/WEB-INF/test-servlet.xml</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>test</servlet-name>
    <url-pattern>/t/*</url-pattern>
  </servlet-mapping>

  <servlet>
    <servlet-name>foo</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
      <param-name>config-location</param-name>
      <param-value>/WEB-INF/foo-servlet.xml</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>foo</servlet-name>
    <url-pattern>/f/*</url-pattern>
  </servlet-mapping>

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

<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xmlns:jaxrs="http://cxf.apache.org/jaxrs";
       xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd";>

  <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="/">
    <jaxrs:serviceBeans>
      <ref bean="testController"/>
    </jaxrs:serviceBeans>
    <jaxrs:extensionMappings>
      <entry key="xml" value="application/xml" />
    </jaxrs:extensionMappings>
  </jaxrs:server>

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

</beans>

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 ignored.

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.

Thanks,
Gary

--------------------------------------------------------------------------
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.

Reply via email to