/* * (C) Copyright 2014 Kurento (http://kurento.org/) * * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser General Public License * (LGPL) version 2.1 which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-2.1.html * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ package com.kurento.kmf.test.services; import java.io.IOException; import javax.servlet.ServletException; import org.apache.catalina.LifecycleException; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.handler.ResourceHandler; import org.springframework.core.io.ClassPathResource; /** * Jetty server for tests. * * @author Micael Gallego (micael.gallego@gmail.com) * @since 4.2.3 */ public class HttpServer { private Server server; public HttpServer(int port) throws ServletException, IOException { server = new Server(port); ResourceHandler resource_handler = new ResourceHandler(); resource_handler.setDirectoriesListed(true); resource_handler.setWelcomeFiles(new String[] { "index.html" }); resource_handler.setResourceBase(new ClassPathResource("static") .getURI().toString()); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() }); server.setHandler(handlers); } public void start() throws LifecycleException { try { server.start(); } catch (Exception e) { throw new RuntimeException(e); } } public void destroy() throws LifecycleException { try { server.stop(); } catch (Exception e) { throw new RuntimeException(e); } } }