You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sebastian Himberger <se...@gmx.de> on 2009/03/21 10:48:41 UTC

How to publish simple Service programatically (CXFNonSpringServlet , Tomcat, ReflectionServiceFactoryBean) ?

Hi,

I'm new to CXF and want to create some webservices programatically using
the simple front (because I want to discover the webservice classes
programatically) and using the CXFNonSpringServlet (deployed in Tomcat).

I've looked at the examples in the documentation but unfortunately the
CXFNonSpringServlet example uses the JAX-WS frontend. This is my
(condensed) sourcecode [1]:

In the example I would use the JAX-WS "Endpoint.publish()" to publish my
endpoint but since I'm using the reflectionFactory for creating my
Service this doesn't work. How to I
publish my Service so that the Servlet picks it up programatically? I've
already spent two hours browsing through the sourcecode and ended up
debugging the ServletController in "org.apache.cxf.transport.servlet".
Here the call "ServletDestination d =
(ServletDestination)transport.getDestinationForPath(ei.getAddress());"
always returns null. This (I suspect) due to the fact that my Service is
not properly published.

This is my log output:

INFO: Load the bus without application context
21.03.2009 10:21:51 org.apache.cxf.transport.servlet.AbstractCXFServlet
replaceDestinationFactory
INFO: Replaced the http destination factory with servlet transport factory
21.03.2009 10:26:46 org.apache.cxf.transport.servlet.ServletController
invoke
WARNING: Can't find the request for
http://localhost:8080/autoservices/services/TestService's Observer

Any help is greatly appreciated. The API of CXF is so big that it's hard
for me to find the right classes to look into. I've already tried making
Sense of the ServerFactoryBean but it didn't help so much.

Thanks a lot in advance,
Sebastian

1:
public class AutomaticWSServlet extends CXFNonSpringServlet {

    @Override
    public void loadBus(ServletConfig servletConfig) throws
ServletException {
        super.loadBus(servletConfig);
        //String busFactory =
System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
        //System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME,
"org.apache.cxf.bus.CXFBusFactory");
        //String busFactory2 =
System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
        Bus bus = this.getBus();
        BusFactory.setDefaultBus(bus);
        registerServices(bus);          
    }

    private void registerServices(Bus b) {
        try {
            ReflectionServiceFactoryBean reflectionFactory = new
ReflectionServiceFactoryBean();
            reflectionFactory.setBus(b);
           
            // Get the class and datamodel
           
            reflectionFactory.setServiceClass(serviceClass);
            Service service = reflectionFactory.create();
             
            //Endpoint.publish("/foo",service);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }

Re: How to publish simple Service programatically (CXFNonSpringServlet , Tomcat, ReflectionServiceFactoryBean) ?

Posted by Daniel Kulp <dk...@apache.org>.
On Monday, June 27, 2011 10:21:13 AM sudhakar wrote:
> The above example, when i am trying to code same way i am getting type cast
> exception for ServerFactoryBean factory = new ServiceFactoryBean();
> 
> Any help?

It should be:

ServerFactoryBean factory = new ServerFactoryBean(); 
 

Dan


> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-publish-simple-Service-programatical
> ly-CXFNonSpringServlet-Tomcat-ReflectionServiceFactoryBea-tp563152p4529136.h
> tml Sent from the cxf-user mailing list archive at Nabble.com.
-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: How to publish simple Service programatically (CXFNonSpringServlet , Tomcat, ReflectionServiceFactoryBean) ?

Posted by sudhakar <su...@gmail.com>.
The above example, when i am trying to code same way i am getting type cast
exception for ServerFactoryBean factory = new ServiceFactoryBean(); 

Any help?

--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-publish-simple-Service-programatically-CXFNonSpringServlet-Tomcat-ReflectionServiceFactoryBea-tp563152p4529136.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to publish simple Service programatically (CXFNonSpringServlet , Tomcat, ReflectionServiceFactoryBean) ?

Posted by Sebastian Himberger <se...@gmx.de>.
Hi Willem,

thanks very much for this answer. This is exactly what I needed. Thanks
thanks thanks!

I thought the ServerFactoryBean could only be used as a standalone
server. I've thrown your code in and it seems to work.

I will play around further and hopefully get everything to work.

All the best,
Sebastian


Willem Jiang schrieb:
> Hi ,
>
> If you are using the simple front end API to publish the endpoint,
> you need to use ServerFactoryBean instead of ReflectionServiceFactory
> and set the address your self.
> Here is the simple front end API to publish the service
>
> ServerFactoryBean factory = new ServiceFactoryBean();
> factory.setBus(bus);
> factroy.setServiceClass();
> factory.setAddress("/foo");
> Service service = factory.create();
>
> BTW, I will add this example into the wiki.
>
> Willem
>
> Sebastian Himberger wrote:
>   
>> Hi,
>>
>> I'm new to CXF and want to create some webservices programatically using
>> the simple front (because I want to discover the webservice classes
>> programatically) and using the CXFNonSpringServlet (deployed in Tomcat).
>>
>> I've looked at the examples in the documentation but unfortunately the
>> CXFNonSpringServlet example uses the JAX-WS frontend. This is my
>> (condensed) sourcecode [1]:
>>
>> In the example I would use the JAX-WS "Endpoint.publish()" to publish my
>> endpoint but since I'm using the reflectionFactory for creating my
>> Service this doesn't work. How to I
>> publish my Service so that the Servlet picks it up programatically? I've
>> already spent two hours browsing through the sourcecode and ended up
>> debugging the ServletController in "org.apache.cxf.transport.servlet".
>> Here the call "ServletDestination d =
>> (ServletDestination)transport.getDestinationForPath(ei.getAddress());"
>> always returns null. This (I suspect) due to the fact that my Service is
>> not properly published.
>>
>> This is my log output:
>>
>> INFO: Load the bus without application context
>> 21.03.2009 10:21:51 org.apache.cxf.transport.servlet.AbstractCXFServlet
>> replaceDestinationFactory
>> INFO: Replaced the http destination factory with servlet transport factory
>> 21.03.2009 10:26:46 org.apache.cxf.transport.servlet.ServletController
>> invoke
>> WARNING: Can't find the request for
>> http://localhost:8080/autoservices/services/TestService's Observer
>>
>> Any help is greatly appreciated. The API of CXF is so big that it's hard
>> for me to find the right classes to look into. I've already tried making
>> Sense of the ServerFactoryBean but it didn't help so much.
>>
>> Thanks a lot in advance,
>> Sebastian
>>
>> 1:
>> public class AutomaticWSServlet extends CXFNonSpringServlet {
>>
>>     @Override
>>     public void loadBus(ServletConfig servletConfig) throws
>> ServletException {
>>         super.loadBus(servletConfig);
>>         //String busFactory =
>> System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
>>         //System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME,
>> "org.apache.cxf.bus.CXFBusFactory");
>>         //String busFactory2 =
>> System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
>>         Bus bus = this.getBus();
>>         BusFactory.setDefaultBus(bus);
>>         registerServices(bus);          
>>     }
>>
>>     private void registerServices(Bus b) {
>>         try {
>>             ReflectionServiceFactoryBean reflectionFactory = new
>> ReflectionServiceFactoryBean();
>>             reflectionFactory.setBus(b);
>>            
>>             // Get the class and datamodel
>>            
>>             reflectionFactory.setServiceClass(serviceClass);
>>             Service service = reflectionFactory.create();
>>              
>>             //Endpoint.publish("/foo",service);
>>         } catch (Exception e) {
>>             e.printStackTrace(System.err);
>>         }
>>     }
>>
>>     


Re: How to publish simple Service programatically (CXFNonSpringServlet , Tomcat, ReflectionServiceFactoryBean) ?

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

If you are using the simple front end API to publish the endpoint,
you need to use ServerFactoryBean instead of ReflectionServiceFactory
and set the address your self.
Here is the simple front end API to publish the service

ServerFactoryBean factory = new ServiceFactoryBean();
factory.setBus(bus);
factroy.setServiceClass();
factory.setAddress("/foo");
Service service = factory.create();

BTW, I will add this example into the wiki.

Willem

Sebastian Himberger wrote:
> Hi,
> 
> I'm new to CXF and want to create some webservices programatically using
> the simple front (because I want to discover the webservice classes
> programatically) and using the CXFNonSpringServlet (deployed in Tomcat).
> 
> I've looked at the examples in the documentation but unfortunately the
> CXFNonSpringServlet example uses the JAX-WS frontend. This is my
> (condensed) sourcecode [1]:
> 
> In the example I would use the JAX-WS "Endpoint.publish()" to publish my
> endpoint but since I'm using the reflectionFactory for creating my
> Service this doesn't work. How to I
> publish my Service so that the Servlet picks it up programatically? I've
> already spent two hours browsing through the sourcecode and ended up
> debugging the ServletController in "org.apache.cxf.transport.servlet".
> Here the call "ServletDestination d =
> (ServletDestination)transport.getDestinationForPath(ei.getAddress());"
> always returns null. This (I suspect) due to the fact that my Service is
> not properly published.
> 
> This is my log output:
> 
> INFO: Load the bus without application context
> 21.03.2009 10:21:51 org.apache.cxf.transport.servlet.AbstractCXFServlet
> replaceDestinationFactory
> INFO: Replaced the http destination factory with servlet transport factory
> 21.03.2009 10:26:46 org.apache.cxf.transport.servlet.ServletController
> invoke
> WARNING: Can't find the request for
> http://localhost:8080/autoservices/services/TestService's Observer
> 
> Any help is greatly appreciated. The API of CXF is so big that it's hard
> for me to find the right classes to look into. I've already tried making
> Sense of the ServerFactoryBean but it didn't help so much.
> 
> Thanks a lot in advance,
> Sebastian
> 
> 1:
> public class AutomaticWSServlet extends CXFNonSpringServlet {
> 
>     @Override
>     public void loadBus(ServletConfig servletConfig) throws
> ServletException {
>         super.loadBus(servletConfig);
>         //String busFactory =
> System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
>         //System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME,
> "org.apache.cxf.bus.CXFBusFactory");
>         //String busFactory2 =
> System.getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
>         Bus bus = this.getBus();
>         BusFactory.setDefaultBus(bus);
>         registerServices(bus);          
>     }
> 
>     private void registerServices(Bus b) {
>         try {
>             ReflectionServiceFactoryBean reflectionFactory = new
> ReflectionServiceFactoryBean();
>             reflectionFactory.setBus(b);
>            
>             // Get the class and datamodel
>            
>             reflectionFactory.setServiceClass(serviceClass);
>             Service service = reflectionFactory.create();
>              
>             //Endpoint.publish("/foo",service);
>         } catch (Exception e) {
>             e.printStackTrace(System.err);
>         }
>     }
>