users@jersey.java.net

Re: [Jersey] Guice / Reference to WebApplication

From: Johannes Schneider <mailings_at_cedarsoft.com>
Date: Wed, 02 Jun 2010 21:16:46 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

And of course that does not work with Stage.PRODUCTION....

Johannes

On 06/02/2010 08:07 PM, Johannes Schneider wrote:
> I used a profiler to find all references to WebApplication. Just found
> one... And with some dirty hacks it resulted in that module configuration:
>
>
> @Singleton
> @Provides
> public WebApplication webApp( @NotNull GuiceContainer guiceContainer ) {
> WebComponent component = Reflection.field( "webComponent"
> ).ofType( WebComponent.class ).in( guiceContainer ).get();
> WebApplication webApplication = Reflection.field( "application"
> ).ofType( WebApplication.class ).in( component ).get();
> return webApplication;
> }
>
> @RequestScoped
> @Provides
> public HttpContext httpContext( @NotNull WebApplication
> webApplication ) {
> return webApplication.getThreadLocalHttpContext();
> }
>
> @RequestScoped
> @Provides
> public UriInfo uriInfo( @NotNull HttpContext httpContext ) {
> return httpContext.getUriInfo();
> }
> @RequestScoped
> @Provides
> public HttpRequestContext requestContext( HttpContext httpContext ) {
> return httpContext.getRequest();
> }
> @RequestScoped
> @Provides
> public HttpHeaders httpHeaders( HttpContext httpContext ) {
> return httpContext.getRequest();
> }
> @RequestScoped
> @Provides
> public Request request( HttpContext httpContext ) {
> return httpContext.getRequest();
> }
> @RequestScoped
> @Provides
> public SecurityContext securityContext( HttpContext httpContext ) {
> return httpContext.getRequest();
> }
>
>
> On 06/02/2010 07:39 PM, Johannes Schneider wrote:
>> At the moment I am struggling with the Guice integration.
>
>> It is working based on that blog entry:
>> http://zcox.wordpress.com/2009/09/22/jersey-guice-scala/
>
>
>> When I mark an constructor of a resources with @com.google.inject.Inject
>> it is injected using Guice.
>> But I also want to add some context stuff (UriInfo) etc.
>
>> Therefore I tried to add some bindings to Guice. But I don't know how I
>> can get the current UriInfo. I have found that code:
>> http://pastie.org/521175
>> But I think that is wrong, since there an additional instance of
>> WebApplicationImpl is created (or am I missing something?).
>
>> So is there any possibility to get the reference to the WebApplication?
>> Any magic/static method?
>
>
>
>> I could extend com.sun.jersey.guice.spi.container.servlet.GuiceContainer
>> and use the instance passed to #initiate. But that looks a little bit
>> dirty because it is too late. Guice has still been created (see the
>> injected Injector to the constructor).
>
>> Any hints?
>
>
>
>> Thanks,
>
>> Johannes
>
> ---------------------------------------------------------------------
> 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


- --
Johannes Schneider - blog.cedarsoft.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBAgAGBQJMBq4eAAoJEAytD9R7Qv6doqcH/04m6G7502VhD/1NB7QU6cXV
0UtXOnmgPd4sxsJSV1zH8xw6QThRnEGdM6rmOrFSp3TkhAmKqAF+Ae1T+gJ3w+8U
MkQCUL1PC2gI2wpAHHkN7y1o8eh+P4V9uOKS+DdJVmxBVlmz0nDpgV9zwRxBi3vn
PwjDrVJAQc/l60LZNzcCg9Ts91A2+Jw2Tilsw31sBBS4UegsGPBsG5s+kdXiyxmx
KUpExXGuWrOfsZ461uXG8fKAaOvWUZAcMLiOHZiYZPf4mJL6RCKeglUtvAMKOOwK
AT2UMnt+FfYe/GQmYTFJBW+9ovYYNTBiqmcNOk85zDFQuRL4acbSPVzmfpDjPaE=
=e3Xr
-----END PGP SIGNATURE-----