mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-11-16 17:25:13 +00:00
89c4d91b41
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.
39 lines
965 B
Java
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());
|
|
}
|
|
|
|
}
|