use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class DispatcherTest method init.
@Before
public void init() throws Exception {
_server = new Server();
_connector = new LocalConnector(_server);
_connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendServerVersion(false);
_connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendDateHeader(false);
_contextCollection = new ContextHandlerCollection();
_contextHandler = new ServletContextHandler();
_contextHandler.setContextPath("/context");
_contextCollection.addHandler(_contextHandler);
_resourceHandler = new ResourceHandler();
_resourceHandler.setResourceBase(MavenTestingUtils.getTestResourceDir("dispatchResourceTest").getAbsolutePath());
_resourceHandler.setPathInfoOnly(true);
ContextHandler resourceContextHandler = new ContextHandler("/resource");
resourceContextHandler.setHandler(_resourceHandler);
_contextCollection.addHandler(resourceContextHandler);
_server.setHandler(_contextCollection);
_server.addConnector(_connector);
_server.start();
}
use of org.eclipse.jetty.server.handler.ContextHandler in project buck by facebook.
the class WebServerTest method testCreateHandlersCoversExpectedContextPaths.
@Test
public void testCreateHandlersCoversExpectedContextPaths() {
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
WebServer webServer = new WebServer(/* port */
9999, projectFilesystem, "/static/", ObjectMappers.newDefaultInstance());
ImmutableList<ContextHandler> handlers = webServer.createHandlers();
final Map<String, ContextHandler> contextPathToHandler = Maps.newHashMap();
for (ContextHandler handler : handlers) {
contextPathToHandler.put(handler.getContextPath(), handler);
}
Function<String, TemplateHandlerDelegate> getDelegate = contextPath -> ((TemplateHandler) contextPathToHandler.get(contextPath).getHandler()).getDelegate();
assertTrue(getDelegate.apply("/") instanceof IndexHandlerDelegate);
assertTrue(contextPathToHandler.get("/static").getHandler() instanceof ResourceHandler);
assertTrue(getDelegate.apply("/trace") instanceof TraceHandlerDelegate);
assertTrue(getDelegate.apply("/traces") instanceof TracesHandlerDelegate);
assertTrue(contextPathToHandler.get("/tracedata").getHandler() instanceof TraceDataHandler);
}
use of org.eclipse.jetty.server.handler.ContextHandler in project sonarqube by SonarSource.
the class HttpProcess method start.
@Override
public void start() {
writeTimeToFile("startingAt");
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setClassLoader(Thread.currentThread().getContextClassLoader());
server.setHandler(context);
context.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
if ("/ping".equals(target)) {
request.setHandled(true);
httpServletResponse.getWriter().print("ping");
} else if ("/restart".equals(target)) {
writeTimeToFile("restartAskedAt");
request.setHandled(true);
processCommands.askForRestart();
httpServletResponse.getWriter().print("ok");
} else if ("/kill".equals(target)) {
writeTimeToFile("killedAt");
System.exit(0);
}
}
});
try {
server.start();
} catch (Exception e) {
throw new IllegalStateException("Fail to start Jetty", e);
}
}
use of org.eclipse.jetty.server.handler.ContextHandler in project gerrit by GerritCodeReview.
the class JettyServer method makeContext.
private Handler makeContext(final JettyEnv env, final Config cfg) {
final Set<String> paths = new HashSet<>();
for (URI u : listenURLs(cfg)) {
String p = u.getPath();
if (p == null || p.isEmpty()) {
p = "/";
}
while (1 < p.length() && p.endsWith("/")) {
p = p.substring(0, p.length() - 1);
}
paths.add(p);
}
final List<ContextHandler> all = new ArrayList<>();
for (String path : paths) {
all.add(makeContext(path, env, cfg));
}
if (all.size() == 1) {
//
return all.get(0);
}
// We have more than one path served out of this container so
// combine them in a handler which supports dispatching to the
// individual contexts.
//
final ContextHandlerCollection r = new ContextHandlerCollection();
r.setHandlers(all.toArray(new Handler[0]));
return r;
}
use of org.eclipse.jetty.server.handler.ContextHandler in project camel by apache.
the class BaseHttpTest method contextHandler.
protected ContextHandler contextHandler(String context, Handler handler) {
ContextHandler contextHandler = new ContextHandler(context);
contextHandler.setHandler(handler);
return contextHandler;
}
Aggregations