X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fhttpserver%2FHttpServer.java;fp=src%2Fjalview%2Fhttpserver%2FHttpServer.java;h=fcfefaa82ac3678dac4196c8b3a3ebb7ecf1e6ba;hb=2150df780eddbdf72013d29ee8eabb0f235c7bb4;hp=e60db9abe3452ed2bf434ac6eebac579e5ae2561;hpb=e5b2fbdb4ecc9faaadcc3e18fabad8794fca44aa;p=jalview.git
diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java
index e60db9a..fcfefaa 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());
}
/**
@@ -200,16 +207,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 +250,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());
}
/**