Permalink
Browse files

use named collections with constants for catchall servlet, security a…

…nd the handlers.
  • Loading branch information...
1 parent 3f94d1f commit 1e21fe415cc33b1a9f74ecddc05c7d7b911fa487 Henning Schmiedehausen committed May 29, 2012
@@ -15,6 +15,10 @@
*/
package com.nesscomputing.httpserver;
+import static com.nesscomputing.httpserver.HttpServerHandlerBinder.CATCHALL_NAME;
+import static com.nesscomputing.httpserver.HttpServerHandlerBinder.HANDLER_NAME;
+import static com.nesscomputing.httpserver.HttpServerHandlerBinder.SECURITY_NAME;
+
import java.util.EnumSet;
import java.util.Set;
@@ -75,7 +79,7 @@
private Connector externalHttpsConnector = null;
@Inject
- public GalaxyJetty8HttpServer(final HttpServerConfig httpServerConfig, final GalaxyConfig galaxyConfig, final Servlet catchallServlet)
+ public GalaxyJetty8HttpServer(final HttpServerConfig httpServerConfig, final GalaxyConfig galaxyConfig, @Named(CATCHALL_NAME) final Servlet catchallServlet)
{
this.httpServerConfig = httpServerConfig;
this.galaxyConfig = galaxyConfig;
@@ -95,13 +99,13 @@ void setMBeanServer(final MBeanServer mbeanServer)
}
@Inject(optional=true)
- void addHandlers(@Named("_handlers") final Set<Handler> handlers)
+ void addHandlers(@Named(HANDLER_NAME) final Set<Handler> handlers)
{
this.handlers = handlers;
}
@Inject(optional=true)
- void setSecurityHandlers(@Named("_security") final HandlerWrapper securityHandler)
+ void setSecurityHandlers(@Named(SECURITY_NAME) final HandlerWrapper securityHandler)
{
this.securityHandler = securityHandler;
}
@@ -15,6 +15,10 @@
*/
package com.nesscomputing.httpserver;
+import java.lang.annotation.Annotation;
+
+import javax.servlet.Servlet;
+
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.handler.HandlerWrapper;
@@ -29,18 +33,32 @@
*/
public final class HttpServerHandlerBinder
{
+ public static final String HANDLER_NAME = "_handlers";
+ public static final Annotation HANDLER_NAMED = Names.named(HANDLER_NAME);
+
+ public static final String SECURITY_NAME = "_security";
+ public static final Annotation SECURITY_NAMED = Names.named(SECURITY_NAME);
+
+ public static final String CATCHALL_NAME = "_catchall";
+ public static final Annotation CATCHALL_NAMED = Names.named(CATCHALL_NAME);
+
private HttpServerHandlerBinder()
{
}
public static LinkedBindingBuilder<Handler> bindHandler(final Binder binder)
{
- final Multibinder<Handler> handlers = Multibinder.newSetBinder(binder, Handler.class);
+ final Multibinder<Handler> handlers = Multibinder.newSetBinder(binder, Handler.class, HANDLER_NAMED);
return handlers.addBinding();
}
public static LinkedBindingBuilder<HandlerWrapper> bindSecurityHandler(final Binder binder)
{
- return binder.bind(HandlerWrapper.class).annotatedWith(Names.named("_security"));
+ return binder.bind(HandlerWrapper.class).annotatedWith(SECURITY_NAMED);
+ }
+
+ public static LinkedBindingBuilder<Servlet> bindCatchallServlet(final Binder binder)
+ {
+ return binder.bind (Servlet.class).annotatedWith(CATCHALL_NAMED);
}
}
@@ -15,8 +15,6 @@
*/
package com.nesscomputing.httpserver;
-import javax.servlet.Servlet;
-
import com.google.inject.Scopes;
import com.google.inject.name.Names;
import com.google.inject.servlet.GuiceFilter;
@@ -57,7 +55,8 @@ public void configureServlets()
bind (serverClass).asEagerSingleton();
bind (HttpServer.class).to(serverClass).asEagerSingleton();
- bind (Servlet.class).to(InvalidRequestServlet.class).in(Scopes.SINGLETON);
+ HttpServerHandlerBinder.bindCatchallServlet(binder()).to(InvalidRequestServlet.class).in(Scopes.SINGLETON);
+
bind (GuiceFilter.class).in(Scopes.SINGLETON);
}
}
@@ -22,11 +22,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.google.inject.Singleton;
import com.nesscomputing.logging.Log;
/**
* This is the backing servlet for Filter chains if no "default mapping" is configured. It will log any attempts to get Data out of it.
*/
+@Singleton
class InvalidRequestServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;

0 comments on commit 1e21fe4

Please sign in to comment.