1
0
mirror of https://github.com/octoleo/plantuml-server.git synced 2024-11-16 17:25:13 +00:00
plantuml-server/src/test/java/net/sourceforge/plantuml/servlet/ServerUtils.java
Pablo Lalloni 89c4d91b41 Project fully mavenized with functionality exceeding previous Ant build.xml implemented (except deployment to servlet container, which can be easily added).
Improved unit tests to be independent of externally running servlet container, now every test runs its own embedded jetty server (and stops it afterward).

Removed all eclipse artifacts (.project, .classpath, .settings, etc.) and added to .gitignore to be independent of development environment (can be autogenerated by maven, or better yet use m2eclipse).

Removed embedded dependency jars since they are handled automatically by maven.
2011-11-02 19:11:52 -03:00

39 lines
965 B
Java

package net.sourceforge.plantuml.servlet;
import java.net.InetSocketAddress;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class ServerUtils {
Server server;
public ServerUtils(boolean start) throws Exception {
server = new Server(new InetSocketAddress("127.0.0.1", 0));
server.addBean(new WebAppContext(server, "src/main/webapp", "/plantuml"));
if (start) {
startServer();
}
}
public ServerUtils() throws Exception {
this(false);
}
public void startServer() throws Exception {
server.start();
}
public void stopServer() throws Exception {
server.stop();
}
public String getServerUrl() {
Connector connector = server.getConnectors()[0];
return String.format("http://%s:%d/plantuml/", connector.getHost(), connector.getLocalPort());
}
}