org.jlot.web.it.ServletContainer Maven / Gradle / Ivy
package org.jlot.web.it;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.WebAppContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@Profile("integration")
public class ServletContainer
{
// private static final String WAR_FILE =
// "../jlot-web/target/jlot-web.war";
private static final String WAR_FILE = "../jlot-web/src/main/webapp";
public static final String HOST = "127.0.0.1";
public static final int PORT = 8080;
public static final int DEBUGGING_PORT = 9080;
public static final String CONTEXT_PATH = "/";
@Bean
Server server ( ) throws Exception
{
System.setProperty("spring.profiles.active", "integration");
Server server = new Server();
server.addConnector(getConnector());
server.setHandler(getWac());
server.setStopAtShutdown(true);
server.start();
return server;
}
private WebAppContext getWac ( )
{
WebAppContext wac = new WebAppContext();
wac.setContextPath(CONTEXT_PATH);
wac.setWar(WAR_FILE);
wac.setExtraClasspath("../jlot-web/target/classes");
// wac.setExtraClasspath("../jlot-core-it/target/classes");
return wac;
}
private Connector getConnector ( )
{
Connector connector = new SelectChannelConnector();
connector.setPort(PORT);
connector.setHost(HOST);
return connector;
}
public static String getUrl ( )
{
return "http://" + HOST + ":" + PORT + CONTEXT_PATH;
}
/**
* to activate a TCP/IP Monitor in eclipse/Preferences/Debug
*
* @return
*/
public static String getDebuggingUrl ( )
{
return "http://" + HOST + ":" + DEBUGGING_PORT + CONTEXT_PATH;
}
public static void main ( String[] args ) throws Exception
{
ServletContainer servletContainer = new ServletContainer();
servletContainer.start();
}
public void start ( ) throws Exception
{
Server server = server();
server.join();
}
}