Skip to content

Commit

Permalink
Simplified server implementations by removing the shutdown REST endpo…
Browse files Browse the repository at this point in the history
…int on the bulk servlet, which was a security issue anyway
  • Loading branch information
Ian Emmons committed Sep 24, 2019
1 parent 57cd956 commit e35148c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,34 @@

import java.nio.charset.StandardCharsets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CmdLineJettyServer {
private static final Logger LOG = LoggerFactory.getLogger(CmdLineJettyServer.class);

/** Default entry point. */
public static void main(String[] args) {
try {
JettyServerCore.initialize();
JettyServerCore.getInstance().startCore();
JettyServerCore.getInstance().start();

try {
Thread.sleep(4000);
} catch (InterruptedException ex) {
// Do nothing
}

printPrompt();
for (boolean timeToExit = false; !timeToExit;) {
printPrompt();
byte[] bytes = new byte[256];
Thread.sleep(2000);
if (!JettyServerCore.getInstance().isCoreStarted()) {
timeToExit = true;
} else if (System.in.available() > 0) {
int count = System.in.read(bytes);
String consoleInput = new String(bytes, 0, count, StandardCharsets.UTF_8).trim();
timeToExit = consoleInput.equalsIgnoreCase("exit");
if (!timeToExit) {
printPrompt();
}
}
int count = System.in.read(bytes);
String consoleInput = new String(bytes, 0, count, StandardCharsets.UTF_8).trim();
timeToExit = consoleInput.equalsIgnoreCase("exit");
}

System.out.format("Shutting down server%n");
} catch (Exception ex) {
LOG.error("Parliament server encountered an exception", ex);
} finally {
JettyServerCore.getInstance().stopCore();
JettyServerCore.getInstance().stop();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

package com.bbn.parliament.jena.jetty;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Provides entry points to use with the Apache Commons Daemon package (jsvc)
* to render Parliament running inside Jetty as a UNIX or Linux Daemon.
Expand Down Expand Up @@ -38,7 +35,7 @@ public void init(String[] args) {
public void start() {
try {
LOG.info("Starting Jetty Daemon");
JettyServerCore.getInstance().startCore();
JettyServerCore.getInstance().start();
} catch (Exception ex) {
LOG.error("Parliament server encountered an exception", ex);
}
Expand All @@ -48,7 +45,7 @@ public void start() {
@SuppressWarnings("static-method")
public void stop() {
LOG.info("Stopping Jetty Daemon");
JettyServerCore.getInstance().stopCore();
JettyServerCore.getInstance().stop();
}

/** Cleanup resources allocated in init() */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.deploy.providers.WebAppProvider;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JettyServerCore {
private static final String JETTY_CONF_SYS_PROP_NAME = "jettyConfig";
Expand Down Expand Up @@ -58,16 +55,12 @@ public static JettyServerCore getInstance() {
//
//================================================================

public boolean isCoreStarted() {
return server.isStarted();
}

public void startCore() throws Exception {
public void start() throws Exception {
server.start();
LOG.info("Starting Parliament server");
}

public void stopCore() {
public void stop() {
try {
LOG.info("Shutting down Parliament server");
server.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

package com.bbn.parliament.jena.jetty;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Provides entry points to use with the Apache Commons Daemon package (procrun)
* to render Parliament running inside Jetty as a Windows Service.
Expand All @@ -25,10 +22,10 @@ public class JettyService {
public static void start(String[] args) {
try {
JettyServerCore.initialize();
JettyServerCore.getInstance().startCore();
JettyServerCore.getInstance().start();
LOG.info("Starting Parliament server");
synchronized (lock) {
while (!timeToExit && JettyServerCore.getInstance().isCoreStarted()) {
while (!timeToExit) {
try {
lock.wait(5000);
} catch (InterruptedException ex) {
Expand All @@ -40,7 +37,7 @@ public static void start(String[] args) {
} catch (Exception ex) {
LOG.error("Parliament server encountered an exception", ex);
} finally {
JettyServerCore.getInstance().stopCore();
JettyServerCore.getInstance().stop();
LOG.info("Parliament server stopped");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bbn.parliament.jena.joseki.bridge.ParliamentBridge;
import com.bbn.parliament.jena.joseki.bridge.util.HttpServerUtil;
import com.bbn.parliament.jena.joseki.handler.ClearHandler;
import com.bbn.parliament.jena.joseki.handler.ExportHandler;
import com.bbn.parliament.jena.joseki.handler.FlushHandler;
import com.bbn.parliament.jena.joseki.handler.InsertHandler;
import com.bbn.parliament.jena.joseki.handler.ShutdownHandler;

/** @author sallen */
public class BulkServlet extends HttpServlet {
Expand Down Expand Up @@ -121,10 +117,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
LOG.info("Flush operation from {}", req.getRemoteAddr());
FlushHandler handler = new FlushHandler();
handler.handleFormURLEncodedRequest(req, resp);
} else if ("shutdown".equals(svcUri)) {
LOG.info("Shutdown operation from {}", req.getRemoteAddr());
ShutdownHandler handler = new ShutdownHandler();
handler.handleFormURLEncodedRequest(req, resp);
} else if ("export".equals(svcUri)) {
LOG.info("Export operation from {}", req.getRemoteAddr());
ExportHandler handler = new ExportHandler();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class ParliamentTestServer {
private static boolean timeToExit = false;
private static final Object lock = new Object();
private static final AtomicBoolean errorOcurredDuringServerStart = new AtomicBoolean(false);
private static final AtomicBoolean serverHasStarted = new AtomicBoolean(false);

// Call from @BeforeClass
public static void createServer() {
Expand All @@ -22,9 +22,10 @@ public static void createServer() {
@Override
public void run() {
try {
JettyServerCore.getInstance().startCore();
JettyServerCore.getInstance().start();
serverHasStarted.set(true);
synchronized (lock) {
while (!timeToExit && JettyServerCore.getInstance().isCoreStarted()) {
while (!timeToExit) {
try {
lock.wait(5000);
} catch (InterruptedException ex) {
Expand All @@ -33,25 +34,22 @@ public void run() {
}
}
} catch (Exception ex) {
errorOcurredDuringServerStart.set(true);
serverHasStarted.set(true);
fail(ex.getMessage());
} finally {
JettyServerCore.getInstance().stopCore();
JettyServerCore.getInstance().stop();
}
}
});
t.setDaemon(true);
t.start();
while (!JettyServerCore.getInstance().isCoreStarted()) {
if (errorOcurredDuringServerStart.get()) {
break;
}
do {
try {
Thread.sleep(250);
} catch(InterruptedException ex) {
fail(ex.getMessage());
}
}
} while (!serverHasStarted.get());
}

// Call from @AfterClass
Expand Down
27 changes: 7 additions & 20 deletions jena/JosekiExtensions/www/admin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,15 @@
<div class="op-list"><h3><a href="index.jsp">Home</a></h3> <jsp:include page="index/000_operations.jsp"/></div>

<br/>
<div class="moreindent infobox">
<div class="moreindent infobox">
<h2>Flush Data</h2>
<form action="bulk/flush" method="post">
<p>
Flush in-memory statements to disk: &nbsp;&nbsp; <input type="submit" value="Flush Data" />
</p>
</form>
</div>
<br/>
<!--
<div class="moreindent">
<br />
<h2>Shutdown</h2>
<form action="bulk/shutdown" method="post">
<p>
Shutdown the server: &nbsp;&nbsp; <input type="submit" value="Shutdown" />
</p>
<p>
Flush in-memory statements to disk: &nbsp;&nbsp; <input type="submit" value="Flush Data" />
</p>
</form>
<br/>
</div>
-->
</div>
<br/>
<div class="moreindent infobox">
<h2 id="numQueries"><span>No</span> Queries</h2>
<table border=0 width=100%>
Expand All @@ -51,8 +39,7 @@
</td>
</tr>
</table>
<div id="queries">

<div id="queries">
</div>
</div>
<script type="text/javascript"><!--
Expand Down

0 comments on commit e35148c

Please sign in to comment.