X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fhttpserver%2FHttpServer.java;h=34b39cd4d452395a34ea271b575810e9b39b1c83;hb=604a94b849bcf1ddb14407418a465c9d134cd6ab;hp=e60db9abe3452ed2bf434ac6eebac579e5ae2561;hpb=bf1ef95b21f5a0c470e33c6cf10022cc732f0df5;p=jalview.git
diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java
index e60db9a..34b39cd 100644
--- a/src/jalview/httpserver/HttpServer.java
+++ b/src/jalview/httpserver/HttpServer.java
@@ -16,6 +16,8 @@ import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
+import jalview.rest.RestHandler;
+
/**
* An HttpServer built on Jetty. To use it
*
@@ -86,6 +88,11 @@ public class HttpServer
private HttpServer() throws BindException
{
startServer();
+
+ /*
+ * Provides a REST server by default; add more programmatically as required
+ */
+ registerHandler(RestHandler.getInstance());
}
/**
@@ -124,7 +131,6 @@ public class HttpServer
// "HttpServer started with %d threads", server.getThreadPool()
// .getThreads()));
contextRoot = server.getURI();
- System.out.println("Jalview endpoint " + contextRoot);
} catch (Exception e)
{
System.err.println("Error trying to start HttpServer: "
@@ -200,16 +206,22 @@ public class HttpServer
}
/**
- * Register a handler for the given path and returns its URI
+ * Register a handler for the given path and set its URI
*
- * @param path
- * a path below the context root (without leading or trailing
- * separator)
* @param handler
* @return
+ * @throws IllegalStateException
+ * if handler path has not been set
*/
- public String registerHandler(String path, AbstractRequestHandler handler)
+ public void registerHandler(AbstractRequestHandler handler)
{
+ String path = handler.getPath();
+ if (path == null)
+ {
+ throw new IllegalStateException(
+ "Must set handler path before registering handler");
+ }
+
// http://stackoverflow.com/questions/20043097/jetty-9-embedded-adding-handlers-during-runtime
ContextHandler ch = new ContextHandler();
ch.setAllowNullPathInfo(true);
@@ -237,7 +249,9 @@ public class HttpServer
+ e.getMessage());
}
- return this.contextRoot + ch.getContextPath().substring(1);
+ handler.setUri(this.contextRoot + ch.getContextPath().substring(1));
+ System.out.println("Jalview " + handler.getName()
+ + " handler started on " + handler.getUri());
}
/**