Created
May 30, 2011 15:25
-
-
Save valotas/999051 to your computer and use it in GitHub Desktop.
Grizzly 2 with guice 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.servlet.ServletContextEvent; | |
import org.glassfish.grizzly.servlet.ServletHandler; | |
import com.google.inject.servlet.GuiceFilter; | |
import com.google.inject.servlet.GuiceServletContextListener; | |
public class GuiceHandler extends ServletHandler { | |
private static final Logger logger = Logger.getLogger(GuiceHandler.class.getName()); | |
private final GuiceServletContextListener guiceServletContextListener; | |
public GuiceHandler(GuiceServletContextListener guiceServletContextListener) { | |
this.guiceServletContextListener = guiceServletContextListener; | |
addFilter(new GuiceFilter(), "guiceFilter", null); | |
} | |
@Override | |
public void start() { | |
if (logger.isLoggable(Level.INFO)) logger.log(Level.INFO, String.format("Starting %s", GuiceHandler.class.getSimpleName())); | |
guiceServletContextListener.contextInitialized(new ServletContextEvent(getServletCtx())); | |
super.start(); | |
} | |
@Override | |
public void destroy() { | |
super.destroy(); | |
guiceServletContextListener.contextDestroyed(new ServletContextEvent(getServletCtx())); | |
if (logger.isLoggable(Level.INFO)) logger.log(Level.INFO, String.format("Destroyed %s", GuiceHandler.class.getSimpleName())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import org.glassfish.grizzly.http.server.HttpServer; | |
import org.glassfish.grizzly.servlet.ServletHandler; | |
public class WebServer { | |
public static void main(String[] args) { | |
HttpServer server = HttpServer.createSimpleServer(); | |
ServletHandler handler = new GuiceHandler(new Live24WebApp()); | |
server.getServerConfiguration().addHttpHandler(handler, "/*"); | |
try { | |
server.start(); | |
System.in.read(); | |
server.stop(); | |
} | |
catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment