use of org.eclipse.jetty.servlet.ServletHandler in project chassis by Kixeye.
the class ChassisEurekaTestConfiguration method httpServer.
@Order(0)
@Bean(initMethod = "start", destroyMethod = "stop")
public Server httpServer(@Value("${http.hostname}") String hostname, @Value("${http.port}") int port, ConfigurableWebApplicationContext webApplicationContext) {
// set up servlets
ServletHandler servlets = new ServletHandler();
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
context.setErrorHandler(null);
context.setWelcomeFiles(new String[] { "/" });
// set up spring with the servlet context
setServletContext(context.getServletContext());
// configure the spring mvc dispatcher
DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext);
// map application servlets
context.addServlet(new ServletHolder(dispatcher), "/");
servlets.setHandler(context);
// create the server
InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setHost(address.getHostName());
connector.setPort(address.getPort());
server.setConnectors(new Connector[] { connector });
server.setHandler(servlets);
return server;
}
Aggregations