You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by Srivatsan Sridharan <sa...@gmail.com> on 2010/01/07 09:04:44 UTC

Re: Context injection using @Resource in the resource class

There is a request handler that sets an attribute say
context.setAttribute(Map.class, obj) in the message context. For a
particular request, the resource method throws a runtime exception for which
there is an exception mapping provider. 

Is there any restriction in accessing the attribute set in the
MessageContext in the exception mapper using @Context Map obj because the
inspection of the obj shows it as a $Proxy and not the actual class that was
set. Further, any operation on the obj results in a NullPointerException.

Bottom line is the user defined attribute set in the context should be
accessible in the exception mapper. Any thoughts on how this should be done?


Michael Elman-2 wrote:
> 
> I'm not familiar with @Resource annotation. Did you mean @Context?
> 
> The attribute from the MessageContext can be received using the @Context
> annotation.
> For example
> 
>        context.setAttribute(RuntimeContext.class, context)
> 
> in the handler will set the message context itself, therefore it can be
> retrieved in the resource using
> 
> @Context RuntimeContext runtimeContext
> 
> Note that context class must be interface, since it might be injected into
> singletons.
> 
> On Tue, Nov 17, 2009 at 1:38 PM, Srivatsan Sridharan <
> sathishsrivatsan@gmail.com> wrote:
> 
>>
>> Hi,
>>
>> We are working on restful service development that has a request handler
>> and
>> a resource class. Request handler sets an attribute on the
>> MessageContext.
>> To my knowledge, the set attribute could be accessed in the resource
>> class
>> if the entire context could be injected using @Resource annotation.
>>
>> 1) Is this the right way of doing it as I dont see a support for resource
>> injection in the resource classes?
>> 2) If there is an alternate way to get a handle to the context in the
>> resource class, please let me know.
>>
>> Thanks,
>> Srivatsan
>> --
>> View this message in context:
>> http://n2.nabble.com/Context-injection-using-Resource-in-the-resource-class-tp4018056p4018056.html
>> Sent from the Apache Wink Users mailing list archive at Nabble.com.
>>
> 
> 

-- 
View this message in context: http://n2.nabble.com/Context-injection-using-Resource-in-the-resource-class-tp4018056p4265333.html
Sent from the Apache Wink Users mailing list archive at Nabble.com.

Re: Context injection using @Resource in the resource class

Posted by Bryant Luk <br...@gmail.com>.
Hi,

Is it possible for you to throw an exception with the attribute?  For
instance, catch the exception in your resource method and set the
attribute you want as a property of a new exception subclass.  Then in
the ExceptionMapper, you can access the attribute.

On Thu, Jan 7, 2010 at 2:04 AM, Srivatsan Sridharan
<sa...@gmail.com> wrote:
>
> There is a request handler that sets an attribute say
> context.setAttribute(Map.class, obj) in the message context. For a
> particular request, the resource method throws a runtime exception for which
> there is an exception mapping provider.
>
> Is there any restriction in accessing the attribute set in the
> MessageContext in the exception mapper using @Context Map obj because the
> inspection of the obj shows it as a $Proxy and not the actual class that was
> set. Further, any operation on the obj results in a NullPointerException.
>
> Bottom line is the user defined attribute set in the context should be
> accessible in the exception mapper. Any thoughts on how this should be done?
>
>
> Michael Elman-2 wrote:
>>
>> I'm not familiar with @Resource annotation. Did you mean @Context?
>>
>> The attribute from the MessageContext can be received using the @Context
>> annotation.
>> For example
>>
>>        context.setAttribute(RuntimeContext.class, context)
>>
>> in the handler will set the message context itself, therefore it can be
>> retrieved in the resource using
>>
>> @Context RuntimeContext runtimeContext
>>
>> Note that context class must be interface, since it might be injected into
>> singletons.
>>
>> On Tue, Nov 17, 2009 at 1:38 PM, Srivatsan Sridharan <
>> sathishsrivatsan@gmail.com> wrote:
>>
>>>
>>> Hi,
>>>
>>> We are working on restful service development that has a request handler
>>> and
>>> a resource class. Request handler sets an attribute on the
>>> MessageContext.
>>> To my knowledge, the set attribute could be accessed in the resource
>>> class
>>> if the entire context could be injected using @Resource annotation.
>>>
>>> 1) Is this the right way of doing it as I dont see a support for resource
>>> injection in the resource classes?
>>> 2) If there is an alternate way to get a handle to the context in the
>>> resource class, please let me know.
>>>
>>> Thanks,
>>> Srivatsan
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/Context-injection-using-Resource-in-the-resource-class-tp4018056p4018056.html
>>> Sent from the Apache Wink Users mailing list archive at Nabble.com.
>>>
>>
>>
>
> --
> View this message in context: http://n2.nabble.com/Context-injection-using-Resource-in-the-resource-class-tp4018056p4265333.html
> Sent from the Apache Wink Users mailing list archive at Nabble.com.
>