You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by "Tong, Gary (FID)" <Ga...@morganstanley.com> on 2008/12/22 16:51:27 UTC

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

This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned or an official confirmation.  Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers.  This is not research and is not from MS Research but it may refer to a research analyst/research report.  Unless indicated, these views are the author's and may differ from those of Morgan Stanley research or others in the Firm.  We do not represent this is accurate or complete and we may not update this.  Past performance is not indicative of future returns.  For additional information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls.  You should not use e-mail to request, authorize or effect the purchase or sale of any security or instrument, to send transfer instructions, or to effect any other transactions.  We cannot guarantee that any such requests received via e-mail will be processed in a timely manner.  This communication is solely for the addressee(s) and may contain confidential information.  We do not waive confidentiality by mistransmission.  Contact me if you do not wish to receive these communications.  In the UK, this communication is directed in the UK to those persons who are professional and eligible counterparties (as defined in the UK Financial Services Authority's rules).

Re: Issue with multiple CXF servlets (and proposed fix)

Posted by Willem Jiang <wi...@gmail.com>.
The default instantiations will include cxf.xml, cxf-extension-*.xml,
I think you should not worry about it :)

Willem

Tong, Gary (FID) wrote:
> Removing the import statements worked, so that will solve the problem for me.
> 
> However, as I understand it, not importing any of the files means that I will be using the default instantiations of the classes without any of the configuration that cxf.xml, cxf-servlet.xml, and cxf-extension-jaxrs-binding.xml provide.  The app actually seems to work, which is a bit surprising, but will I run into problems down the line by not importing any of these files?
> 
> Thanks,
> Gary
> 
> -----Original Message-----
> From: Willem Jiang [mailto:willem.jiang@gmail.com]
> Sent: 23 December 2008 07:48
> To: dev@cxf.apache.org
> Subject: Re: Issue with multiple CXF servlets (and proposed fix)
> 
> Hi
> 
> I'm here (no vocation plan for this Christmas).
> 
> I just went through the CXFServelet code to refresh my memory, found it could be cased by not using right bus for the jaxrs endpoint.
> 
> Since you include ...cxf.xml in the jaxrs spring configuration file, the jaxrs endpoint can't take the already created bus of the application context into consideration. The new created jaxrs endpoint will use its own context's bus instead using the already configured bus.
> 
> To fix this issue , you just need to remove these three imports
>>>  <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" />
>>>
> 
> I just write a quick junit test[1] to verify this.
> 
> [1] http://svn.apache.org/viewvc?rev=728897&view=rev
> 
> Willem
> 
> Glen Mazza wrote:
>> I would highly recommend waiting until Dan K. reviews this.  He (and
>> perhaps
>> Willem) would be in position best to know about all moving parts that
>> may be affected by this change.  I suspect he is on holiday leave this
>> week (and possibly the next), however.
>>
>> Could the problem also be that you specified
>> <load-on-startup>1</load-on-startup> for *both* the servlets defined,
>> instead of giving them distinct values?  Somehow I doubt that's the
>> issue though.
>>
>> Glen
>>
>>
>>
>> Tong, Gary (FID) wrote:
>>> 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
>>> --------------------------------------------------------
>>>
>>> This is not an offer (or solicitation of an offer) to buy/sell the
>>> securities/instruments mentioned or an official confirmation.  Morgan
>>> Stanley may deal as principal in or own or act as market maker for
>>> securities/instruments mentioned or may advise the issuers.  This is
>>> not research and is not from MS Research but it may refer to a
>>> research analyst/research report.  Unless indicated, these views are
>>> the author's and may differ from those of Morgan Stanley research or
>>> others in the Firm.  We do not represent this is accurate or complete
>>> and we may not update this.  Past performance is not indicative of
>>> future returns.  For additional information, research reports and
>>> important disclosures, contact me or see
>>> https://secure.ms.com/servlet/cls.  You should not use e-mail to
>>> request, authorize or effect the purchase or sale of any security or
>>> instrument, to send transfer instructions, or to effect any other
>>> transactions.  We cannot guarantee that any such requests received
>>> via e-mail will be processed in a timely manner.  This communication
>>> is solely for the addressee(s) and may contain confidential
>>> information.  We do not waive confidentiality by mistransmission.
>>> Contact me if you do not wish to receive these communications.  In
>>> the UK, this communication is directed in the UK to those persons who
>>> are professional and eligible counterparties (as defined in the UK Financial Services Authority's rules).
>>>
>>>
> --------------------------------------------------------
> 
> This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned or an official confirmation.  Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers.  This is not research and is not from MS Research but it may refer to a research analyst/research report.  Unless indicated, these views are the author's and may differ from those of Morgan Stanley research or others in the Firm.  We do not represent this is accurate or complete and we may not update this.  Past performance is not indicative of future returns.  For additional information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls.  You should not use e-mail to request, authorize or effect the purchase or sale of any security or instrument, to send transfer instructions, or to effect any other transactions.  We cannot guarantee that any such requests received vi
a e-mail will be processed in a timely manner.  This communication is solely for the addressee(s) and may contain confidential information.  We do not waive confidentiality by mistransmission.  Contact me if you do not wish to receive these communications.  In the UK, this communication is directed in the UK to those persons who are professional and eligible counterparties (as defined in the UK Financial Services Authority's rules).
> 


RE: Issue with multiple CXF servlets (and proposed fix)

Posted by "Tong, Gary (FID)" <Ga...@morganstanley.com>.
Removing the import statements worked, so that will solve the problem for me.

However, as I understand it, not importing any of the files means that I will be using the default instantiations of the classes without any of the configuration that cxf.xml, cxf-servlet.xml, and cxf-extension-jaxrs-binding.xml provide.  The app actually seems to work, which is a bit surprising, but will I run into problems down the line by not importing any of these files?

Thanks,
Gary

-----Original Message-----
From: Willem Jiang [mailto:willem.jiang@gmail.com]
Sent: 23 December 2008 07:48
To: dev@cxf.apache.org
Subject: Re: Issue with multiple CXF servlets (and proposed fix)

Hi

I'm here (no vocation plan for this Christmas).

I just went through the CXFServelet code to refresh my memory, found it could be cased by not using right bus for the jaxrs endpoint.

Since you include ...cxf.xml in the jaxrs spring configuration file, the jaxrs endpoint can't take the already created bus of the application context into consideration. The new created jaxrs endpoint will use its own context's bus instead using the already configured bus.

To fix this issue , you just need to remove these three imports
>>  <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" />
>>

I just write a quick junit test[1] to verify this.

[1] http://svn.apache.org/viewvc?rev=728897&view=rev

Willem

Glen Mazza wrote:
> I would highly recommend waiting until Dan K. reviews this.  He (and
> perhaps
> Willem) would be in position best to know about all moving parts that
> may be affected by this change.  I suspect he is on holiday leave this
> week (and possibly the next), however.
>
> Could the problem also be that you specified
> <load-on-startup>1</load-on-startup> for *both* the servlets defined,
> instead of giving them distinct values?  Somehow I doubt that's the
> issue though.
>
> Glen
>
>
>
> Tong, Gary (FID) wrote:
>> 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
>> --------------------------------------------------------
>>
>> This is not an offer (or solicitation of an offer) to buy/sell the
>> securities/instruments mentioned or an official confirmation.  Morgan
>> Stanley may deal as principal in or own or act as market maker for
>> securities/instruments mentioned or may advise the issuers.  This is
>> not research and is not from MS Research but it may refer to a
>> research analyst/research report.  Unless indicated, these views are
>> the author's and may differ from those of Morgan Stanley research or
>> others in the Firm.  We do not represent this is accurate or complete
>> and we may not update this.  Past performance is not indicative of
>> future returns.  For additional information, research reports and
>> important disclosures, contact me or see
>> https://secure.ms.com/servlet/cls.  You should not use e-mail to
>> request, authorize or effect the purchase or sale of any security or
>> instrument, to send transfer instructions, or to effect any other
>> transactions.  We cannot guarantee that any such requests received
>> via e-mail will be processed in a timely manner.  This communication
>> is solely for the addressee(s) and may contain confidential
>> information.  We do not waive confidentiality by mistransmission.
>> Contact me if you do not wish to receive these communications.  In
>> the UK, this communication is directed in the UK to those persons who
>> are professional and eligible counterparties (as defined in the UK Financial Services Authority's rules).
>>
>>
>
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned or an official confirmation.  Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers.  This is not research and is not from MS Research but it may refer to a research analyst/research report.  Unless indicated, these views are the author's and may differ from those of Morgan Stanley research or others in the Firm.  We do not represent this is accurate or complete and we may not update this.  Past performance is not indicative of future returns.  For additional information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls.  You should not use e-mail to request, authorize or effect the purchase or sale of any security or instrument, to send transfer instructions, or to effect any other transactions.  We cannot guarantee that any such requests received via e-mail will be processed in a timely manner.  This communication is solely for the addressee(s) and may contain confidential information.  We do not waive confidentiality by mistransmission.  Contact me if you do not wish to receive these communications.  In the UK, this communication is directed in the UK to those persons who are professional and eligible counterparties (as defined in the UK Financial Services Authority's rules).

Re: Issue with multiple CXF servlets (and proposed fix)

Posted by Sergey Beryozkin <se...@progress.com>.
Hi,

>
> Since you include ...cxf.xml in the jaxrs spring configuration file, the
> jaxrs endpoint can't take the already created bus of the application
> context into consideration. The new created jaxrs endpoint will use its
> own context's bus instead using the already configured bus.
>
> To fix this issue , you just need to remove these three imports
>>>  <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" />
>>>
>
> I just write a quick junit test[1] to verify this.

Thanks, I'll add a system test too.

Another option, if the requirement is to be able to route requests with different URIs to the same bean is to have a single 
CXFServlet with "/" but multiple jaxrs:server endpoints referring to the same application bean :

CXFServlet  "/*"
jaxrs:server address="/bar"
jaxrs:server address="/foo"

Another option is to have multiple root resource classes with different root/class Path annotations but managing the variable bits 
in the configuration is lilely to be a better option.

Cheers, Sergey

>
> [1] http://svn.apache.org/viewvc?rev=728897&view=rev
>
> Willem
>
> Glen Mazza wrote:
>> I would highly recommend waiting until Dan K. reviews this.  He (and perhaps
>> Willem) would be in position best to know about all moving parts that may be
>> affected by this change.  I suspect he is on holiday leave this week (and
>> possibly the next), however.
>>
>> Could the problem also be that you specified
>> <load-on-startup>1</load-on-startup> for *both* the servlets defined,
>> instead of giving them distinct values?  Somehow I doubt that's the issue
>> though.
>>
>> Glen
>>
>>
>>
>> Tong, Gary (FID) wrote:
>>> 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
>>> --------------------------------------------------------
>>>
>>> This is not an offer (or solicitation of an offer) to buy/sell the
>>> securities/instruments mentioned or an official confirmation.  Morgan
>>> Stanley may deal as principal in or own or act as market maker for
>>> securities/instruments mentioned or may advise the issuers.  This is not
>>> research and is not from MS Research but it may refer to a research
>>> analyst/research report.  Unless indicated, these views are the author's
>>> and may differ from those of Morgan Stanley research or others in the
>>> Firm.  We do not represent this is accurate or complete and we may not
>>> update this.  Past performance is not indicative of future returns.  For
>>> additional information, research reports and important disclosures,
>>> contact me or see https://secure.ms.com/servlet/cls.  You should not use
>>> e-mail to request, authorize or effect the purchase or sale of any
>>> security or instrument, to send transfer instructions, or to effect any
>>> other transactions.  We cannot guarantee that any such requests received
>>> via e-mail will be processed in a timely manner.  This communication is
>>> solely for the addressee(s) and may contain confidential information.  We
>>> do not waive confidentiality by mistransmission.  Contact me if you do not
>>> wish to receive these communications.  In the UK, this communication is
>>> directed in the UK to those persons who are professional and eligible
>>> counterparties (as defined in the UK Financial Services Authority's
>>> rules).
>>>
>>>
>>
> 


Re: Issue with multiple CXF servlets (and proposed fix)

Posted by Willem Jiang <wi...@gmail.com>.
Hi

I'm here (no vocation plan for this Christmas).

I just went through the CXFServelet code to refresh my memory, found it
could be cased by not using right bus for the jaxrs endpoint.

Since you include ...cxf.xml in the jaxrs spring configuration file, the
jaxrs endpoint can't take the already created bus of the application
context into consideration. The new created jaxrs endpoint will use its
own context's bus instead using the already configured bus.

To fix this issue , you just need to remove these three imports
>>  <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" />
>>

I just write a quick junit test[1] to verify this.

[1] http://svn.apache.org/viewvc?rev=728897&view=rev

Willem

Glen Mazza wrote:
> I would highly recommend waiting until Dan K. reviews this.  He (and perhaps
> Willem) would be in position best to know about all moving parts that may be
> affected by this change.  I suspect he is on holiday leave this week (and
> possibly the next), however.
> 
> Could the problem also be that you specified
> <load-on-startup>1</load-on-startup> for *both* the servlets defined,
> instead of giving them distinct values?  Somehow I doubt that's the issue
> though.
> 
> Glen
> 
> 
> 
> Tong, Gary (FID) wrote:
>> 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
>> --------------------------------------------------------
>>
>> This is not an offer (or solicitation of an offer) to buy/sell the
>> securities/instruments mentioned or an official confirmation.  Morgan
>> Stanley may deal as principal in or own or act as market maker for
>> securities/instruments mentioned or may advise the issuers.  This is not
>> research and is not from MS Research but it may refer to a research
>> analyst/research report.  Unless indicated, these views are the author's
>> and may differ from those of Morgan Stanley research or others in the
>> Firm.  We do not represent this is accurate or complete and we may not
>> update this.  Past performance is not indicative of future returns.  For
>> additional information, research reports and important disclosures,
>> contact me or see https://secure.ms.com/servlet/cls.  You should not use
>> e-mail to request, authorize or effect the purchase or sale of any
>> security or instrument, to send transfer instructions, or to effect any
>> other transactions.  We cannot guarantee that any such requests received
>> via e-mail will be processed in a timely manner.  This communication is
>> solely for the addressee(s) and may contain confidential information.  We
>> do not waive confidentiality by mistransmission.  Contact me if you do not
>> wish to receive these communications.  In the UK, this communication is
>> directed in the UK to those persons who are professional and eligible
>> counterparties (as defined in the UK Financial Services Authority's
>> rules).
>>
>>
> 


Re: Issue with multiple CXF servlets (and proposed fix)

Posted by Glen Mazza <gl...@gmail.com>.
I would highly recommend waiting until Dan K. reviews this.  He (and perhaps
Willem) would be in position best to know about all moving parts that may be
affected by this change.  I suspect he is on holiday leave this week (and
possibly the next), however.

Could the problem also be that you specified
<load-on-startup>1</load-on-startup> for *both* the servlets defined,
instead of giving them distinct values?  Somehow I doubt that's the issue
though.

Glen



Tong, Gary (FID) wrote:
> 
> 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
> --------------------------------------------------------
> 
> This is not an offer (or solicitation of an offer) to buy/sell the
> securities/instruments mentioned or an official confirmation.  Morgan
> Stanley may deal as principal in or own or act as market maker for
> securities/instruments mentioned or may advise the issuers.  This is not
> research and is not from MS Research but it may refer to a research
> analyst/research report.  Unless indicated, these views are the author's
> and may differ from those of Morgan Stanley research or others in the
> Firm.  We do not represent this is accurate or complete and we may not
> update this.  Past performance is not indicative of future returns.  For
> additional information, research reports and important disclosures,
> contact me or see https://secure.ms.com/servlet/cls.  You should not use
> e-mail to request, authorize or effect the purchase or sale of any
> security or instrument, to send transfer instructions, or to effect any
> other transactions.  We cannot guarantee that any such requests received
> via e-mail will be processed in a timely manner.  This communication is
> solely for the addressee(s) and may contain confidential information.  We
> do not waive confidentiality by mistransmission.  Contact me if you do not
> wish to receive these communications.  In the UK, this communication is
> directed in the UK to those persons who are professional and eligible
> counterparties (as defined in the UK Financial Services Authority's
> rules).
> 
> 

-- 
View this message in context: http://www.nabble.com/Issue-with-multiple-CXF-servlets-%28and-proposed-fix%29-tp21129999p21138164.html
Sent from the cxf-dev mailing list archive at Nabble.com.