You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by bb...@apache.org on 2017/11/20 19:34:04 UTC
nifi-registry git commit: NIFIREG-55 Adding a startupFailure method
to be called when exceptions are caught in JettyServer which will called
system.exit
Repository: nifi-registry
Updated Branches:
refs/heads/master a66503552 -> 63ddf4129
NIFIREG-55 Adding a startupFailure method to be called when exceptions are caught in JettyServer which will called system.exit
This closes #39.
Signed-off-by: Bryan Bende <bb...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/nifi-registry/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-registry/commit/63ddf412
Tree: http://git-wip-us.apache.org/repos/asf/nifi-registry/tree/63ddf412
Diff: http://git-wip-us.apache.org/repos/asf/nifi-registry/diff/63ddf412
Branch: refs/heads/master
Commit: 63ddf412963c2ac5a858b23c27da410d6cd75872
Parents: a665035
Author: Bryan Bende <bb...@apache.org>
Authored: Thu Nov 16 14:57:23 2017 -0500
Committer: Bryan Bende <bb...@apache.org>
Committed: Mon Nov 20 14:33:47 2017 -0500
----------------------------------------------------------------------
.../apache/nifi/registry/jetty/JettyServer.java | 82 ++++++++++----------
1 file changed, 43 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi-registry/blob/63ddf412/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java
----------------------------------------------------------------------
diff --git a/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java b/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java
index 6cdcfb8..db3129b 100644
--- a/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java
+++ b/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java
@@ -89,8 +89,12 @@ public class JettyServer {
final Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
classlist.addBefore(JettyWebXmlConfiguration.class.getName(), AnnotationConfiguration.class.getName());
- configureConnectors();
- loadWars();
+ try {
+ configureConnectors();
+ loadWars();
+ } catch (final Throwable t) {
+ startUpFailure(t);
+ }
}
private void configureConnectors() {
@@ -195,7 +199,7 @@ public class JettyServer {
return contextFactory;
}
- private void loadWars() {
+ private void loadWars() throws IOException {
final File warDirectory = properties.getWarLibDirectory();
final File[] wars = warDirectory.listFiles(WAR_FILTER);
@@ -243,7 +247,7 @@ public class JettyServer {
server.setHandler(handlers);
}
- private WebAppContext loadWar(final File warFile, final String contextPath) {
+ private WebAppContext loadWar(final File warFile, final String contextPath) throws IOException {
final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath);
webappContext.setContextPath(contextPath);
webappContext.setDisplayName(contextPath);
@@ -275,47 +279,40 @@ public class JettyServer {
// configure the max form size (3x the default)
webappContext.setMaxFormContentSize(600000);
- try {
- webappContext.setClassLoader(new WebAppClassLoader(ClassLoader.getSystemClassLoader(), webappContext));
- } catch (final IOException ioe) {
- throw new RuntimeException(ioe);
- }
+ webappContext.setClassLoader(new WebAppClassLoader(ClassLoader.getSystemClassLoader(), webappContext));
+
logger.info("Loading WAR: " + warFile.getAbsolutePath() + " with context path set to " + contextPath);
return webappContext;
}
- private ContextHandler createDocsWebApp(final String contextPath) {
- try {
- final ResourceHandler resourceHandler = new ResourceHandler();
- resourceHandler.setDirectoriesListed(false);
-
- // load the docs directory
- final File docsDir = Paths.get("docs").toRealPath().toFile();
- final Resource docsResource = Resource.newResource(docsDir);
-
- // load the rest documentation
- final File webApiDocsDir = new File(webApiContext.getTempDirectory(), "webapp/docs");
- if (!webApiDocsDir.exists()) {
- final boolean made = webApiDocsDir.mkdirs();
- if (!made) {
- throw new RuntimeException(webApiDocsDir.getAbsolutePath() + " could not be created");
- }
+ private ContextHandler createDocsWebApp(final String contextPath) throws IOException {
+ final ResourceHandler resourceHandler = new ResourceHandler();
+ resourceHandler.setDirectoriesListed(false);
+
+ // load the docs directory
+ final File docsDir = Paths.get("docs").toRealPath().toFile();
+ final Resource docsResource = Resource.newResource(docsDir);
+
+ // load the rest documentation
+ final File webApiDocsDir = new File(webApiContext.getTempDirectory(), "webapp/docs");
+ if (!webApiDocsDir.exists()) {
+ final boolean made = webApiDocsDir.mkdirs();
+ if (!made) {
+ throw new RuntimeException(webApiDocsDir.getAbsolutePath() + " could not be created");
}
- final Resource webApiDocsResource = Resource.newResource(webApiDocsDir);
+ }
+ final Resource webApiDocsResource = Resource.newResource(webApiDocsDir);
- // create resources for both docs locations
- final ResourceCollection resources = new ResourceCollection(docsResource, webApiDocsResource);
- resourceHandler.setBaseResource(resources);
+ // create resources for both docs locations
+ final ResourceCollection resources = new ResourceCollection(docsResource, webApiDocsResource);
+ resourceHandler.setBaseResource(resources);
- // create the context handler
- final ContextHandler handler = new ContextHandler(contextPath);
- handler.setHandler(resourceHandler);
+ // create the context handler
+ final ContextHandler handler = new ContextHandler(contextPath);
+ handler.setHandler(resourceHandler);
- logger.info("Loading documents web app with context path set to " + contextPath);
- return handler;
- } catch (Exception ex) {
- throw new IllegalStateException("Resource directory paths are malformed: " + ex.getMessage());
- }
+ logger.info("Loading documents web app with context path set to " + contextPath);
+ return handler;
}
public void start() {
@@ -332,17 +329,24 @@ public class JettyServer {
// see if this webapp had any exceptions that would
// cause it to be unavailable
if (context.getUnavailableException() != null) {
- throw context.getUnavailableException();
+ startUpFailure(context.getUnavailableException());
}
}
}
dumpUrls();
} catch (final Throwable t) {
- throw new RuntimeException("Unable to start up: " + t, t);
+ startUpFailure(t);
}
}
+ private void startUpFailure(Throwable t) {
+ System.err.println("Failed to start web server: " + t.getMessage());
+ System.err.println("Shutting down...");
+ logger.warn("Failed to start web server... shutting down.", t);
+ System.exit(1);
+ }
+
private void dumpUrls() throws SocketException {
final List<String> urls = new ArrayList<>();