You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Kirill R." <bo...@gmail.com> on 2008/10/23 09:18:25 UTC

configuring CXFServlet to publish services using JAX-WS API

I have found a few threads on this topic but none really answered my
question, so here goes:

We have a standalone application which uses a Spring context with embedded
Jetty.
I want to be able to start and stop web services in runtime using the CXF
servlet hosted in that Jetty.
In order to do this, I need to access servlet's bus as suggested in docs. So
I create the servlet
as a bean in our Spring context, hook it up to Jetty using a simple wrapper:

[code]
    public ServletWrapperBean(ContextHandlerCollection contexts,
        CXFServlet cxfServlet, String path) throws Exception
    {
        final Context root = new Context(contexts, "/", Context.SESSIONS);
        ServletHolder servlet = new ServletHolder(cxfServlet);
        root.addServlet(servlet, path);
    }
[/code]

and then pass to my class which uses it to set BusFactory's defaultBus
before publishing services.

And it doesn't quite work:
in 2.1.1 the servlet's bus was null and CXF was unable to locate the HTTP
transport extension.
With newer versions (tried 2.1.3 today), it can't even load our Spring
context because CFXServlet throws
an NPE in updateContext (ServletConfig is null).

How do I configure it properly?

Sorry if this is an amateurish question.
-- 
View this message in context: http://www.nabble.com/configuring-CXFServlet-to-publish-services-using-JAX-WS-API-tp20125613p20125613.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: configuring CXFServlet to publish services using JAX-WS API

Posted by Daniel Kulp <dk...@apache.org>.
On Thursday 23 October 2008 5:42:30 am Kirill R. wrote:
> The problem is, with CXFServlet being another bean in our Spring context,
> it prevents the context
> from loading by throwing NPE in updateContext and it doesn't even get to
> the point where I
> retrieve the servlet's bus.
>
> Otherwise, my wrapper (quoted in the first post) does just the same thing
> as this test you
> cited. However, servletConfig isn't set at the time
> CXFServlet.updateContext is called and I have
> no idea where it's supposed to come from.

I wonder if it would make sense for you to just subclass the 
AbstractCXFServlet and override loadBus(ServletConfig servletConfig) to get 
your ApplicationContext from the config and get the bus (object name would 
be "cxf") from that context and then call the registration stuff.    
Something like:


    private void loadBus(ServletConfig servletConfig) 
       throws ServletException {

        ServletContext svCtx = getServletContext();
        ApplicationContext ctx = (ApplicationContext)svCtx
            .getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");

	bus = ctx.getBean("cxf", Bus.class);
        ResourceManager resourceManager = 
bus.getExtension(ResourceManager.class);
        resourceManager.addResourceResolver(new 
ServletContextResourceResolver(
                                               
servletConfig.getServletContext()));

        replaceDestinationFactory();
        // Set up the ServletController
        controller = createServletController(servletConfig);
    }

In your context, you just need to "import" the various CXF things you need 
(cxf.xml/cxf-extension-soap.xml/etc...) (or cxf-all.xml if you use the 
bundle)


-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Re: configuring CXFServlet to publish services using JAX-WS API

Posted by "Kirill R." <bo...@gmail.com>.
The problem is, with CXFServlet being another bean in our Spring context, it
prevents the context
from loading by throwing NPE in updateContext and it doesn't even get to the
point where I
retrieve the servlet's bus.

Otherwise, my wrapper (quoted in the first post) does just the same thing as
this test you
cited. However, servletConfig isn't set at the time CXFServlet.updateContext
is called and I have
no idea where it's supposed to come from.
-- 
View this message in context: http://www.nabble.com/configuring-CXFServlet-to-publish-services-using-JAX-WS-API-tp20125613p20127670.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: configuring CXFServlet to publish services using JAX-WS API

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

You can take a look at this code[1] in the CXF systests. You just need
to change the CXFNonSpringServlet to CXFSpringServlet.
[1]
https://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletServer.java

Willem

Kirill R. wrote:
> I have found a few threads on this topic but none really answered my
> question, so here goes:
> 
> We have a standalone application which uses a Spring context with embedded
> Jetty.
> I want to be able to start and stop web services in runtime using the CXF
> servlet hosted in that Jetty.
> In order to do this, I need to access servlet's bus as suggested in docs. So
> I create the servlet
> as a bean in our Spring context, hook it up to Jetty using a simple wrapper:
> 
> [code]
>     public ServletWrapperBean(ContextHandlerCollection contexts,
>         CXFServlet cxfServlet, String path) throws Exception
>     {
>         final Context root = new Context(contexts, "/", Context.SESSIONS);
>         ServletHolder servlet = new ServletHolder(cxfServlet);
>         root.addServlet(servlet, path);
>     }
> [/code]
> 
> and then pass to my class which uses it to set BusFactory's defaultBus
> before publishing services.
> 
> And it doesn't quite work:
> in 2.1.1 the servlet's bus was null and CXF was unable to locate the HTTP
> transport extension.
> With newer versions (tried 2.1.3 today), it can't even load our Spring
> context because CFXServlet throws
> an NPE in updateContext (ServletConfig is null).
> 
> How do I configure it properly?
> 
> Sorry if this is an amateurish question.


Re: configuring CXFServlet to publish services using JAX-WS API

Posted by Daniel Kulp <dk...@apache.org>.
On Thursday 23 October 2008 5:25:19 pm Glen Mazza wrote:
> I'm not accustomed to the concept of starting and stopping web services, as
> opposed to starting and stopping the servlet that hosts them.  The latter
> seems more natural, and can be handled just as you would for any
> servlet-based web application.  Another issue is that I'm unsure whether
> CXFServlet was designed to turn on/off web services (as opposed to
> CXFServlet being turned on/off itself in order to accomplish the same
> purpose)--and how tested such functionality is, even if it's available.

It's definitely possible.   We have a couple system tests that do a "factory 
pattern" thing where there is one web service that acts as a factory for 
other webservices that get registered and such as demand.   

Basically, the JAX-WS spec specifically allows for it.    The RI is a bit 
strange in that anything that you "endpoint.publish" would come up via the 
embedded HTTP engine on a different port than your servlet, but it certainly 
allows it.   CXF forces into the same servlet as the current bus.

Dan


>
> Glen
>
> Kirill R. wrote:
> > I want to be able to start and stop web services in runtime using the CXF
> > servlet hosted in that Jetty.



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Re: configuring CXFServlet to publish services using JAX-WS API

Posted by Glen Mazza <gl...@gmail.com>.
I'm not accustomed to the concept of starting and stopping web services, as
opposed to starting and stopping the servlet that hosts them.  The latter
seems more natural, and can be handled just as you would for any
servlet-based web application.  Another issue is that I'm unsure whether
CXFServlet was designed to turn on/off web services (as opposed to
CXFServlet being turned on/off itself in order to accomplish the same
purpose)--and how tested such functionality is, even if it's available.

Glen


Kirill R. wrote:
> 
> I want to be able to start and stop web services in runtime using the CXF
> servlet hosted in that Jetty.
> 

-- 
View this message in context: http://www.nabble.com/configuring-CXFServlet-to-publish-services-using-JAX-WS-API-tp20125613p20139893.html
Sent from the cxf-user mailing list archive at Nabble.com.