cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem Jiang <>
Subject Re: Use CXFServlet programmatically (moving from XFire to CXF)
Date Thu, 31 May 2007 05:34:12 GMT
Hi Fabian,

There is a Jetty transport factory which responsible is to handle the 
http transport with the embedded Jetty in CXF, we call the service which 
is published by that way,  a standalone server.
We also support to publish the service with CXFServlet transport. It is 
much like the Xfire Servlet dose.
You definitely can start a Jetty HTTPServer and register the CXFServlet 
to it then publish the service with JAXWS API or JaxWsServerFactoryBean.
But most important thing you need to take care is the bus instance, it 
is newer to Xfire user. You can find more information about the CXF bus 
from [1].
I also found there some error in the document [2], I will fix soon.

I just changed some of you below codes and ran with latest CXF trunk, it 
You can access the service with http://localhost:9000/services/GreeterImpl
You also can get the services list form http://localhost:9000/services

         Server httpServer = new Server(9000);
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        Context root = new Context(contexts,"/services",Context.SESSIONS);
        CXFServlet servlet = new CXFServlet();
        root.addServlet(new ServletHolder(servlet), "/*");
        // set the default bus which is initiated for CXFServlet  for 
jaxws API or JaxWsServerFactoryBean to use
        Bus bus = servlet.getBus();
        // there is no bus definition in the JAXWS API, so we need to 
set the default bus.
        // register service, the address should start with "/"
        String uri = "/" + GreeterImpl.class.getSimpleName();
        Endpoint endpoint = Endpoint.create(new GreeterImpl());




Fabian wrote:
> Hi!
> I started to have a look at CXF today. In XFire I was able to start a 
> Jetty HTTPServer, register the XFireServlet and later make services 
> available via the XFire ServiceRegistry.So I was able to use a Jetty 
> HTTPServer I created myself. I would like to do the same with CXF.
> Using the JaxWsServerFactoryBean as suggested in the Migration Guide 
> does not work because I want to reuse the HTTPServer I already have 
> and don't want to start a new one (under another port). So I thought 
> the CXFServlet should be the proper replacement. But I am not sure 
> what I need to do to register a new service. Calling Endpoint.create() 
> as explained in 
> does not work. 
> (I can request the service list at http://localhost:8080/services but 
> the list is empty). So I guess I have to do something with my Endpoint 
> but what?
>  // jetty
> Server httpServer = new Server(8080); Context xfireContext = new 
> Context(httpServer, "/services");
> xfireContext.addServlet(CXFServlet.class.getName(), "/*");     
> httpServer.start();
>        // register service
> String uri = "http://localhost:8080/services/" + 
> ServiceImplementation.class.getSimpleName();
> Endpoint.create(uri, new ServiceImplementation());
> Maybe one of you can give me a tip which way to go here.
> Thanks!
> Fabian
> P.S. In XFire it worked like this
> Server httpServer = new Server(8080); Context xfireContext = new 
> Context(httpServer, "/services");
> xfireContext.addServlet(XFireServlet.class.getName(), "/*");     
> httpServer.start();
> [....]
> XFire xfire = XFireFactory.newInstance().getXFire();
> // create service
> AnnotationServiceFactory factory = new 
> AnnotationServiceFactory(xfire.getTransportManager())
> Service service = factory.create(serviceImplementation.getClass());
> service.setInvoker(new BeanInvoker(serviceImplementation));
> // register
> ServiceRegistry serviceRegistry = xfire.getServiceRegistry()
> serviceRegistry.register(service);

View raw message