Resource injection fails for an AOP scoped proxy bean

View: New views
8 Messages — Rating Filter:   Alert me  

Resource injection fails for an AOP scoped proxy bean

by CFX Novice :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have this piece of code in my applicationContext.xml

    <jaxrs:server id="xyzserver" address="/xyzservice/">
    <jaxrs:serviceBeans>
      <ref bean="xyzservice" />
    </jaxrs:serviceBeans>
  </jaxrs:server>

  <bean id="xyzservice" class="com.xyz.xyzService" scope="session">
          <aop:scoped-proxy/>
  </bean>

Somehow resource injection stopped working as soon as I started using <aop:scoped-proxy/> I need to access the HttpServletRequest object in my service class. Any help would be greatly appreciated

Re: Resource injection fails for an AOP scoped proxy bean

by Glen Mazza :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can't answer your question, -->CXF<-- Novice, but do please spell your name correctly...   ;-)

CFX Novice wrote:
Hi,

I have this piece of code in my applicationContext.xml

    <jaxrs:server id="xyzserver" address="/xyzservice/">
    <jaxrs:serviceBeans>
      <ref bean="xyzservice" />
    </jaxrs:serviceBeans>
  </jaxrs:server>

  <bean id="xyzservice" class="com.xyz.xyzService" scope="session">
          <aop:scoped-proxy/>
  </bean>

Somehow resource injection stopped working as soon as I started using <aop:scoped-proxy/> I need to access the HttpServletRequest object in my service class. Any help would be greatly appreciated

Re: Resource injection fails for an AOP scoped proxy bean

by ianroberts :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

CFX Novice wrote:

> Hi,
>
> I have this piece of code in my applicationContext.xml
>
>     <jaxrs:server id="xyzserver" address="/xyzservice/">
>     <jaxrs:serviceBeans>
>       <ref bean="xyzservice" />
>     </jaxrs:serviceBeans>
>   </jaxrs:server>
>
>   <bean id="xyzservice" class="com.xyz.xyzService" scope="session">
>           <aop:scoped-proxy/>
>   </bean>
>
> Somehow resource injection stopped working as soon as I started using
> <aop:scoped-proxy/> I need to access the HttpServletRequest object in my
> service class. Any help would be greatly appreciated

Rather than session-scoping the service bean, an alternative would be to
move the data that needs to be scoped at the session level out into
another class and keep your service bean singleton, i.e.:

<bean id="serviceSessionData" class="com.xyz.xyzSessionState"
scope="session">
   <aop:scoped-proxy/>
</bean>

<bean id="xyzservice" class="com.xyz.xyzService">
   <property name="sessionData" ref="serviceSessionData" />
</bean>

Ian

--
Ian Roberts               | Department of Computer Science
i.roberts@...  | University of Sheffield, UK

Re: Resource injection fails for an AOP scoped proxy bean

by CFX Novice :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Even then, I would need access to HttpServletRequest in xyzSessionState which is now an aop-scoped proxy bean and again resource injection would not work, isnt it?

ianroberts wrote:
CFX Novice wrote:
> Hi,
>
> I have this piece of code in my applicationContext.xml
>
>     <jaxrs:server id="xyzserver" address="/xyzservice/">
>     <jaxrs:serviceBeans>
>       <ref bean="xyzservice" />
>     </jaxrs:serviceBeans>
>   </jaxrs:server>
>
>   <bean id="xyzservice" class="com.xyz.xyzService" scope="session">
>           <aop:scoped-proxy/>
>   </bean>
>
> Somehow resource injection stopped working as soon as I started using
> <aop:scoped-proxy/> I need to access the HttpServletRequest object in my
> service class. Any help would be greatly appreciated

Rather than session-scoping the service bean, an alternative would be to
move the data that needs to be scoped at the session level out into
another class and keep your service bean singleton, i.e.:

<bean id="serviceSessionData" class="com.xyz.xyzSessionState"
scope="session">
   <aop:scoped-proxy/>
</bean>

<bean id="xyzservice" class="com.xyz.xyzService">
   <property name="sessionData" ref="serviceSessionData" />
</bean>

Ian

--
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK

Re: Resource injection fails for an AOP scoped proxy bean

by ianroberts :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

CFX Novice wrote:
> Even then, I would need access to HttpServletRequest in xyzSessionState which
> is now an aop-scoped proxy bean and again resource injection would not work,
> isnt it?

I guess you could inject the HttpServletRequest in the usual way into
your singleton-scoped service bean, then pass it as a parameter to the
methods of xyzSessionState?  Somewhat ugly, I admit...

Ian

--
Ian Roberts               | Department of Computer Science
i.roberts@...  | University of Sheffield, UK

Re: Resource injection fails for an AOP scoped proxy bean

by Sergey Beryozkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can you explain please what is it exactly that you're trying to achieve with a JAX-RS root resource class by
applying <aop:scoped-proxy/> to it ?
And again, why what Ian suggested below is not working for you ?

You said you needed a reference to an HttpServletRequest in your resource class ? If yes, then you can get it using just JAX-RS
techniques...

Sorry, I just don't understand all these Spring black-art tricks, so please be patient :-)

Cheers, Sergey

>
> Even then, I would need access to HttpServletRequest in xyzSessionState which
> is now an aop-scoped proxy bean and again resource injection would not work,
> isnt it?
>
>
> ianroberts wrote:
>>
>> CFX Novice wrote:
>>> Hi,
>>>
>>> I have this piece of code in my applicationContext.xml
>>>
>>>     <jaxrs:server id="xyzserver" address="/xyzservice/">
>>>     <jaxrs:serviceBeans>
>>>       <ref bean="xyzservice" />
>>>     </jaxrs:serviceBeans>
>>>   </jaxrs:server>
>>>
>>>   <bean id="xyzservice" class="com.xyz.xyzService" scope="session">
>>>           <aop:scoped-proxy/>
>>>   </bean>

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: Resource injection fails for an AOP scoped proxy bean

by CFX Novice :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ian/Sergey,

Ultimately I had to do what Ian suggested. I was kind of avoiding that because making the service bean session scoped would be neat. Here's the deal. I had to do some pagination in my service bean and thats why I was trying to make it session scoped(by adding aop:scoped-proxy tag) so that pagination would work properly for different users. Yesterday I read somewhere that Spring's resource injection may override Apache CXF's resource injection sometimes, which I think was happening in my case. So ultimately I placed the session-sensitive info (i.e. the object holding the results being paginated, along with the pagination info) into the session.  I did not use a separate class xyzSessionState to store the session state. So this way having a singleton service bean did not cause any problem. Although I wish I could somehow make the aop:scoped-proxy work with Spring 2.0 and Apache CXF.

Thanks everybody for your help.


Sergey Beryozkin wrote:
Can you explain please what is it exactly that you're trying to achieve with a JAX-RS root resource class by
applying <aop:scoped-proxy/> to it ?
And again, why what Ian suggested below is not working for you ?

You said you needed a reference to an HttpServletRequest in your resource class ? If yes, then you can get it using just JAX-RS
techniques...

Sorry, I just don't understand all these Spring black-art tricks, so please be patient :-)

Cheers, Sergey

>
> Even then, I would need access to HttpServletRequest in xyzSessionState which
> is now an aop-scoped proxy bean and again resource injection would not work,
> isnt it?
>
>
> ianroberts wrote:
>>
>> CFX Novice wrote:
>>> Hi,
>>>
>>> I have this piece of code in my applicationContext.xml
>>>
>>>     <jaxrs:server id="xyzserver" address="/xyzservice/">
>>>     <jaxrs:serviceBeans>
>>>       <ref bean="xyzservice" />
>>>     </jaxrs:serviceBeans>
>>>   </jaxrs:server>
>>>
>>>   <bean id="xyzservice" class="com.xyz.xyzService" scope="session">
>>>           <aop:scoped-proxy/>
>>>   </bean>

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: Resource injection fails for an AOP scoped proxy bean

by Sergey Beryozkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

I'm wondering, can JAX-RS itself help you, such that you don't rely on other technologies to help you with managing the state, etc ?
Ex., JAX-RS lets you access Cookies and create new ones explicitly from the application code and easily set them on a response
(provided you rely on cookies for the session management).
Arguably, it would be more complicated though - but it would likely give you more control ovet the cookies management...
Cheers, Sergey

>
> Hi Ian/Sergey,
>
> Ultimately I had to do what Ian suggested. I was kind of avoiding that
> because making the service bean session scoped would be neat. Here's the
> deal. I had to do some pagination in my service bean and thats why I was
> trying to make it session scoped(by adding aop:scoped-proxy tag) so that
> pagination would work properly for different users. Yesterday I read
> somewhere that Spring's resource injection may override Apache CXF's
> resource injection sometimes, which I think was happening in my case. So
> ultimately I placed the session-sensitive info (i.e. the object holding the
> results being paginated, along with the pagination info) into the session.
> I did not use a separate class xyzSessionState to store the session state.
> So this way having a singleton service bean did not cause any problem.
> Although I wish I could somehow make the aop:scoped-proxy work with Spring
> 2.0 and Apache CXF.
>
> Thanks everybody for your help.
>

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
LightInTheBox - Buy quality products at wholesale price