6

I have followed the online documentation on the xnat site (https://wiki.xnat.org/documentation/getting-started-with-xnat/xnat-installation-guide) and installed apache tomcat 9 ( version 9.0.75, JVM Version : 1.8.0_372_b07, JVM Vendor: Temurin). But when I click 'start' on the xnat webapp, I get the error:

FAIL - Application at context path [/xnat-web-1.8.8] could not be started
FAIL - Encountered exception [org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@35a50a4c]]

The log file shows the following (truncated to allow it to post here):


... org.apache.catalina.core.ApplicationContext.log HTMLManager: Error starting [/xnat-web-1.8.8]
        org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@6dde5c8c]
                at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
              
...
...
...
                at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
                at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
                at java.lang.Thread.run(Thread.java:750)
        Caused by: java.lang.NullPointerException
                at java.lang.String.startsWith(String.java:1405)
                at java.lang.String.startsWith(String.java:1434)
                at org.apache.catalina.webresources.AbstractFileResourceSet.file(AbstractFileResourceSet.java:98)
                at org.apache.catalina.webresources.DirResourceSet.getResource(DirResourceSet.java:94)
                at org.apache.catalina.webresources.StandardRoot.getResourceInternal(StandardRoot.java:272)
                at org.apache.catalina.webresources.Cache.getResource(Cache.java:64)
                at org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:211)
                at org.apache.catalina.webresources.StandardRoot.listResources(StandardRoot.java:347)
                at org.apache.catalina.webresources.StandardRoot.processWebInfLib(StandardRoot.java:585)
                at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:722)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)

According to ChatGPT:

Based on the provided log file, it appears that there is an error during the deployment of the web application '/xnat-web-1.8.8' in Tomcat. The error message indicates a NullPointerException and a LifecycleException related to the StandardRoot component.

The root cause of the issue seems to be the NullPointerException occurring within the AbstractFileResourceSet class. It specifically fails when attempting to access a file resource, likely due to a missing or invalid file path.

I am wondering if the issue is either in the unit file or in the postgresql config (TCP/IP connections) setup. I am only using tomcat on localhost. In my pg_hba.conf file i have just added the line listen_addresses = '*' If you look at the unit file below, I have given it multiple folders to readwrite. Tomcat is by default using /opt/tomcat. But the xnat documentation settings indicate I use /var/lib/tomcat, /var/log/tomcat, and /etc/tomcat/Catalina as ReadWritePaths. I have just added all those alongwith my installation default paths in my unit file. I am wondering if that's where the error is. My tomcat unit file is :


[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=xnat
Group=xnat
PrivateTmp=yes
Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS="-Xms512M -Xmx1024M -server -XX:+UseParallelGC -Dxnat.home=/data/xnat/home"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
#AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=true
CacheDirectory=tomcat
CacheDirectoryMode=750
#ProtectSystem=strict
ReadWritePaths=/etc/tomcat/Catalina/
ReadWritePaths=/opt/tomcat/webapps/
ReadWritePaths=/var/lib/tomcat/webapps/
ReadWritePaths=/opt/log/tomcat/
ReadWritePaths=/var/log/tomcat/
ReadWritePaths=/data/xnat/home
ReadWritePaths=/home/xnat/
[Install]
WantedBy=multi-user.target

The context.xml file under /opt/tomcat/webapps/xnat-1.8.8/META-INF is:

xml version="1.0" encoding="utf-8"?>
<!--
  ~ web: context.xml
  ~ XNAT http://www.xnat.org
  ~ Copyright (c) 2005-2021, Washington University School of Medicine and Howard Hughes Medical Institute
  ~ All Rights Reserved
  ~
  ~ Released under the Simplified BSD.
  -->

<Context>
    <!--
    For Tomcat 7 compatibility, uncomment the <Loader> element and comment out the <Resources>
    and <CookieProcessor> elements under that.
    -->
    <!-- Loader className="org.apache.catalina.loader.VirtualWebappLoader" searchVirtualFirst="true" virtualClasspath="${xnat.home}/plugins/*.jar"/ -->

    <!--
    For Tomcat 8 compatibility, uncomment the <Resources> and <CookieProcessor> elements below and
    comment out the <Loader> element below that.
    -->
    <Resources>
        <PreResources className="org.apache.catalina.webresources.DirResourceSet" base="${xnat.home}/plugins" webAppMount="/WEB-INF/lib" />
    </Resources>
    <CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />
    <JarScanner scanAllDirectories="true" />
    <Parameter name="xnatHome" value="${xnat.home}"/>
    <Manager pathname="" />
</Context>

I have since also unsuccessfully tried to deploy xnat via vagrant and docker. I will be grateful for any help you can give me.

Maelstorm
  • 580
  • 2
  • 10
  • 29
  • What XNAT online documentation are you referring to? Can you share a link? – andrewJames May 27 '23 at 20:02
  • https://wiki.xnat.org/documentation/getting-started-with-xnat/xnat-installation-guide – Maelstorm May 27 '23 at 20:44
  • Thank you for the link. Maybe add that to the question. The instructions are fairly long - and if you are not sure which specific step is causing your Tomcat issue, it may be difficult to help you. Perhaps try the container solutions mentioned at the start of that page? – andrewJames May 27 '23 at 21:40
  • Thank you for helping. I have added my configs in the post. I am hoping that will point to the issue – Maelstorm May 28 '23 at 11:48
  • P.S tried container options today. For various reasons none work! (e.g., installing vm ends with a 'Bad gatway' error. – Maelstorm May 29 '23 at 14:40
  • What is the exact version of Tomcat? – aled May 29 '23 at 15:30
  • And have you modified META-INF/context.xml? Please also share the content of this file. – aled May 29 '23 at 15:36
  • Hi, tomcat 9 ( version 9.0.75, JVM Version : 1.8.0_372_b07, JVM Vendor: Temurin). I havent altered the context.xml file. I have pasted its contents at the bottom of my post. Thanks – Maelstorm May 29 '23 at 16:59
  • ReadWritePaths doesn't include the xnat home directory defined above`/data/xnat/home`. Could you try it? – aled May 29 '23 at 18:20
  • Did it. No effect – Maelstorm May 29 '23 at 19:10

1 Answers1

0

In my opinion the problem is related to the fact that Tomcat is unable to process correctly the application resources defined in the context.xml file:

<Resources>
  <PreResources className="org.apache.catalina.webresources.DirResourceSet" base="${xnat.home}/plugins" webAppMount="/WEB-INF/lib" />
</Resources>

The reason for that could be very likely that the ${xnat.home} placeholder is not resolved successfully, probably because the system property with the same name is not properly defined.

You are try defining that system property in your unit file when defining the CATALINA_OPTS environment variable:

Environment="CATALINA_OPTS="-Xms512M -Xmx1024M -server -XX:+UseParallelGC -Dxnat.home=/data/xnat/home"

Please, note that it is incorrectly defined, note the " after CATALINA_OPTS=.

It should be:

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC -Dxnat.home=/data/xnat/home"

It could be a typo but it may explain as well the problem.

jccampanero
  • 50,989
  • 3
  • 20
  • 49