users@jersey.java.net

RE: [Jersey] Custom Context type is not injected?

From: Roytman, Alex <Roytmana_at_peacetech.com>
Date: Tue, 17 Feb 2009 12:26:16 -0500

Hello Paul,

Thank you for the tip

I do use InjectableProvider for JDO injection for per-request lifecycle (it also subscribe its injections to cleanup service automatically). I hoped to use @Context for cleanup service to avoid an additional annotation for it. The cleanup service is the service we talked about with regard of guaranteed "closeable" closure at the end of lifecycle. I wanted it as transparent and non-intrusive as possible so you could consider it for addition to jersey and did not want extra annotations.

I would appreciate your advise on how to proceed with CleanupService integration with Jersey. If you would like me to use InjectableProvider for CleanupService resolution, which annotation would you like me to use?

BTW Are there any samples on Resources with Session lifecycle and on communication from request level resources to session level one? I could not find any prescribed ways of doing it in the specs.

Thanks again,

Alex





-----Original Message-----
From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Tuesday, February 17, 2009 5:36 AM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] Custom Context type is not injected?

Hi Alex,

You need to declare the generic type:

  private ContextResolver<CleanupService> cleanupService;

  public PositionRecord(@Context ContextResolver<CleanupService>
cleanupService) {
    this.cleanupService = cleanupService;
  }

ContextResolver is not a way to provide generic injection support as
is the case with InjectableProvider. It is designed to provide some
contextual object for a given Java type e.g. for a JAXB type return a
JAXB context.

Instead it is better to define an InjectableProvider for the
CleanupService and then you can support what you require.

I can write some example code to help you in this respect. I could
even write some injectable provider code for the injection of JDO
objects on singleton and per-request resources.

Paul.

On Feb 17, 2009, at 6:03 AM, Roytman, Alex wrote:

> Hello Paul,
>
> I created a custom service which I want to inject using @Context
> annotation. It gets loaded and registered fine.
>
> I can get it using
> @Context Providers providers;
> providers.getContextResolver(CleanupService.class, null);
>
> but any field or constructor parameter defined as @Context
> CleanupService cleanupService in Resource or another Provider is not
> injected. My resolver's getContext() method is never called.
>
>
> I will try to debug it but if you could give me some hints or if you
> think it is a bug, I would appreciate
>
> Thank you,
> Alex
>
>
> @Path("position")
> public class PositionRecord extends JdoResource {
> private CleanupService cleanupService;
>
> public PositionRecord(@Context CleanupService cleanupService) {
> this.cleanupService = cleanupService;
> }
>
> ....
>
>
> Context resolver is attached
>
>
> <
> CleanupServiceContextResolver
> .java
> >---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: users-help_at_jersey.dev.java.net