Over a million developers have joined DZone.

Using Google Guice with Atmosphere

· Java Zone

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

Starting with Atmosphere 0.5, you can now use Google Guice to configure Atmosphere. Google Guice support is enabled by referencing the Guice filter GuiceFilter and an application specific ServletContextListener that extends from GuiceServletContextListener in the web.xml. For example, the web.xml may be as follows:

   <web-app>
<listener>
<listener-class>org.atmosphere.samples.guice.GuiceChatModule</listener-class>
</listener>
<filter>

<filter-name>Guice Filter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>

<filter-name>Guice Filter</filter-name>

<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

and the application specific servlet context listener may be as follows:

public class GuiceChatConfig extends GuiceServletContextListener {

@Override
protected Injector getInjector() {
return Guice.createInjector(new GuiceChatModule());
}
}

with

public class GuiceChatModule  extends ServletModule{

@Override
protected void configureServlets(){
Map params = new HashMap();
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "org.atmosphere.samples.guice");
serve("/chat*").with(AtmosphereGuiceServlet.class, params);
}
}

That's it. You can download the previously Atmosphere-Jersey sample, this time Guice enabled from here. For any questions or to download Atmosphere, go to our main site and use our Nabble forum (no subscription needed) or follow us on Twitter and tweet your questions there!

From http://weblogs.java.net/blog/jfarcand

Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}