cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: Cannot obtain UriInfo in isWriteable() for custom providers
Date Wed, 30 Nov 2011 10:35:26 GMT
Hi Tao
On 29/11/11 17:45, Lin, Tao wrote:
> Hi Sergey,
>
> Thank you very much for fixing the bug so quickly.
>
> Can you give me a little bit more details (on something like which jars are affected
and which files have been modified)?
>
> We currently use CXF 2.3.3 so we may need to backport the fix to CXF 2.3.3.
>
Please see these revisions:
http://svn.apache.org/viewvc?rev=1207824&view=rev
http://svn.apache.org/viewvc?rev=1207837&view=rev

You might want to experiment with 2.3.8-SNAPSHOT; migrating to CXF 2.3.8 
when it gets released should be safe enough, it's a bug fixes branch so 
no extra dependencies or major changes have been introduced since CXF 2.3.3

Cheers, Sergey

> Thanks,
>
> Tao
>
> -----Original Message-----
> From: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
> Sent: Tuesday, November 29, 2011 3:48 AM
> To: users@cxf.apache.org
> Subject: Re: Cannot obtain UriInfo in isWriteable() for custom providers
>
> Hi Tao
> On 25/11/11 21:53, Lin, Tao wrote:
>> Hi Sergey,
>>
>> Thank you for the quick response. It would be greatly appreciated if you could fix
the problem.
>>
>> There is another minor problem related to this one. The list returned from UriInfo.getMatchedResources()
is not in the correct order according to the JAX-RS spec.
>>
>>   From the Java Doc for UriInfo.getMatchedResources():
>>
>> "Get a read-only list of the currently matched resource class instances. Each entry
is a resource class instance that matched the request URI either directly or via a sub-resource
method or a sub-resource locator. Entries are ordered according to reverse request URI matching
order, with the current resource first."
>>
>> In my testing, the entries are NOT ordered according to reverse request URI matching
order. The current resource is actually at the end.
>>
>
> Both issues have been fixed, thanks for reporting them
>
> Cheers, Sergey
>
>> Thanks,
>>
>> Tao
>>
>> -----Original Message-----
>> From: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
>> Sent: Friday, November 25, 2011 1:20 PM
>> To: users@cxf.apache.org
>> Subject: Re: Cannot obtain UriInfo in isWriteable() for custom providers
>>
>> Hi
>> On 25/11/11 18:21, Lin, Tao wrote:
>>> Hi,
>>>
>>> I would like to write a custom provider, which extends a default provider in
CXF. I would also like to make the custom provider only handles the resources my application
exposes. It should be possible since the requested resource can be obtained through UriInfo
object (UriInfo.getMatchedResources()), which is injected into the provider directly or indirectly
.
>>>
>>> However, UriInfo is only available in writeTo() but not in isWriteable(). Here
is the sample code to demonstrate the problem:
>>>
>>> ~~
>>> @Produces("application/json")
>>> @Consumes("application/json")
>>> @Provider
>>> public class MyJSONProvider extends JSONProvider
>>> {
>>>        @Context MessageContext context;
>>>
>>>        @Override
>>>        public boolean isWriteable(Class<?>    type, Type genericType, Annotation[]
annotations, MediaType mt)
>>>        {
>>>            UriInfo uriInfo = context.getUriInfo();
>>>            List<Object>    resources = uriInfo.getMatchedResources(); //
throw null pointer at this line
>>>
>>>            return Customer.class.isAssignableFrom(type);
>>>        }
>>>
>>>        @Override
>>>        public void writeTo(Object obj, Class<?>    cls, Type genericType,
Annotation[] anns, MediaType m, MultivaluedMap<String, Object>    headers, OutputStream
os)
>>>                throws IOException
>>>        {
>>>            UriInfo uriInfo = context.getUriInfo();
>>>            List<Object>    resources = uriInfo.getMatchedResources();
>>>
>>>            super.writeTo(obj, cls, genericType, anns, m, headers, os);
>>>        }
>>> }
>>> ~~
>>>
>>> In the writeTo() method, uriInfo contains the information I need while in the
isWriteable(), uriInfo is null. But what I really want is the uriInfo available in isWriteable().
>>>
>>> Here is my question:
>>>
>>> is this by design or simply a bug?
>>>
>>> To me, this is a bug.
>>>
>> I'll probably agree; I've been aware of it, the reason I've never done
>> it that all the the injection is kind of not cheap so I thought I'd only
>> get the code injecting contexts only for the chosen provider.
>> I'll investigate a bit more, and get back on this issue
>>
>> Cheers, Sergey
>>
>>
>>> Thanks,
>>>
>>> Tao
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Mime
View raw message