You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Michael Kleinhenz <m....@tarent.de> on 2007/12/20 17:48:21 UTC

Adding ServiceConfigurations / ServiceFactories

Hi,

I try to get used to the inner workings of cxf. I suppose it is possible
to add new ServiceFactories to cxf, but how would this be done?

If I create a new ServiceFactory by subclassing AbstractServiceFactory,
how do I add it to cxf?

Another thing: the documentation talks about customizing the behaviour
of ReflectionServiceFactoryBean by adding ServiceConfigurations. How do
I add these ServiceConfigurations to cxf in a servlet environment. The
example creates the server from scratch, but I understand that in a
servlet context, the Server instance is started (I think) from CXFServlet..?

I try to do this:

public class MyCustomServlet extends CXFServlet
{
    @Override
    public void init(ServletConfig servletConfig)
                  throws ServletException
    {
        super.init(servletConfig);

        Bus bus = getBus();
        BusFactory.setDefaultBus(bus);

        ReflectionServiceFactoryBean serviceFactory =
                     new ReflectionServiceFactoryBean();
        serviceFactory.getServiceConfigurations()
                     .add(0, new AbstractServiceConfiguration()
        {
		.. my programmatically created service setup ..
        });

	... now, how to set my custom ServiceFactory to be used? ...

	// standard JAX-WS service creation
        Endpoint.publish("/OtherService", new OtherServiceImpl());
    }
}

Thanks,
-- Michael

-- 
Dipl.-Technoinform Michael Kleinhenz

tarent
Gesellschaft für Softwareentwicklung und IT-Beratung mbH

Heilsbachstr. 24, 53123 Bonn  | Poststr. 4-5, 10178 Berlin
fon: +49(228) / 52675-0       | fon: +49(30) / 27594853
fax: +49(228) / 52675-25      | fax: +49(30) / 78709617

Geschäftsführer: Boris Esser, Elmar Geese, Thomas Müller-Ackermann
HRB AG Bonn 5168 - Ust-ID: DE122264941

Re: Adding ServiceConfigurations / ServiceFactories

Posted by Jim Ma <em...@iona.com>.
Hi Micheal,

You also need to  instantiate a ServerFactoryBean (or your own server 
factory that
extends ServerFactoryBean) and start it:

 ServerFactoryBean svrFactory = new ServerFactoryBean();
 svrFactory.setBus(bus);   // set cxf default bus
 svrFactory.setServiceFactory(YourServiceFactoryBean);
 svrFactory.setAddress(address); 
 svrFactory.setStart(true);
 svrFactory.create();

Before start the server , replace  the DestinationFactory
and create ServletController like the CXFServlet does.

Regards

Jim


Michael Kleinhenz wrote:
> Hi Jim,
>
> mmh, I don't get it, sorry. I create a new ServiceFactoryBean, do the
> configuration, but what to do then? I suppose I have to inject the new
> ServiceFactoryBean somehow into cxf.
>
>   
>> subclassing AbstractServiceFactoryBean. Then use your own
>> ServiceFactoryBean to create your Servlet :
>>     
>
> How do I do that? Sorry if this is a dull question, but I don't see how
> the ServiceFactoryBean is used after creation:
>
>   
>> public class MyCustomServlet extends CXFServlet
>> {
>>    @Override
>>    public void init(ServletConfig servletConfig)
>>                  throws ServletException
>>    {
>>        super.init(servletConfig);
>>
>>        Bus bus = getBus();
>>        BusFactory.setDefaultBus(bus);
>>
>>        YourServiceFactoryBean serviceFactory =
>>                     new YourServiceFactoryBean ();
>>        serviceFactory.getServiceConfigurations()
>>                   .add(0, new AbstractServiceConfiguration()
>>     
>
> ... I think there is something missing here ...
>
>   
>>            // standard JAX-WS service creation
>>        Endpoint.publish("/OtherService", new OtherServiceImpl());
>>    }
>> }
>>     
>
> Thanks,
> Michael
>
>   

Re: Adding ServiceConfigurations / ServiceFactories

Posted by Michael Kleinhenz <m....@tarent.de>.
Hi Jim,

mmh, I don't get it, sorry. I create a new ServiceFactoryBean, do the
configuration, but what to do then? I suppose I have to inject the new
ServiceFactoryBean somehow into cxf.

> subclassing AbstractServiceFactoryBean. Then use your own
> ServiceFactoryBean to create your Servlet :

How do I do that? Sorry if this is a dull question, but I don't see how
the ServiceFactoryBean is used after creation:

> public class MyCustomServlet extends CXFServlet
> {
>    @Override
>    public void init(ServletConfig servletConfig)
>                  throws ServletException
>    {
>        super.init(servletConfig);
> 
>        Bus bus = getBus();
>        BusFactory.setDefaultBus(bus);
> 
>        YourServiceFactoryBean serviceFactory =
>                     new YourServiceFactoryBean ();
>        serviceFactory.getServiceConfigurations()
>                   .add(0, new AbstractServiceConfiguration()

... I think there is something missing here ...

>            // standard JAX-WS service creation
>        Endpoint.publish("/OtherService", new OtherServiceImpl());
>    }
> }

Thanks,
Michael

-- 
Dipl.-Technoinform Michael Kleinhenz

tarent
Gesellschaft für Softwareentwicklung und IT-Beratung mbH

Heilsbachstr. 24, 53123 Bonn  | Poststr. 4-5, 10178 Berlin
fon: +49(228) / 52675-0       | fon: +49(30) / 27594853
fax: +49(228) / 52675-25      | fax: +49(30) / 78709617

Geschäftsführer: Boris Esser, Elmar Geese, Thomas Müller-Ackermann
HRB AG Bonn 5168 - Ust-ID: DE122264941

Re: Adding ServiceConfigurations / ServiceFactories

Posted by Jim Ma <em...@iona.com>.
Hi Micheal ,

I suppose you actually mean create your own ServiceFactoryBean that 
extends AbstractServiceFactoryBean.
AbstractServiceFactory is only used for code generation .

You can create new ServiceFactoryBean by extending  
ReflectionServiceFactoryBean , JaxwsServiceFactoryBean or
subclassing AbstractServiceFactoryBean. Then use your own 
ServiceFactoryBean to create your Servlet :

public class MyCustomServlet extends CXFServlet
{
    @Override
    public void init(ServletConfig servletConfig)
                  throws ServletException
    {
        super.init(servletConfig);

        Bus bus = getBus();
        BusFactory.setDefaultBus(bus);

        YourServiceFactoryBean serviceFactory =
                     new YourServiceFactoryBean ();
        serviceFactory.getServiceConfigurations()
                   .add(0, new AbstractServiceConfiguration()
        
	// standard JAX-WS service creation
        Endpoint.publish("/OtherService", new OtherServiceImpl());
    }
}

Regards

Jim

Michael Kleinhenz wrote:
> Hi,
>
> I try to get used to the inner workings of cxf. I suppose it is possible
> to add new ServiceFactories to cxf, but how would this be done?
>
> If I create a new ServiceFactory by subclassing AbstractServiceFactory,
> how do I add it to cxf?
>
> Another thing: the documentation talks about customizing the behaviour
> of ReflectionServiceFactoryBean by adding ServiceConfigurations. How do
> I add these ServiceConfigurations to cxf in a servlet environment. The
> example creates the server from scratch, but I understand that in a
> servlet context, the Server instance is started (I think) from CXFServlet..?
>
> I try to do this:
>
> public class MyCustomServlet extends CXFServlet
> {
>     @Override
>     public void init(ServletConfig servletConfig)
>                   throws ServletException
>     {
>         super.init(servletConfig);
>
>         Bus bus = getBus();
>         BusFactory.setDefaultBus(bus);
>
>         ReflectionServiceFactoryBean serviceFactory =
>                      new ReflectionServiceFactoryBean();
>         serviceFactory.getServiceConfigurations()
>                      .add(0, new AbstractServiceConfiguration()
>         {
> 		.. my programmatically created service setup ..
>         });
>
> 	... now, how to set my custom ServiceFactory to be used? ...
>
> 	// standard JAX-WS service creation
>         Endpoint.publish("/OtherService", new OtherServiceImpl());
>     }
> }
>
> Thanks,
> -- Michael
>
>