Skip to main content

[jsr339-experts] Re: [Resteasy-users] ContextResolver issue

  • From: Sergey Beryozkin <sberyozkin@...>
  • To: <jsr339-experts@...>
  • Cc: Bill Burke <bburke@...>
  • Subject: [jsr339-experts] Re: [Resteasy-users] ContextResolver issue
  • Date: Thu, 30 Aug 2012 23:33:57 +0200

Hi Bill
On 30/08/12 23:21, Bill Burke wrote:
Here's an example of a user trying to use ContextResolver to inject a
dependency and realizing that CDI provides a much better solution.

I agree with Marek that CDI is not the only solution that users may want to try; I see that Duncan is more concerned about meeting EE programming model/etc as opposed to trying to write a more neutral code, which is what JAX-RS can and should offer; (still not happy about ResourceContext, but...)

Sergey

On 8/30/2012 3:13 PM, Duncan Bloem wrote:
Thank you.

Although the @Context Providers solution does work, I have chosen the
CDI path to comply more to EE programming model.

Regards,
Duncan

On Thu, Aug 30, 2012 at 4:58 PM, Bill Burke <bburke@...
<mailto:bburke@...>> wrote:

Its sort of a bug.

ContextResolver wasn't supposed to be used in the way your example was
written, it really was supposed to be used in conjunction with the
Providers interface:

@Context
protected Providers providers;


public JAXBContext findProvidedJAXBContext(Class<?> type, MediaType
mediaType)
throws JAXBException
{
JAXBContext jaxb = null;
ContextResolver<JAXBContext> resolver =
providers.getContextResolver(JAXBContext.class, mediaType);
if (resolver != null)
{
jaxb = resolver.getContext(type);
if (jaxb != null) return jaxb;
}
return jaxb;
}

The above is taken from our MessageBodyReader/Writer support for JAXB.
It allows people to personally configure JAXB for a specific media type
and for a specific java type.

IMO, you should be using it in this way, or instead, use CDI, Spring,
Guice, EJB or whatever for your dependenncy injection.


On 8/30/2012 6:28 AM, Duncan Bloem wrote:
> Hi,
>
> I have made a very simple pure JAX-RS demo application.
> You can find it here: https://github.com/dabloem/jaxrs
>
> When deployed to JBoss As 7.1.0, the application does not inject
> MyResolver into field @Context ContextResolver<MyObject> within
> GenericResource. It is always null.
>
> When deployed to GF3.1.2, injections works fine.
>
> It looks like I am missing something to register the
ContextResolver in
> RestEasy, but I could not find any documentation or example.
>
> Any suggestions are welcome, thanks.
>
> Duncan
>
>
>
>
>
------------------------------------------------------------------------------

> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.
Discussions
> will include endpoint security, mobile security and the latest in
malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>
>
>
> _______________________________________________
> Resteasy-users mailing list
> Resteasy-users@...
<mailto:Resteasy-users@...>
https://lists.sourceforge.net/lists/listinfo/resteasy-users
>

--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com

------------------------------------------------------------------------------

Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond.
Discussions
will include endpoint security, mobile security and the latest in
malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Resteasy-users mailing list
Resteasy-users@...
<mailto:Resteasy-users@...>
https://lists.sourceforge.net/lists/listinfo/resteasy-users




------------------------------------------------------------------------------

Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/



_______________________________________________
Resteasy-users mailing list
Resteasy-users@...
https://lists.sourceforge.net/lists/listinfo/resteasy-users






[jsr339-experts] Re: [Resteasy-users] ContextResolver issue

Bill Burke 08/30/2012

[jsr339-experts] Re: [Resteasy-users] ContextResolver issue

Sergey Beryozkin 08/30/2012
 
 
Close
loading
Please Confirm
Close