You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2010/06/17 16:23:43 UTC

Re: How to make ServiceBeans created by CXF Servlet to be in prototype or HTTP Session Scope

Hi

JAXRS module also ships prototypes aware factories :
http://cxf.apache.org/docs/jax-rs.html#JAX-RS-Lifecyclemanagement

cheers, Sergey

On Thu, Jun 17, 2010 at 2:57 PM, Daniel Kulp <dk...@apache.org> wrote:

>
>
> I believe the easiest way to do it is to just use the Spring AOP stuff and
> set
> the bookService bean to be scope=session.  Spring will handle the rest.
>
> Dan
>
>
> On Thursday 17 June 2010 6:19:21 am Balaji Sankar Chopparapu wrote:
> > Hi,
> >
> >
> >
> > We Observed Servicebeans created by
> > "org.apache.cxf.transport.servlet.CXFServlet” is always singleton. How
> can
> > I change their scope to prototype or in best case HTTP Session Scope?
> > Please Suggest.
> >
> >
> >
> >
> >
> > *WEB.xml:*
> >
> >         <servlet>
> >
> >                <servlet-name>CXFServlet</servlet-name>
> >
> >                <display-name>CXF Servlet</display-name>
> >
> >                <servlet-class>
> >
> >                        org.apache.cxf.transport.servlet.CXFServlet
> >
> >                </servlet-class>
> >
> >                <load-on-startup>1</load-on-startup>
> >
> >         </servlet>
> >
> > *Bean Definitions:*
> >
> > <jaxrs:server id="restServer" address="/services/">
> >
> >
> >
> >         <jaxrs:serviceBeans>
> >
> >             <ref bean="bookService"/>
> >
> > </jaxrs:serviceBeans>
> >
> >
> > Thanks in Advance,
> >
> > Balaji
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: How to make ServiceBeans created by CXF Servlet to be in prototype or HTTP Session Scope

Posted by Balaji Sankar Chopparapu <ba...@gmail.com>.
Thanks Sergey for you quick reply. The "beanNames"attribute doenst work on
Service Beans.  Is this by design. Even in the example the
"customerBean2,customerBean3" are not referred as service beans.  Please
suggest


     <beans>
  <jaxrs:server id="customerService" address="/service1"
    beanNames="customerBean2 customerBean3">
    <jaxrs:serviceBeans>
*      <ref bean="customerBean" />*
    </jaxrs:serviceBeans>
    <jaxrs:serviceFactories>
      <ref bean="sfactory1" />
      <ref bean="sfactory2" />
    </jaxrs:serviceFactories>
  </jaxrs:server>
*  <bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
  <bean id="customerBean2" class="demo.jaxrs.server.CustomerService2"
scope="prototype"/>
  <bean id="customerBean3" class="demo.jaxrs.server.CustomerService3"
scope="prototype"/>
*
  <bean id="sfactory1" class="org.apache.cxf.jaxrs.
spring.SpringResourceFactory">
     <property name="beanName" value="customerBean4"/>
  </bean>
  <bean id="sfactory2"
class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
     <property name="beanName" value="customerBean5"/>
  </bean>

  <bean id="customerBean4" class="demo.jaxrs.server.CustomerService4"
scope="prototype"/>
  <bean id="customerBean5" class="demo.jaxrs.server.CustomerService5"
scope="prototype"/>
</beans>


On Thu, Jun 17, 2010 at 7:53 PM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi
>
> JAXRS module also ships prototypes aware factories :
> http://cxf.apache.org/docs/jax-rs.html#JAX-RS-Lifecyclemanagement
>
> cheers, Sergey
>
>
> On Thu, Jun 17, 2010 at 2:57 PM, Daniel Kulp <dk...@apache.org> wrote:
>
>>
>>
>> I believe the easiest way to do it is to just use the Spring AOP stuff and
>> set
>> the bookService bean to be scope=session.  Spring will handle the rest.
>>
>> Dan
>>
>>
>> On Thursday 17 June 2010 6:19:21 am Balaji Sankar Chopparapu wrote:
>> > Hi,
>> >
>> >
>> >
>> > We Observed Servicebeans created by
>> > "org.apache.cxf.transport.servlet.CXFServlet” is always singleton. How
>> can
>> > I change their scope to prototype or in best case HTTP Session Scope?
>> > Please Suggest.
>> >
>> >
>> >
>> >
>> >
>> > *WEB.xml:*
>> >
>> >         <servlet>
>> >
>> >                <servlet-name>CXFServlet</servlet-name>
>> >
>> >                <display-name>CXF Servlet</display-name>
>> >
>> >                <servlet-class>
>> >
>> >                        org.apache.cxf.transport.servlet.CXFServlet
>> >
>> >                </servlet-class>
>> >
>> >                <load-on-startup>1</load-on-startup>
>> >
>> >         </servlet>
>> >
>> > *Bean Definitions:*
>> >
>> > <jaxrs:server id="restServer" address="/services/">
>> >
>> >
>> >
>> >         <jaxrs:serviceBeans>
>> >
>> >             <ref bean="bookService"/>
>> >
>> > </jaxrs:serviceBeans>
>> >
>> >
>> > Thanks in Advance,
>> >
>> > Balaji
>>
>> --
>> Daniel Kulp
>> dkulp@apache.org
>> http://dankulp.com/blog
>>
>
>

Re: How to make ServiceBeans created by CXF Servlet to be in prototype or HTTP Session Scope

Posted by Balaji Sankar Chopparapu <ba...@gmail.com>.
Thanks Sergey for you quick reply. The "beanNames"attribute doenst work on
Service Beans.  Is this by design. Even in the example the
"customerBean2,customerBean3" are not referred as service beans.  Please
suggest


     <beans>
  <jaxrs:server id="customerService" address="/service1"
    beanNames="customerBean2 customerBean3">
    <jaxrs:serviceBeans>
*      <ref bean="customerBean" />*
    </jaxrs:serviceBeans>
    <jaxrs:serviceFactories>
      <ref bean="sfactory1" />
      <ref bean="sfactory2" />
    </jaxrs:serviceFactories>
  </jaxrs:server>
*  <bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
  <bean id="customerBean2" class="demo.jaxrs.server.CustomerService2"
scope="prototype"/>
  <bean id="customerBean3" class="demo.jaxrs.server.CustomerService3"
scope="prototype"/>
*
  <bean id="sfactory1" class="org.apache.cxf.jaxrs.
spring.SpringResourceFactory">
     <property name="beanName" value="customerBean4"/>
  </bean>
  <bean id="sfactory2"
class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
     <property name="beanName" value="customerBean5"/>
  </bean>

  <bean id="customerBean4" class="demo.jaxrs.server.CustomerService4"
scope="prototype"/>
  <bean id="customerBean5" class="demo.jaxrs.server.CustomerService5"
scope="prototype"/>
</beans>


On Thu, Jun 17, 2010 at 7:53 PM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi
>
> JAXRS module also ships prototypes aware factories :
> http://cxf.apache.org/docs/jax-rs.html#JAX-RS-Lifecyclemanagement
>
> cheers, Sergey
>
>
> On Thu, Jun 17, 2010 at 2:57 PM, Daniel Kulp <dk...@apache.org> wrote:
>
>>
>>
>> I believe the easiest way to do it is to just use the Spring AOP stuff and
>> set
>> the bookService bean to be scope=session.  Spring will handle the rest.
>>
>> Dan
>>
>>
>> On Thursday 17 June 2010 6:19:21 am Balaji Sankar Chopparapu wrote:
>> > Hi,
>> >
>> >
>> >
>> > We Observed Servicebeans created by
>> > "org.apache.cxf.transport.servlet.CXFServlet” is always singleton. How
>> can
>> > I change their scope to prototype or in best case HTTP Session Scope?
>> > Please Suggest.
>> >
>> >
>> >
>> >
>> >
>> > *WEB.xml:*
>> >
>> >         <servlet>
>> >
>> >                <servlet-name>CXFServlet</servlet-name>
>> >
>> >                <display-name>CXF Servlet</display-name>
>> >
>> >                <servlet-class>
>> >
>> >                        org.apache.cxf.transport.servlet.CXFServlet
>> >
>> >                </servlet-class>
>> >
>> >                <load-on-startup>1</load-on-startup>
>> >
>> >         </servlet>
>> >
>> > *Bean Definitions:*
>> >
>> > <jaxrs:server id="restServer" address="/services/">
>> >
>> >
>> >
>> >         <jaxrs:serviceBeans>
>> >
>> >             <ref bean="bookService"/>
>> >
>> > </jaxrs:serviceBeans>
>> >
>> >
>> > Thanks in Advance,
>> >
>> > Balaji
>>
>> --
>> Daniel Kulp
>> dkulp@apache.org
>> http://dankulp.com/blog
>>
>
>

Re: How to make ServiceBeans created by CXF Servlet to be in prototype or HTTP Session Scope

Posted by Sudheer <su...@gmail.com>.
Thank you for the response Sergey!

You mean to say we can use either 'jaxrs:serviceBeans' approach or
beanNames="customerBean2 customerBean3" approach (same as factory
internally) to have service beans.

Sudheer
On Tue, Jun 22, 2010 at 2:33 AM, Sergey Beryozkin <sb...@gmail.com>wrote:

> Hi
>
> What exactly does not work ?
> 1.<jaxrs:serviceBeans>
> *      <ref bean="customerBean" />*
> </jaxrs:serviceBeans>
>
> refers to the singleton bean. Beans declared inside/linked from
> jaxrs:serviceBeans can be singletons only, it is a bit confusing probably,
> but this is the limitation.
> 2. beans = "customerBean2 customerBean3" refer to  customerBean2 &
> customerBean3 beans. Using the 'beans' attribute is a shortcut, it is
> equivalent to  using
>
> <jaxrs:serviceFactories>
>      <ref bean="sfactory1" />
>      <ref bean="sfactory2" />
> </jaxrs:serviceFactories>
>
> where each factory bean refers to a bean it manages (customerBean4 &
> customerBean5).
>
> So one can use either jaxrs:serviceBeans or jaxrs:serviceFactories ( often
> equivalent to jaxrs:server/@beans )
>
> Using Spring AOP is another option.
>
> cheers, Sergey
>
> On Mon, Jun 21, 2010 at 7:02 AM, Balaji Sankar Chopparapu <
> balaji.chopparapu@gmail.com> wrote:
>
> > Thanks Sergey for you quick reply. The "beanNames"attribute doenst work
> on
> > Service Beans.  Is this by design. Even in the example the
> > "customerBean2,customerBean3" are not referred as service beans.  Please
> > suggest
> >
> >
> >      <beans>
> >   <jaxrs:server id="customerService" address="/service1"
> >     beanNames="customerBean2 customerBean3">
> >     <jaxrs:serviceBeans>
> > *      <ref bean="customerBean" />*
> >     </jaxrs:serviceBeans>
> >     <jaxrs:serviceFactories>
> >       <ref bean="sfactory1" />
> >       <ref bean="sfactory2" />
> >     </jaxrs:serviceFactories>
> >   </jaxrs:server>
> > *  <bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
> >   <bean id="customerBean2" class="demo.jaxrs.server.CustomerService2"
> > scope="prototype"/>
> >   <bean id="customerBean3" class="demo.jaxrs.server.CustomerService3"
> > scope="prototype"/>
> > *
> >   <bean id="sfactory1"
> > class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
> >      <property name="beanName" value="customerBean4"/>
> >   </bean>
> >   <bean id="sfactory2"
> > class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
> >      <property name="beanName" value="customerBean5"/>
> >   </bean>
> >
> >   <bean id="customerBean4" class="demo.jaxrs.server.CustomerService4"
> > scope="prototype"/>
> >   <bean id="customerBean5" class="demo.jaxrs.server.CustomerService5"
> > scope="prototype"/>
> > </beans>
> >
> >
> >
> > On Thu, Jun 17, 2010 at 7:53 PM, Sergey Beryozkin <sberyozkin@gmail.com
> >wrote:
> >
> >> Hi
> >>
> >> JAXRS module also ships prototypes aware factories :
> >> http://cxf.apache.org/docs/jax-rs.html#JAX-RS-Lifecyclemanagement
> >>
> >> cheers, Sergey
> >>
> >>
> >> On Thu, Jun 17, 2010 at 2:57 PM, Daniel Kulp <dk...@apache.org> wrote:
> >>
> >>>
> >>>
> >>> I believe the easiest way to do it is to just use the Spring AOP stuff
> >>> and set
> >>> the bookService bean to be scope=session.  Spring will handle the rest.
> >>>
> >>> Dan
> >>>
> >>>
> >>> On Thursday 17 June 2010 6:19:21 am Balaji Sankar Chopparapu wrote:
> >>> > Hi,
> >>> >
> >>> >
> >>> >
> >>> > We Observed Servicebeans created by
> >>> > "org.apache.cxf.transport.servlet.CXFServlet” is always singleton.
> How
> >>> can
> >>> > I change their scope to prototype or in best case HTTP Session Scope?
> >>> > Please Suggest.
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> > *WEB.xml:*
> >>> >
> >>> >         <servlet>
> >>> >
> >>> >                <servlet-name>CXFServlet</servlet-name>
> >>> >
> >>> >                <display-name>CXF Servlet</display-name>
> >>> >
> >>> >                <servlet-class>
> >>> >
> >>> >                        org.apache.cxf.transport.servlet.CXFServlet
> >>> >
> >>> >                </servlet-class>
> >>> >
> >>> >                <load-on-startup>1</load-on-startup>
> >>> >
> >>> >         </servlet>
> >>> >
> >>> > *Bean Definitions:*
> >>> >
> >>> > <jaxrs:server id="restServer" address="/services/">
> >>> >
> >>> >
> >>> >
> >>> >         <jaxrs:serviceBeans>
> >>> >
> >>> >             <ref bean="bookService"/>
> >>> >
> >>> > </jaxrs:serviceBeans>
> >>> >
> >>> >
> >>> > Thanks in Advance,
> >>> >
> >>> > Balaji
> >>>
> >>> --
> >>> Daniel Kulp
> >>> dkulp@apache.org
> >>> http://dankulp.com/blog
> >>>
> >>
> >>
> >
>

Re: How to make ServiceBeans created by CXF Servlet to be in prototype or HTTP Session Scope

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

What exactly does not work ?
1.<jaxrs:serviceBeans>
*      <ref bean="customerBean" />*
</jaxrs:serviceBeans>

refers to the singleton bean. Beans declared inside/linked from
jaxrs:serviceBeans can be singletons only, it is a bit confusing probably,
but this is the limitation.
2. beans = "customerBean2 customerBean3" refer to  customerBean2 &
customerBean3 beans. Using the 'beans' attribute is a shortcut, it is
equivalent to  using

<jaxrs:serviceFactories>
      <ref bean="sfactory1" />
      <ref bean="sfactory2" />
</jaxrs:serviceFactories>

where each factory bean refers to a bean it manages (customerBean4 &
customerBean5).

So one can use either jaxrs:serviceBeans or jaxrs:serviceFactories ( often
equivalent to jaxrs:server/@beans )

Using Spring AOP is another option.

cheers, Sergey

On Mon, Jun 21, 2010 at 7:02 AM, Balaji Sankar Chopparapu <
balaji.chopparapu@gmail.com> wrote:

> Thanks Sergey for you quick reply. The "beanNames"attribute doenst work on
> Service Beans.  Is this by design. Even in the example the
> "customerBean2,customerBean3" are not referred as service beans.  Please
> suggest
>
>
>      <beans>
>   <jaxrs:server id="customerService" address="/service1"
>     beanNames="customerBean2 customerBean3">
>     <jaxrs:serviceBeans>
> *      <ref bean="customerBean" />*
>     </jaxrs:serviceBeans>
>     <jaxrs:serviceFactories>
>       <ref bean="sfactory1" />
>       <ref bean="sfactory2" />
>     </jaxrs:serviceFactories>
>   </jaxrs:server>
> *  <bean id="customerBean" class="demo.jaxrs.server.CustomerService" />
>   <bean id="customerBean2" class="demo.jaxrs.server.CustomerService2"
> scope="prototype"/>
>   <bean id="customerBean3" class="demo.jaxrs.server.CustomerService3"
> scope="prototype"/>
> *
>   <bean id="sfactory1"
> class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
>      <property name="beanName" value="customerBean4"/>
>   </bean>
>   <bean id="sfactory2"
> class="org.apache.cxf.jaxrs.spring.SpringResourceFactory">
>      <property name="beanName" value="customerBean5"/>
>   </bean>
>
>   <bean id="customerBean4" class="demo.jaxrs.server.CustomerService4"
> scope="prototype"/>
>   <bean id="customerBean5" class="demo.jaxrs.server.CustomerService5"
> scope="prototype"/>
> </beans>
>
>
>
> On Thu, Jun 17, 2010 at 7:53 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
>
>> Hi
>>
>> JAXRS module also ships prototypes aware factories :
>> http://cxf.apache.org/docs/jax-rs.html#JAX-RS-Lifecyclemanagement
>>
>> cheers, Sergey
>>
>>
>> On Thu, Jun 17, 2010 at 2:57 PM, Daniel Kulp <dk...@apache.org> wrote:
>>
>>>
>>>
>>> I believe the easiest way to do it is to just use the Spring AOP stuff
>>> and set
>>> the bookService bean to be scope=session.  Spring will handle the rest.
>>>
>>> Dan
>>>
>>>
>>> On Thursday 17 June 2010 6:19:21 am Balaji Sankar Chopparapu wrote:
>>> > Hi,
>>> >
>>> >
>>> >
>>> > We Observed Servicebeans created by
>>> > "org.apache.cxf.transport.servlet.CXFServlet” is always singleton. How
>>> can
>>> > I change their scope to prototype or in best case HTTP Session Scope?
>>> > Please Suggest.
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > *WEB.xml:*
>>> >
>>> >         <servlet>
>>> >
>>> >                <servlet-name>CXFServlet</servlet-name>
>>> >
>>> >                <display-name>CXF Servlet</display-name>
>>> >
>>> >                <servlet-class>
>>> >
>>> >                        org.apache.cxf.transport.servlet.CXFServlet
>>> >
>>> >                </servlet-class>
>>> >
>>> >                <load-on-startup>1</load-on-startup>
>>> >
>>> >         </servlet>
>>> >
>>> > *Bean Definitions:*
>>> >
>>> > <jaxrs:server id="restServer" address="/services/">
>>> >
>>> >
>>> >
>>> >         <jaxrs:serviceBeans>
>>> >
>>> >             <ref bean="bookService"/>
>>> >
>>> > </jaxrs:serviceBeans>
>>> >
>>> >
>>> > Thanks in Advance,
>>> >
>>> > Balaji
>>>
>>> --
>>> Daniel Kulp
>>> dkulp@apache.org
>>> http://dankulp.com/blog
>>>
>>
>>
>