guice-servlet

Is there a way to check if I'm inside a servlet request with Guice?

回眸只為那壹抹淺笑 提交于 2020-01-05 03:32:14
问题 I'm writing a JUL logging Handler and I'd like to augment the logged messages with information about the current request, if we're currently handling a request. To accomplish this, I've injected a Provider<Thing> into the Handler , where Thing is @RequestScoped . However, calling provider.get() throws an OutOfScopeException if the logging happens while we're not handling a request. I feel like catching the OutOfScopeException would be bad form. Is there a better way to determine whether or

Guice + Tomcat potential memory leak

我的未来我决定 提交于 2019-12-29 06:44:09
问题 I have just started using Google Guice with my Tomcat webapp, and have noticed the following in the catalina.out file whenever the WAR file is undeployed: May 16, 2011 5:37:24 PM org.apache.catalina.startup.HostConfig checkResources INFO: Undeploying context [/app] May 16, 2011 5:37:24 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: A web application appears to have started a thread named [com.google.inject.internal.util.$Finalizer] but has failed to stop it.

Install custom Jersey ViewProcessor from Guice ServletModule

倖福魔咒の 提交于 2019-12-25 03:05:27
问题 I am using jersey-guice to set up all my Jersey 1 resources using a bunch of Guice (Servlet)Modules. I have written a custom ViewProcessor ( CustomViewProcessor ) that relies on a configuration object, that I want to be injected into it using Guice. This CustomViewProcessor should be picked up and used by Jersey every time it needs one. How do I tell Jersey to fetch a Guice-created CustomViewProcessor instance whenever it needs a ViewProcessor ? I want to set all this up within my Guice

Injecting dependencies to ServletContextListener with Guice

喜欢而已 提交于 2019-12-22 05:58:52
问题 Since ServletContextListener is created by the server, not by Guice I can't find a way to make it work together. How do I get guice injector at ServletContextListener? Maybe there is better way to shutdown services like logger or persistance then doing it at contextDestroyed method and initialize them at contextInitialized? 回答1: The extension GuiceServlet puts the injector in the servlet context, so you can get it by doing something like this: public class MyServletContextListener implements

How to use guice-servlet with Jersey 2.0?

白昼怎懂夜的黑 提交于 2019-12-20 10:33:27
问题 Is there any sample code demonstrating how to use guice-servlet with Jersey 2.0? 回答1: https://github.com/Squarespace/jersey2-guice seems to be the first genuine Guice integration for Jersey 2 but it requires version 2.11+. NOTE : I haven't tested this, but the idea is sound. 回答2: Yes, I've adapted an example and it's available here - https://github.com/piersy/jersey2-guice-example-with-test I've updated the example code now, its got a test using jetty and another using tomcat. 回答3: There is a

Inject @SessionScoped value into filter with Guice

ぃ、小莉子 提交于 2019-12-13 03:43:11
问题 I have a class hold value of a user in session @SessionScoped class UserSession{} Now I have a LoginFilter to ensure some url accessed with user login class LoginFilter{ @Inject UserSession userSession; ... } Then Out of scope exception was thrown when I try to bootstrap jetty. How can I check if the session contains the UserSession object? I don't know the attribute name of UserSession class. 回答1: You can inject a Provider<UserSession> instead of a plain UserSession . 来源: https:/

When using the guice servlet extension is it possible to react to servlet destruction?

[亡魂溺海] 提交于 2019-12-07 23:04:10
问题 I need to do some cleanup when guice servlet is removed. Is it possible to hook into the servlet destruction when using a guice servlet? I need to use the Injector to do the cleanup work. I can override the contextDestroyed method in GuiceServletContextListener , but then how do I get access to the injector? Is there a better way to react to servlet destruction? 回答1: I can override the contextDestroyed method in GuiceServletContextListener, but then how do I get access to the injector? You

When using the guice servlet extension is it possible to react to servlet destruction?

南楼画角 提交于 2019-12-06 04:57:30
I need to do some cleanup when guice servlet is removed. Is it possible to hook into the servlet destruction when using a guice servlet? I need to use the Injector to do the cleanup work. I can override the contextDestroyed method in GuiceServletContextListener , but then how do I get access to the injector? Is there a better way to react to servlet destruction? I can override the contextDestroyed method in GuiceServletContextListener, but then how do I get access to the injector? You could do it like this: public class MyGuiceServletConfig extends GuiceServletContextListener { private final

Configuring Apache Shiro with Google Guice Servlet

空扰寡人 提交于 2019-12-04 10:51:09
问题 I'm starting to use Guice/Shiro instead of Spring/Spring Security. I have looked examples from Shiro site, and all configuration examples are made as INI-file examples. Is it possible to configure Shiro in plain Java, as Guice Servlets are meant to be configured? 回答1: Yes it is possible, but requires some glue code if you want Guice to create your Realms. Bind Realm implementation: bind(Realm.class).to(MyRealm.class).in(Singleton.class); Bind WebSecurityManager: @Provides @Singleton

How to use guice-servlet with Jersey 2.0?

你离开我真会死。 提交于 2019-12-02 23:36:08
Is there any sample code demonstrating how to use guice-servlet with Jersey 2.0? https://github.com/Squarespace/jersey2-guice seems to be the first genuine Guice integration for Jersey 2 but it requires version 2.11+. NOTE : I haven't tested this, but the idea is sound. Yes, I've adapted an example and it's available here - https://github.com/piersy/jersey2-guice-example-with-test I've updated the example code now, its got a test using jetty and another using tomcat. Globber There is a page at HK2 official about correct guice implementation: https://javaee.github.io/hk2/guice-bridge.html You