users@jersey.java.net

[Jersey] How to bind object as RequestScoped?

From: Roger Nordquist <roger.nordquist_at_valtech.se>
Date: Thu, 14 Aug 2014 09:53:39 +0000

Hi,

My question is regarding hk2/jersey2 bindings request scoped, is it possible?

In my project we need to have an instance created by a factory only created once per request.
It only contains data taken from the HttpRequest but we want our own class which maps our model better.

Can we bind this via hk2 bindings as org.glassfish.jersey.process.internal.RequestScoped ?
My initial tests looks ok but the todo comment in the annotation class file and the fact that it resides inside the internal package makes me worry a bit if it is stable?

/**
 * Request scope binding annotation.
 *
 * TODO find a way how to bind the scope annotation to the request scope instance.
 *
 * @author Marek Potociar (marek.potociar at oracle.com)
 */
@Target({TYPE, METHOD})
@Retention(RUNTIME)
@Scope
public @interface RequestScoped {
}

Thx for any help!

/Roger