GuiceServletContextListener.INJECTOR_NAME

23 views
Skip to first unread message

Cow_woC

unread,
Jul 22, 2008, 3:23:06 AM7/22/08
to google-guice
Hi,

I'm wondering how one is supposed to look up an Injector from a
servlet context given the fact that
GuiceServletContextListener.INJECTOR_NAME is package-private instead
of public. InjectedHttpServlet.init() invokes:

Injector injector = (Injector)

servletContext.getAttribute(GuiceServletContextListener.INJECTOR_NAME);

but I can't do the same because of the field accessibility. What is
the correct way to get at the Injector?

Secondly, how I am supposed to ensure that EntityManager is closed at
the end of each servlet request? I was going to do this at the end of
HttpServlet.doGet(), doPost() but I'm not sure how those methods are
supposed to look up the request-specific EntityManager instance to be
closed.

Any ideas?

Thank you,
Gili

tzwoenn

unread,
Jul 22, 2008, 5:16:11 AM7/22/08
to google-guice
1. Without knowing the concrete reason for the package private
constant... I believe the injector is supposed rather to be injected
than looked up from the application context.

2. E.g. use a servlet filter to open and close and request scoped
EntityManager (and maybe also begin and commit the corresponding
transaction) like the Spring's OpenSessionInViewFilter does it for
Hibernate sessions.

Dhanji R. Prasanna

unread,
Jul 22, 2008, 5:24:33 AM7/22/08
to google...@googlegroups.com
On Tue, Jul 22, 2008 at 5:23 PM, Cow_woC <gili.t...@gmail.com> wrote:


Secondly, how I am supposed to ensure that EntityManager is closed at
the end of each servlet request? I was going to do this at the end of
HttpServlet.doGet(), doPost() but I'm not sure how those methods are
supposed to look up the request-specific EntityManager instance to be
closed.

Try warp-persist. It takes care of OSIV and transaction semantics for you. =)


Dhanji.

jordi

unread,
Jul 22, 2008, 5:39:52 AM7/22/08
to google...@googlegroups.com
now that you said that.. i didn't success trying to attach warp-persist with struts2 & hibernate.. i tried building manually the hibernate but no luck..

anyways i implemented an struts2 interceptor that makes the same work.

i guess warp-persist can work with struts2 & hibernate.. really?

Dhanji R. Prasanna

unread,
Jul 22, 2008, 5:52:21 AM7/22/08
to google...@googlegroups.com
On Tue, Jul 22, 2008 at 7:39 PM, jordi <jo...@donky.org> wrote:
now that you said that.. i didn't success trying to attach warp-persist with struts2 & hibernate.. i tried building manually the hibernate but no luck..

anyways i implemented an struts2 interceptor that makes the same work.

i guess warp-persist can work with struts2 & hibernate.. really?

Yea there's a bit of a problem because of the struts2 plugin (it's very unfriendly). Robbie has written a Struts2 interceptor for warp-persist which can be found at:


We use this successfully at my work.

Dhanji.

jordi

unread,
Jul 22, 2008, 6:05:36 AM7/22/08
to google...@googlegroups.com
thank you!

i guess it would be nice that you say something about it on warp-persist page, as it not so strange to work with struts2, hibernate and guice alleviating all the pain

Cow_woC

unread,
Jul 22, 2008, 4:13:58 PM7/22/08
to google-guice
Hi Dhanji,

Your website could use some online tutorials. It isn't immediately
clear how to get started with warp-servlet and warp-persist and
whether the two are even meant to be used together (I assume so).

Thanks,
Gili

On Jul 22, 5:24 am, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:

Dhanji R. Prasanna

unread,
Jul 22, 2008, 5:47:08 PM7/22/08
to google...@googlegroups.com
On Wed, Jul 23, 2008 at 6:13 AM, Cow_woC <gili.t...@gmail.com> wrote:

Hi Dhanji,

Your website could use some online tutorials. It isn't immediately
clear how to get started with warp-servlet and warp-persist and
whether the two are even meant to be used together (I assume so).

They can be used independently or together as it says on the docs page for each. They are unrelated as far as functionality goes. Did you check out this guide:


and for JPA:


and various tutorials and example apps:


Can you suggest how we can improve our docs? I am interested in doing so.
Thanks,

Dhanji.

Cow_woC

unread,
Jul 23, 2008, 4:01:50 AM7/23/08
to google-guice
You did a good job with the warp-servlet guide but none of that great
documentation made it back into the Javadoc. It's a pain using the
code without decent code complete + javadoc support. Secondly, you
provided a link to the warp-persist Wiki but it doesn't get mentioned
at all in the online guides (it should be!)

Finally, I found some parts of the API to be a little quirky... For
example, you can invoke Servlets.configure().filters().servlets() but
not Servlets.configure().servlets() directly. Please consider rounding
this edge case ;) Also, please consider documenting what servlets(),
filters() and other methods actually do. The current javadoc is empty.

I know it might sound like I'm being picky here but please appreciate
the fact that a lot of stuff is obvious once you've been using your
own library for months on end. The lack of decent Javadoc is a real
annoyance to new users. It is a real shame because I think you did a
great job with the library design itself :)

Gili

On Jul 22, 5:47 pm, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:

Dhanji R. Prasanna

unread,
Jul 23, 2008, 8:35:27 AM7/23/08
to google...@googlegroups.com
So, would you say that if the javadoc contained information available on the website that would suffice?

Dhanji.

jhulford

unread,
Jul 23, 2008, 9:51:55 AM7/23/08
to google-guice
Yeah, I'm going to second that too. I found myself having to dig
through the code several times to make sure code I was calling in warp-
servlets was doing what I was expecting it to. Having an accurate
javadoc would have helped shave off a fair amount of time I spent
digging through your code. In the grand scheme of things it's a minor
annoyance given the great functionality warp-servlets provides.

Cow_woC

unread,
Jul 23, 2008, 11:02:33 AM7/23/08
to google-guice
Dhanji,

I would say it is a good start, but definitely not sufficient for the
Javadoc. For example, if you took the guide documentation on
FlashScoped and added it into the Javadoc it would sufficient for the
class description in my opinion but the Javadoc would not be complete
until all methods/classes had detailed Javadoc associated with them.
Doesn't IntelliJ bug you to death until you document your code? :)
Netbeans is pretty good about that.

Thanks,
Gili

On Jul 23, 8:35 am, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> So, would you say that if the javadoc contained information available on the
> website that would suffice?
> Dhanji.
>
Reply all
Reply to author
Forward
0 new messages