Mercurial > dive4elements > framework
diff artifact-database/src/main/java/de/intevation/artifactdatabase/rest/Standalone.java @ 264:fa0d9acea897
flys/issue65: Added Jetty HTTP server as a replacement option to foster better scalability. Needs testing.
artifacts/trunk@1975 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 22 May 2011 12:40:32 +0000 |
parents | c0fb96f88ad1 |
children | d52947ce8629 |
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/Standalone.java Sun May 22 11:21:40 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/Standalone.java Sun May 22 12:40:32 2011 +0000 @@ -67,10 +67,10 @@ public Standalone() { } + @Override public void setup(Document document) { String portString = XMLUtils.xpathString(document, REST_PORT, null); - port = DEFAULT_PORT; if (portString != null) { @@ -90,6 +90,18 @@ maxThreads = XMLUtils.xpathString(document, MAX_THREADS, null); } + protected Server createServer() { + return listen != null + ? new Server(Protocol.HTTP, listen, port) + : new Server(Protocol.HTTP, port); + } + + protected void logServerStart() { + logger.info("Starting " + getClass().getName() + " HTTP server on " + + (listen != null ? listen : "*") + + ":" + port); + } + /** * Builds a RestApp wrapped around the given artifact database, * and bind this application to HTTP server. The HTTP server @@ -100,20 +112,14 @@ * @param db The artifact database to be exposed via the * REST application. */ + @Override public void startAsServer(ArtifactDatabase db) { RestApp app = new RestApp(db); Component component = new Component(); - Server server = null; - - if (listen != null) { - server = new Server(Protocol.HTTP, listen, port); - } - else { - server = new Server(Protocol.HTTP, port); - } + Server server = createServer(); component.getServers().add(server); @@ -124,9 +130,7 @@ component.getDefaultHost().attach(app); - logger.info("Starting rest HTTP server on " - + (listen != null ? listen : "*") - + ":" + port); + logServerStart(); try { component.start();