You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Frizz <fr...@googlemail.com> on 2015/06/07 16:40:06 UTC

How to install a CXF ServerLifeCycleListener when app is running in Apache Tomcat?

I have published a Web-Service in Tomcat with cxf-servlet.xml

   <jaxws:endpoint id="myService"
        implementor="#MyServiceImpl" address="/MyService">
   </jaxws:endpoint>

So far, so god.

Now I wanted to add a CXF ServerLifeCycleListener, but it seems this has to
be done BEFORE the service is published in order to have an effect.

How can I do this with Tomcat / Spring?


When I run my app in pure Java I do it this way:

        Bus cxfBus = BusFactory.getDefaultBus();
        ServerLifeCycleManager mgr =
cxfBus.getExtension(ServerLifeCycleManager.class);
        mgr.registerListener(new MyListener());

        MyServiceImpl fri = new MyServiceImpl();
        Endpoint ep = Endpoint.publish("http://localhost:8080/apps/MyService",
service);

This works.

- But how do I get access to the *correct* bus when deployed in Tomcat?
- And how can I set my ServerLicefycleListener *before* services get
published by the cxf-servlet.xml?

RE: How to install a CXF ServerLifeCycleListener when app is running in Apache Tomcat?

Posted by Andrei Shakirin <as...@talend.com>.
Hi,

The ExtensionManagerImpl, loading extensions from bus-extensions.txt, implements ConfiguredBeanLocator interface.
See details in: https://github.com/apache/cxf/blob/master/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java

Regards,
Andrei.

> -----Original Message-----
> From: André Costa Lima [mailto:andreclima.pt@gmail.com]
> Sent: Donnerstag, 11. Juni 2015 23:17
> To: users@cxf.apache.org
> Subject: RE: How to install a CXF ServerLifeCycleListener when app is running in
> Apache Tomcat?
> 
> Is this loaded by ConfiguredBeanLocator?
> 
> Regards,
> 
> André Costa Lima
> Em 09/06/2015 19:51, "Andrei Shakirin" <as...@talend.com> escreveu:
> 
> > Hi,
> >
> > More easy way to start your ServerLifeCycleListener is using
> > META-INF/cxf/bus-extensions.txt.
> > Here is example:
> >
> > https://github.com/apache/cxf/blob/master/rt/ws/security/src/main/reso
> > urces/META-INF/cxf/bus-extensions.txt
> >
> > https://github.com/apache/cxf/blob/master/rt/ws/security/src/main/java
> > /org/apache/cxf/ws/security/cache/CacheCleanupListener.java
> >
> > Regards,
> > Andrei.
> >
> > > -----Original Message-----
> > > From: Frizz [mailto:frizzthecat@googlemail.com]
> > > Sent: Montag, 8. Juni 2015 15:30
> > > To: users@cxf.apache.org; andreclima.pt@gmail.com
> > > Subject: Re: How to install a CXF ServerLifeCycleListener when app
> > > is
> > running in
> > > Apache Tomcat?
> > >
> > > How do I access the WebApplicationContext?
> > >
> > > I did this in my code:
> > >
> > > @Resource
> > > private WebServiceContext wsContext;
> > >
> > > The code gets executed when I deploy the WAR, but wsContext is null.
> > >
> > >
> > >
> > > On Sun, Jun 7, 2015 at 6:31 PM, André Costa Lima <
> > andreclima.pt@gmail.com>
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > You can set publish=false in jaws:endpoint. Then, through
> > > > WebApplicationContext you can get the bean and start the endpoint
> > yourself.
> > > > You probably can get the Bus through the bean casting.
> > > >
> > > > There is probably a cleaner way of doing this. Maybe supplying the
> > > > Bus to the endpoint in Spring xml configuration?
> > > >
> > > > Regards,
> > > >
> > > > André Costa Lima
> > > >
> > > >
> > > > 2015-06-07 15:40 GMT+01:00 Frizz <fr...@googlemail.com>:
> > > >
> > > > > I have published a Web-Service in Tomcat with cxf-servlet.xml
> > > > >
> > > > >    <jaxws:endpoint id="myService"
> > > > >         implementor="#MyServiceImpl" address="/MyService">
> > > > >    </jaxws:endpoint>
> > > > >
> > > > > So far, so god.
> > > > >
> > > > > Now I wanted to add a CXF ServerLifeCycleListener, but it seems
> > > > > this has
> > > > to
> > > > > be done BEFORE the service is published in order to have an effect.
> > > > >
> > > > > How can I do this with Tomcat / Spring?
> > > > >
> > > > >
> > > > > When I run my app in pure Java I do it this way:
> > > > >
> > > > >         Bus cxfBus = BusFactory.getDefaultBus();
> > > > >         ServerLifeCycleManager mgr =
> > > > > cxfBus.getExtension(ServerLifeCycleManager.class);
> > > > >         mgr.registerListener(new MyListener());
> > > > >
> > > > >         MyServiceImpl fri = new MyServiceImpl();
> > > > >         Endpoint ep = Endpoint.publish("
> > > > > http://localhost:8080/apps/MyService",
> > > > > service);
> > > > >
> > > > > This works.
> > > > >
> > > > > - But how do I get access to the *correct* bus when deployed in
> > Tomcat?
> > > > > - And how can I set my ServerLicefycleListener *before* services
> > > > > get published by the cxf-servlet.xml?
> > > > >
> > > >
> >

RE: How to install a CXF ServerLifeCycleListener when app is running in Apache Tomcat?

Posted by André Costa Lima <an...@gmail.com>.
Is this loaded by ConfiguredBeanLocator?

Regards,

André Costa Lima
Em 09/06/2015 19:51, "Andrei Shakirin" <as...@talend.com> escreveu:

> Hi,
>
> More easy way to start your ServerLifeCycleListener is using
> META-INF/cxf/bus-extensions.txt.
> Here is example:
>
> https://github.com/apache/cxf/blob/master/rt/ws/security/src/main/resources/META-INF/cxf/bus-extensions.txt
>
> https://github.com/apache/cxf/blob/master/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java
>
> Regards,
> Andrei.
>
> > -----Original Message-----
> > From: Frizz [mailto:frizzthecat@googlemail.com]
> > Sent: Montag, 8. Juni 2015 15:30
> > To: users@cxf.apache.org; andreclima.pt@gmail.com
> > Subject: Re: How to install a CXF ServerLifeCycleListener when app is
> running in
> > Apache Tomcat?
> >
> > How do I access the WebApplicationContext?
> >
> > I did this in my code:
> >
> > @Resource
> > private WebServiceContext wsContext;
> >
> > The code gets executed when I deploy the WAR, but wsContext is null.
> >
> >
> >
> > On Sun, Jun 7, 2015 at 6:31 PM, André Costa Lima <
> andreclima.pt@gmail.com>
> > wrote:
> >
> > > Hi,
> > >
> > > You can set publish=false in jaws:endpoint. Then, through
> > > WebApplicationContext you can get the bean and start the endpoint
> yourself.
> > > You probably can get the Bus through the bean casting.
> > >
> > > There is probably a cleaner way of doing this. Maybe supplying the Bus
> > > to the endpoint in Spring xml configuration?
> > >
> > > Regards,
> > >
> > > André Costa Lima
> > >
> > >
> > > 2015-06-07 15:40 GMT+01:00 Frizz <fr...@googlemail.com>:
> > >
> > > > I have published a Web-Service in Tomcat with cxf-servlet.xml
> > > >
> > > >    <jaxws:endpoint id="myService"
> > > >         implementor="#MyServiceImpl" address="/MyService">
> > > >    </jaxws:endpoint>
> > > >
> > > > So far, so god.
> > > >
> > > > Now I wanted to add a CXF ServerLifeCycleListener, but it seems this
> > > > has
> > > to
> > > > be done BEFORE the service is published in order to have an effect.
> > > >
> > > > How can I do this with Tomcat / Spring?
> > > >
> > > >
> > > > When I run my app in pure Java I do it this way:
> > > >
> > > >         Bus cxfBus = BusFactory.getDefaultBus();
> > > >         ServerLifeCycleManager mgr =
> > > > cxfBus.getExtension(ServerLifeCycleManager.class);
> > > >         mgr.registerListener(new MyListener());
> > > >
> > > >         MyServiceImpl fri = new MyServiceImpl();
> > > >         Endpoint ep = Endpoint.publish("
> > > > http://localhost:8080/apps/MyService",
> > > > service);
> > > >
> > > > This works.
> > > >
> > > > - But how do I get access to the *correct* bus when deployed in
> Tomcat?
> > > > - And how can I set my ServerLicefycleListener *before* services get
> > > > published by the cxf-servlet.xml?
> > > >
> > >
>

RE: How to install a CXF ServerLifeCycleListener when app is running in Apache Tomcat?

Posted by Andrei Shakirin <as...@talend.com>.
Hi,

More easy way to start your ServerLifeCycleListener is using META-INF/cxf/bus-extensions.txt.
Here is example: 
https://github.com/apache/cxf/blob/master/rt/ws/security/src/main/resources/META-INF/cxf/bus-extensions.txt
https://github.com/apache/cxf/blob/master/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/CacheCleanupListener.java 

Regards,
Andrei.

> -----Original Message-----
> From: Frizz [mailto:frizzthecat@googlemail.com]
> Sent: Montag, 8. Juni 2015 15:30
> To: users@cxf.apache.org; andreclima.pt@gmail.com
> Subject: Re: How to install a CXF ServerLifeCycleListener when app is running in
> Apache Tomcat?
> 
> How do I access the WebApplicationContext?
> 
> I did this in my code:
> 
> @Resource
> private WebServiceContext wsContext;
> 
> The code gets executed when I deploy the WAR, but wsContext is null.
> 
> 
> 
> On Sun, Jun 7, 2015 at 6:31 PM, André Costa Lima <an...@gmail.com>
> wrote:
> 
> > Hi,
> >
> > You can set publish=false in jaws:endpoint. Then, through
> > WebApplicationContext you can get the bean and start the endpoint yourself.
> > You probably can get the Bus through the bean casting.
> >
> > There is probably a cleaner way of doing this. Maybe supplying the Bus
> > to the endpoint in Spring xml configuration?
> >
> > Regards,
> >
> > André Costa Lima
> >
> >
> > 2015-06-07 15:40 GMT+01:00 Frizz <fr...@googlemail.com>:
> >
> > > I have published a Web-Service in Tomcat with cxf-servlet.xml
> > >
> > >    <jaxws:endpoint id="myService"
> > >         implementor="#MyServiceImpl" address="/MyService">
> > >    </jaxws:endpoint>
> > >
> > > So far, so god.
> > >
> > > Now I wanted to add a CXF ServerLifeCycleListener, but it seems this
> > > has
> > to
> > > be done BEFORE the service is published in order to have an effect.
> > >
> > > How can I do this with Tomcat / Spring?
> > >
> > >
> > > When I run my app in pure Java I do it this way:
> > >
> > >         Bus cxfBus = BusFactory.getDefaultBus();
> > >         ServerLifeCycleManager mgr =
> > > cxfBus.getExtension(ServerLifeCycleManager.class);
> > >         mgr.registerListener(new MyListener());
> > >
> > >         MyServiceImpl fri = new MyServiceImpl();
> > >         Endpoint ep = Endpoint.publish("
> > > http://localhost:8080/apps/MyService",
> > > service);
> > >
> > > This works.
> > >
> > > - But how do I get access to the *correct* bus when deployed in Tomcat?
> > > - And how can I set my ServerLicefycleListener *before* services get
> > > published by the cxf-servlet.xml?
> > >
> >

Re: How to install a CXF ServerLifeCycleListener when app is running in Apache Tomcat?

Posted by Frizz <fr...@googlemail.com>.
How do I access the WebApplicationContext?

I did this in my code:

@Resource
private WebServiceContext wsContext;

The code gets executed when I deploy the WAR, but wsContext is null.



On Sun, Jun 7, 2015 at 6:31 PM, André Costa Lima <an...@gmail.com>
wrote:

> Hi,
>
> You can set publish=false in jaws:endpoint. Then, through
> WebApplicationContext you can get the bean and start the endpoint yourself.
> You probably can get the Bus through the bean casting.
>
> There is probably a cleaner way of doing this. Maybe supplying the Bus to
> the endpoint in Spring xml configuration?
>
> Regards,
>
> André Costa Lima
>
>
> 2015-06-07 15:40 GMT+01:00 Frizz <fr...@googlemail.com>:
>
> > I have published a Web-Service in Tomcat with cxf-servlet.xml
> >
> >    <jaxws:endpoint id="myService"
> >         implementor="#MyServiceImpl" address="/MyService">
> >    </jaxws:endpoint>
> >
> > So far, so god.
> >
> > Now I wanted to add a CXF ServerLifeCycleListener, but it seems this has
> to
> > be done BEFORE the service is published in order to have an effect.
> >
> > How can I do this with Tomcat / Spring?
> >
> >
> > When I run my app in pure Java I do it this way:
> >
> >         Bus cxfBus = BusFactory.getDefaultBus();
> >         ServerLifeCycleManager mgr =
> > cxfBus.getExtension(ServerLifeCycleManager.class);
> >         mgr.registerListener(new MyListener());
> >
> >         MyServiceImpl fri = new MyServiceImpl();
> >         Endpoint ep = Endpoint.publish("
> > http://localhost:8080/apps/MyService",
> > service);
> >
> > This works.
> >
> > - But how do I get access to the *correct* bus when deployed in Tomcat?
> > - And how can I set my ServerLicefycleListener *before* services get
> > published by the cxf-servlet.xml?
> >
>

Re: How to install a CXF ServerLifeCycleListener when app is running in Apache Tomcat?

Posted by André Costa Lima <an...@gmail.com>.
Hi,

You can set publish=false in jaws:endpoint. Then, through
WebApplicationContext you can get the bean and start the endpoint yourself.
You probably can get the Bus through the bean casting.

There is probably a cleaner way of doing this. Maybe supplying the Bus to
the endpoint in Spring xml configuration?

Regards,

André Costa Lima


2015-06-07 15:40 GMT+01:00 Frizz <fr...@googlemail.com>:

> I have published a Web-Service in Tomcat with cxf-servlet.xml
>
>    <jaxws:endpoint id="myService"
>         implementor="#MyServiceImpl" address="/MyService">
>    </jaxws:endpoint>
>
> So far, so god.
>
> Now I wanted to add a CXF ServerLifeCycleListener, but it seems this has to
> be done BEFORE the service is published in order to have an effect.
>
> How can I do this with Tomcat / Spring?
>
>
> When I run my app in pure Java I do it this way:
>
>         Bus cxfBus = BusFactory.getDefaultBus();
>         ServerLifeCycleManager mgr =
> cxfBus.getExtension(ServerLifeCycleManager.class);
>         mgr.registerListener(new MyListener());
>
>         MyServiceImpl fri = new MyServiceImpl();
>         Endpoint ep = Endpoint.publish("
> http://localhost:8080/apps/MyService",
> service);
>
> This works.
>
> - But how do I get access to the *correct* bus when deployed in Tomcat?
> - And how can I set my ServerLicefycleListener *before* services get
> published by the cxf-servlet.xml?
>