You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sergey Beryozkin <sb...@progress.com> on 2009/06/16 10:53:27 UTC

Re: Configure CXF JAXRS services in the Spring context and stand-aloneusage

Hi

Will the code code work for you ?

ClassPathXmlApplicationContext ctx =
            new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxrs/spring/servers.xml"});
// 'simple' is the id of the jaxrs server bean
JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean)ctx.getBean("simple");sfb.create();or may be you just can get all the beans 
from the context and call create() on those which are assignable to JAXRSServerFactoryBean.give a try pleaseCheers, SergeyHello, 
everybody!Can somebody please explain, how can I configure all of beans to be used forserving the RESTful application requests 
within the Spring context, and startthe entire application as a stand-alone app? Looks like the user manual lacksthis section - 
there are examples of how to use JAXRSServerFactoryBean tocreate and start up the server, or use Spring in a servlet container.Thank 
you in advance!-- Eugene N Dzhurinsky

----- Original Message ----- 
From: "Eugeny N Dzhurinsky" <bo...@redwerk.com>
To: <us...@cxf.apache.org>
Sent: Tuesday, June 16, 2009 7:31 AM
Subject: Configure CXF JAXRS services in the Spring context and stand-aloneusage



Re: Configure CXF JAXRS services in the Spring context and stand-aloneusage

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Tue, Jun 16, 2009 at 09:56:39AM +0100, Sergey Beryozkin wrote:
> Not sure why but the message formatting is broken
> Here's another attempt :
> 
> ClassPathXmlApplicationContext ctx =
>             new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxrs/spring/servers.xml"});
> 
> // 'simple' is the id of the jaxrs server bean
> JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean)ctx.getBean("simple");
> sfb.create();
> 
> or may be you just can get all the beans  from the context and call create() on those which are assignable to JAXRSServerFactoryBean
> 
> give a try please
> 
> Cheers, Sergey


Hello, Sergey!

Thank you for the reply, however looks like I am still missing something.

I created the sample application, which has the following beans.xml in the
classpath:

=======================================================================================================
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">

    <!--
        do not use import statements if CXFServlet init parameters link
        to this beans.xml
    -->

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <jaxrs:server id="customerService" address="http://localhost:9000/">
        <jaxrs:serviceBeans>
            <ref bean="customerBean" />
        </jaxrs:serviceBeans>
    </jaxrs:server>

    <bean id="customerBean" class="test.service.CustomerService" />
</beans>
=======================================================================================================

And I am using the following simple class to start the things up:

=======================================================================================================
package test;

import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
                "/beans.xml");
        JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean) ctx
                .getBean("customerService");
        Server server = sfb.create();
        Thread.sleep(Long.MAX_VALUE);
    }
}
=======================================================================================================

And at this point the service seems to start up:

=======================================================================================================
16.06.2009 18:38:58
org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing
org.springframework.context.support.ClassPathXmlApplicationContext@eb017e:
display name
[org.springframework.context.support.ClassPathXmlApplicationContext@eb017e];
startup date [Tue Jun 16 18:38:58 EEST 2009]; root of context hierarchy
16.06.2009 18:38:59
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
16.06.2009 18:38:59
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource
[META-INF/cxf/cxf.xml]
16.06.2009 18:39:00
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource
[META-INF/cxf/cxf-extension-jaxrs-binding.xml]
16.06.2009 18:39:00
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource
[META-INF/cxf/cxf-servlet.xml]
16.06.2009 18:39:00
org.springframework.context.support.AbstractApplicationContext
obtainFreshBeanFactory
INFO: Bean factory for application context
[org.springframework.context.support.ClassPathXmlApplicationContext@eb017e]:
org.springframework.beans.factory.support.DefaultListableBeanFactory@14520eb
16.06.2009 18:39:00
org.springframework.beans.factory.support.DefaultListableBeanFactory
preInstantiateSingletons
INFO: Pre-instantiating singletons in
org.springframework.beans.factory.support.DefaultListableBeanFactory@14520eb:
defining beans
[cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.jaxrs.JAXRSBindingFactory,org.apache.cxf.transport.servlet.ServletTransportFactory,customerService,customerBean];
root of factory hierarchy
16.06.2009 18:39:01 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be http://localhost:9000/
16.06.2009 18:39:01 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be http://localhost:9000/
=======================================================================================================

However there is nothing being listening on the port 9000, and when trying to connect to this URL 
with the browser - the connection refused is reported.

What am I doing in the wrong way?

Thank you in advance!

-- 
Eugene N Dzhurinsky

Re: Configure CXF JAXRS services in the Spring context andstand-aloneusage

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Tue, Jun 16, 2009 at 04:39:32PM -0400, Sergey Beryozkin wrote:
> Hi
> 
> I was planning to write a test, just didn't get a chance yet, sorry.
> Now that you mentioned Jetty, I think may be the trick is to import
> jetty transport, rather that the servlet one, so instead of
> 
> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
> 
> You should do
> 
> <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml"
> />
> 
> Can you try it please ?


Hello, Sergey!

That worked, thank you! Now Jetty starts just fine. Thanks again!

-- 
Eugene N Dzhurinsky

RE: Configure CXF JAXRS services in the Spring context andstand-aloneusage

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi

I was planning to write a test, just didn't get a chance yet, sorry.
Now that you mentioned Jetty, I think may be the trick is to import
jetty transport, rather that the servlet one, so instead of

<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

You should do

<import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml"
/>

Can you try it please ?

Cheers, Sergey


-----Original Message-----
From: Eugeny N Dzhurinsky [mailto:bofh@redwerk.com] 
Sent: 16 June 2009 21:17
To: users@cxf.apache.org
Subject: Re: Configure CXF JAXRS services in the Spring context
andstand-aloneusage

On Tue, Jun 16, 2009 at 09:56:39AM +0100, Sergey Beryozkin wrote:
> Not sure why but the message formatting is broken
> Here's another attempt :
> 
> ClassPathXmlApplicationContext ctx =
>             new ClassPathXmlApplicationContext(new String[]
{"/org/apache/cxf/jaxrs/spring/servers.xml"});
> 
> // 'simple' is the id of the jaxrs server bean
> JAXRSServerFactoryBean sfb =
(JAXRSServerFactoryBean)ctx.getBean("simple");
> sfb.create();
> 
> or may be you just can get all the beans  from the context and call
create() on those which are assignable to JAXRSServerFactoryBean
> 
> give a try please
> 
> Cheers, Sergey


Also I noticed if the following line of code

ClassPathXmlApplicationContext ctx = new
ClassPathXmlApplicationContext("/beans.xml");

appears in the Java class aimed to start up the things, the call to the

JAXRSServerFactoryBean() sfb = new JAXRSServerFactoryBean();
sfb.setAddress("...");
sfb.create();

does not start the internal Jetty server. Commenting out the context
loading
does the trick.

So is it possible the jaxrs:server tag needs to be configured somehow
with the
transport or something like this?

-- 
Eugene N Dzhurinsky

Re: Configure CXF JAXRS services in the Spring context and stand-aloneusage

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Tue, Jun 16, 2009 at 09:56:39AM +0100, Sergey Beryozkin wrote:
> Not sure why but the message formatting is broken
> Here's another attempt :
> 
> ClassPathXmlApplicationContext ctx =
>             new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxrs/spring/servers.xml"});
> 
> // 'simple' is the id of the jaxrs server bean
> JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean)ctx.getBean("simple");
> sfb.create();
> 
> or may be you just can get all the beans  from the context and call create() on those which are assignable to JAXRSServerFactoryBean
> 
> give a try please
> 
> Cheers, Sergey


Also I noticed if the following line of code

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/beans.xml");

appears in the Java class aimed to start up the things, the call to the

JAXRSServerFactoryBean() sfb = new JAXRSServerFactoryBean();
sfb.setAddress("...");
sfb.create();

does not start the internal Jetty server. Commenting out the context loading
does the trick.

So is it possible the jaxrs:server tag needs to be configured somehow with the
transport or something like this?

-- 
Eugene N Dzhurinsky

Re: Configure CXF JAXRS services in the Spring context and stand-aloneusage

Posted by Sergey Beryozkin <sb...@progress.com>.
Not sure why but the message formatting is broken
Here's another attempt :

ClassPathXmlApplicationContext ctx =
            new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxrs/spring/servers.xml"});

// 'simple' is the id of the jaxrs server bean
JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean)ctx.getBean("simple");
sfb.create();

or may be you just can get all the beans  from the context and call create() on those which are assignable to JAXRSServerFactoryBean

give a try please

Cheers, Sergey


----- Original Message ----- 
From: "Sergey Beryozkin" <sb...@progress.com>
To: <us...@cxf.apache.org>
Sent: Tuesday, June 16, 2009 9:53 AM
Subject: Re: Configure CXF JAXRS services in the Spring context and stand-aloneusage


> Hi
>
> Will the code code work for you ?
>
> ClassPathXmlApplicationContext ctx =
>            new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxrs/spring/servers.xml"});
> // 'simple' is the id of the jaxrs server bean
> JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean)ctx.getBean("simple");sfb.create();or may be you just can get all the beans 
> from the context and call create() on those which are assignable to JAXRSServerFactoryBean.give a try pleaseCheers, SergeyHello, 
> everybody!Can somebody please explain, how can I configure all of beans to be used forserving the RESTful application requests 
> within the Spring context, and startthe entire application as a stand-alone app? Looks like the user manual lacksthis section - 
> there are examples of how to use JAXRSServerFactoryBean tocreate and start up the server, or use Spring in a servlet 
> container.Thank you in advance!-- Eugene N Dzhurinsky
>
> ----- Original Message ----- 
> From: "Eugeny N Dzhurinsky" <bo...@redwerk.com>
> To: <us...@cxf.apache.org>
> Sent: Tuesday, June 16, 2009 7:31 AM
> Subject: Configure CXF JAXRS services in the Spring context and stand-aloneusage
>
>