Discussion:
@Context field injection timing
m***@public.gmane.org
2012-01-20 18:35:19 UTC
Permalink
At what point in the object's lifecycle is field level Context
injection done?

I've run a simple experiment and can get @Context UriInfo injected on
the constructor and a setter bean but can't seem to get a @Context
annotated field set.

TIA.
John Yeary
2012-01-22 02:36:39 UTC
Permalink
I am not sure of the lifecycle point, but I am curious which @Context
object are you trying to inject at a field level.

There are five default context objects: UriInfo, Request, HttpHeaders,
SecurityContext, and Providers.

John
____________________________

John Yeary
____________________________

<http://javaevangelist.blogspot.com/> <https://twitter.com/jyeary>
<http://www.youtube.com/johnyeary>
<http://www.linkedin.com/in/jyeary>
<https://plus.google.com/112146428878473069965>
<http://www.facebook.com/jyeary>
<http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
<http://netbeans.org/people/84414-jyeary>
____________________________

"Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to take rank with those poor spirits who
neither enjoy much nor suffer much, because they live in the gray twilight
that knows not victory nor defeat."
-- Theodore Roosevelt
Post by m***@public.gmane.org
At what point in the object's lifecycle is field level Context
injection done?
annotated field set.
TIA.
Mike Summers
2012-01-22 04:04:55 UTC
Permalink
UriInfo, I haven't played with the others.

--Mike
Post by John Yeary
object are you trying to inject at a field level.
There are five default context objects: UriInfo, Request, HttpHeaders,
SecurityContext, and Providers.
John
____________________________
John Yeary
____________________________
<http://javaevangelist.blogspot.com/> <https://twitter.com/jyeary> <http://www.youtube.com/johnyeary>
<http://www.linkedin.com/in/jyeary> <https://plus.google.com/112146428878473069965>
<http://www.facebook.com/jyeary> <http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
<http://netbeans.org/people/84414-jyeary>
____________________________
"Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to take rank with those poor spirits who
neither enjoy much nor suffer much, because they live in the gray twilight
that knows not victory nor defeat."
-- Theodore Roosevelt
Post by m***@public.gmane.org
At what point in the object's lifecycle is field level Context
injection done?
annotated field set.
TIA.
John Yeary
2012-01-22 10:49:23 UTC
Permalink
What version of Jersey are you using? That is the one I use most often, and I usually set it on the field level. Rarely do I set it in the constructor, and I have never set it on the setter.

@Context
UriInfo uriInfo;

Right?

John

Sent from my iPhone
Post by Mike Summers
UriInfo, I haven't played with the others.
--Mike
There are five default context objects: UriInfo, Request, HttpHeaders, SecurityContext, and Providers.
John
____________________________
John Yeary
____________________________
____________________________
"Far better it is to dare mighty things, to win glorious triumphs, even though checkered by failure, than to take rank with those poor spirits who neither enjoy much nor suffer much, because they live in the gray twilight that knows not victory nor defeat."
-- Theodore Roosevelt
At what point in the object's lifecycle is field level Context
injection done?
annotated field set.
TIA.
Mike Summers
2012-01-23 15:21:51 UTC
Permalink
Jersey 1.3

I had a bug in my test case, looks like the execution order for @Context
UriInfo is:
1) Constructor (makes sense)
2) Field
3) Bean/Setter
Post by John Yeary
What version of Jersey are you using? That is the one I use most often,
and I usually set it on the field level. Rarely do I set it in the
constructor, and I have never set it on the setter.
@Context
UriInfo uriInfo;
Right?
John
Sent from my iPhone
UriInfo, I haven't played with the others.
--Mike
Post by John Yeary
object are you trying to inject at a field level.
There are five default context objects: UriInfo, Request, HttpHeaders,
SecurityContext, and Providers.
John
____________________________
John Yeary
____________________________
<http://javaevangelist.blogspot.com/> <https://twitter.com/jyeary> <http://www.youtube.com/johnyeary>
<http://www.linkedin.com/in/jyeary> <https://plus.google.com/112146428878473069965>
<http://www.facebook.com/jyeary> <http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
<http://netbeans.org/people/84414-jyeary>
____________________________
"Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to take rank with those poor spirits who
neither enjoy much nor suffer much, because they live in the gray twilight
that knows not victory nor defeat."
-- Theodore Roosevelt
Post by m***@public.gmane.org
At what point in the object's lifecycle is field level Context
injection done?
annotated field set.
TIA.
Loading...