blob: f7f2a5c64d0b67d4a21bfc45eec04f2c8de08627 [file] [log] [blame]
package org.eclipse.jetty.nosql.ehcache;
import java.net.URI;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.webapp.WebAppContext;
public class EhcacheServer
{
private Server _server;
private int _port;
private String _host;
private String _path;
public EhcacheServer()
{
}
public void start() throws Exception
{
_server = new Server();
Connector connector = new SelectChannelConnector();
_server.setConnectors(new Connector[] { connector });
String war = MavenTestingUtils.getTargetFile("ehcache-server.war").getAbsolutePath();
WebAppContext webapp = new WebAppContext();
webapp.setWar(war);
webapp.setParentLoaderPriority(true);
_server.setHandler(webapp);
_server.start();
_port = connector.getLocalPort();
_host = connector.getHost();
if (_host == null)
{
_host = "localhost";
}
_path = webapp.getContextPath();
}
public void stop() throws Exception
{
_server.stop();
_server = null;
}
public URI getURI() throws Exception
{
return new URI("http://" + _host + ":" + _port + _path);
}
public static void main(String[] args) throws Exception
{
EhcacheServer cacheServer = new EhcacheServer();
cacheServer.start();
System.out.println(cacheServer.getURI());
}
}