diff --git a/Kitodo/src/main/java/org/kitodo/production/KitodoProduction.java b/Kitodo/src/main/java/org/kitodo/production/KitodoProduction.java index 91e4a764e5f..c73954ece75 100644 --- a/Kitodo/src/main/java/org/kitodo/production/KitodoProduction.java +++ b/Kitodo/src/main/java/org/kitodo/production/KitodoProduction.java @@ -48,27 +48,29 @@ public class KitodoProduction implements ServletContextListener, HttpSessionList private static final Logger logger = LogManager.getLogger(KitodoProduction.class); private static CompletableFuture instance = new CompletableFuture<>(); private ServletContext context; - private Optional manifest = Optional.empty(); + private Optional manifest; private KitodoVersion version = new KitodoVersion(); private ActiveMQDirector activeMQDirector; @Override - public void contextInitialized(ServletContextEvent sce) { - // Retrieve Manifest file as Stream - context = sce.getServletContext(); - try (InputStream rs = context.getResourceAsStream("/META-INF/MANIFEST.MF")) { - // Use Manifest to setup version information - if (Objects.nonNull(rs)) { - Manifest m = new Manifest(rs); - manifest = Optional.of(m); - version.setupFromManifest(m); + public void contextInitialized(ServletContextEvent event) { + context = event.getServletContext(); + manifest = retrieveManifestFileAsStream(context); + manifest.ifPresent(version::setupFromManifest); + instance.complete(this); + startActiveMQ(); + } + + private static final Optional retrieveManifestFileAsStream(ServletContext context) { + try (InputStream manifestResource = context.getResourceAsStream("/META-INF/MANIFEST.MF")) { + if (Objects.nonNull(manifestResource)) { + return Optional.of(new Manifest(manifestResource)); } } catch (IOException e) { logger.error(e.getMessage(), e); context.log(e.getMessage()); } - instance.complete(this); - startActiveMQ(); + return Optional.empty(); } /**