Advertisement
tpeierls

com.example.server.MainServletModule

Jan 23rd, 2012
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.26 KB | None | 0 0
  1. /*
  2.  * This code is placed in the public domain by its author, Tim Peierls.
  3.  */
  4. package com.example.server;
  5.  
  6. import com.google.common.collect.ImmutableMap;
  7.  
  8. import com.google.inject.servlet.ServletModule;
  9.  
  10.  
  11. /**
  12.  * Configure the main servlet to use MainComponent and to handle
  13.  * context path correctly.
  14.  * <p>
  15.  * We make ServerServlet believe we are supplying the component via
  16.  * init-param instead of by overriding it. If we don't do this,
  17.  * ServerServlet won't know which "mode" we're running in.
  18.  * See Restlet's ServerServlet javadocs for more info.
  19.  * </p><p>
  20.  * We set autoWire true to ensure that the servlet context path is
  21.  * included. This means that in, for example, a foobar.war
  22.  * file deployed at context path /foobar, the /foobar
  23.  * part of the URI will be consumed by the time the Restlet Component
  24.  * is handling the request. Without this setting, we'd have to deal
  25.  * with a /foobar prefix to every request.
  26.  * </p>
  27.  */
  28. public class MainServletModule extends ServletModule {
  29.     @Override protected void configureServlets() {
  30.         serve("/*").with(MainServlet.class, ImmutableMap.<String, String>of(
  31.             "org.restlet.component", MainComponent.class.getName(),
  32.             "org.restlet.autoWire",  "true"
  33.         ));
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement