0
votes

I'm trying to put 2 apps, which occupy different subdomains under the same Tomcat. Apps use different oracle db user/schemas but share some env-variables

   **server.xml**
      <Server port="8005" shutdown="SHUTDOWN">
       <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
      <Listener className="org.apache.catalina.core.JasperListener" />
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
            <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
      <GlobalNamingResources>
        <Environment name="birt/engineHome" value="/opt/birt-runtime-4_2_1/ReportEngine" type="java.lang.String" override="false" />
        <Environment name="birt/logDir" value="/opt/tomcat/logs" type="java.lang.String" override="false" />
        <Environment name="educ/uploadDir" value="/opt/upload" type="java.lang.String" override="false" />
        <Environment name="educ/exportDir" value="/opt/export" type="java.lang.String" override="false" />
        <Environment name="educ/officeExec" value="/usr/bin/soffice" type="java.lang.String" override="false" />
        <Environment name="educ/kavExec" override="false" type="java.lang.String" value="/opt/kaspersky/kav4fs/bin/kav4fs-control"/>
        <Environment name="educ/protectedPorts" value="8443,8082,443" type="java.lang.String" override="false" />
      </GlobalNamingResources>
            <Service name="Catalina">

       <Connector server="" allowTrace="false" port="8443" maxHttpHeaderSize="1048576" protocol="org.apache.coyote.http11.Http11AprProtocol" connectionTimeout="20000" redirectPort="8443" maxSwallowSize="-1" maxPostSize="-1" SSLHonorCipherOrd
    er="true" SSLCertificateFile="/home/oracle/certificate.crt" SSLCertificateKeyFile="/home/oracle/private.key" SSLCertificateChainFile="/home/oracle/ca_bundle.crt" SSLProtocol="TLSv1.2" maxThreads="350" minSpareThreads="25" SSLEnabled="tru
    e" enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true" compression="force" SSLCipherSuite="ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-ECDSA-AES256-GCM-SHA256,ECDHE-RSA-AES256-GCM-SHA384,ECDHE-ECDSA-C
    HACHA20-POLY1305,ECDHE-RSA-CHACHA20-POLY1305,ECDHE-ECDSA-AES128-GCM-SHA256, ECDHE-RSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES256-SHA384,ECDHE-RSA-AES256-SHA384,ECDHE-ECDSA-AES128-SHA256,ECDHE-RSA-AES128-SHA256,ECDHE-RSA-AES128-SHA,ECDHE-RSA-AE
    S256-SHA" />
        <Engine name="Catalina" defaultHost="demo.idissoft.ru">
          <Host name="demo.idissoft.ru" appBase="/opt/tomcat/"
           unpackWARs="true" autoDeploy="true" deployXML="true">
             <Realm className="org.apache.catalina.realm.DataSourceRealm"
               dataSourceName="jdbc/IEML_DB" digest="MD5"
               userTable="educ.ad_Users" userNameCol="UserName" userCredCol="PWD"
               userRoleTable="educ.ad_UserRoles" roleNameCol="RoleName"/>
             </Host>
          <Host name="kazpds.idissoft.ru" appBase="/opt/tomcat/"
           unpackWARs="true" autoDeploy="true" deployXML="true">
      <Realm className="org.apache.catalina.realm.DataSourceRealm"
               dataSourceName="jdbc/IEML_DB" digest="MD5"
               userTable="sem.ad_Users" userNameCol="UserName" userCredCol="PWD"
               userRoleTable="sem.ad_UserRoles" roleNameCol="RoleName"/>
            </Host>
        </Engine>
      </Service>
    </Server>

**Stend.xml** located at /opt/tomcat/conf/Catalina/demo.idissoft.ru
    <?xml version="1.0" encoding="UTF-8"?>
    <Context useHttpOnly="false" allowCasualMultipartParsing="true">
            <Valve className="org.apache.catalina.authenticator.FormAuthenticator"
              disableProxyCaching="false"  />
            <Resource name="jdbc/IEML_DB" auth="Container" type="javax.sql.DataSource"
                   maxActive="200" maxIdle="200" maxWait="50000"
                   poolPreparedStatements="false"
                   username="educ" password="******"
                   driverClassName="oracle.jdbc.driver.OracleDriver"
                   url="jdbc:oracle:thin:@//192.168.1.10:1521/sun.ieml.ru"
                   accessToUnderlyingConnectionAllowed="true"
                       removeAbandoned="true" removeAbandonedTimeout="300"
               logAbandoned="true" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
    />
            <ResourceLink name="birt/engineHome" global="birt/engineHome" type="java.lang.String" />
            <ResourceLink name="birt/logDir" global="birt/logDir" type="java.lang.String" />
            <ResourceLink name="educ/uploadDir" global="educ/uploadDir" type="java.lang.String" />
            <ResourceLink name="educ/exportDir" global="educ/exportDir" type="java.lang.String" />
            <ResourceLink name="educ/officeExec" global="educ/officeExec" type="java.lang.String"/>
            <ResourceLink name="educ/kavExec" global="educ/kavExec" type="java.lang.String"/>

        <Parameter name="schema" value="educ" />
        <Parameter name="guiStyle" value="style.css" />
        <Parameter name="checkSecurity" value="false" />
        <Parameter name="redirectPort" value="443" />
    </Context>

**Seminary.xml** located at /opt/tomcat/conf/Catalina/kazpds.idissoft.ru
<?xml version="1.0" encoding="UTF-8"?>
<Context  useHttpOnly="false" allowCasualMultipartParsing="true">
        <Valve className="org.apache.catalina.authenticator.FormAuthenticator"
          disableProxyCaching="false"  />
<Resource name="jdbc/IEML_DB" auth="Container" type="javax.sql.DataSource"
               maxActive="200" maxIdle="200" maxWait="50000"
               poolPreparedStatements="false"
               username="sem" password="******"
               driverClassName="oracle.jdbc.driver.OracleDriver"
               url="jdbc:oracle:thin:@//192.168.1.10:1521/sem.ieml.ru"
               accessToUnderlyingConnectionAllowed="true"
                   removeAbandoned="true" removeAbandonedTimeout="300"
           logAbandoned="true" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
/>
        <ResourceLink name="birt/engineHome" global="birt/engineHome" type="java.lang.String" />
        <ResourceLink name="birt/logDir" global="birt/logDir" type="java.lang.String" />
        <ResourceLink name="educ/uploadDir" global="educ/uploadDir" type="java.lang.String" />
        <ResourceLink name="educ/exportDir" global="educ/exportDir" type="java.lang.String" />
        <ResourceLink name="educ/officeExec" global="educ/officeExec" type="java.lang.String"/>
        <ResourceLink name="educ/kavExec" global="educ/kavExec" type="java.lang.String"/>
    <Parameter name="schema" value="sem" />
    <Parameter name="guiStyle" value="style.css" />
    <Parameter name="checkSecurity" value="false" />
    <Parameter name="redirectPort" value="443" />
</Context>

part of Seminary web.xml

  <resource-ref>
    <description>Oracle Datasource</description>
    <res-ref-name>jdbc/IEML_DB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
<env-ref>
    <env-ref-name>educ/uploadDir</env-ref-name>
    <env-ref-type>java.lang.String</env-ref-type>
</env-ref>

part of Stend web.xml

     <resource-ref>
                <description>Oracle Datasource</description>
                <res-ref-name>jdbc/IEML_DB</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
        </resource-ref>
directory structure of tomcat ls - output
ll /opt/tomcat/
total 324
-rwxr-xr-x.  1 oracle oinstall   4172 Sep 26  2017 authorities.crt
drwxr-xr-x.  4 oracle oinstall   4096 Sep 26  2017 bin
drwxr-xr-x.  3 oracle oinstall   4096 Jul 22 19:56 conf
drwxr-xr-x.  3 oracle oinstall   4096 Sep 26  2017 lib
-rwxr-xr-x.  1 oracle oinstall  57896 Sep 26  2017 LICENSE
drwxr-xr-x.  2 oracle oinstall 139264 Jul 22 20:23 logs
-rwxr-xr-x.  1 oracle oinstall   1275 Sep 26  2017 NOTICE
-rwxr-xr-x.  1 oracle oinstall   9195 Sep 26  2017 RELEASE-NOTES
-rwxr-xr-x.  1 oracle oinstall  16671 Sep 26  2017 RUNNING.txt
drwxr-xr-x. 14 oracle oinstall   4096 Jul 22 14:35 Seminary
-rwxr-xr-x.  1 oracle oinstall   1734 Sep 26  2017 server.key
-rwxr-xr-x.  1 oracle oinstall   1887 Sep 26  2017 STAR_ieml_ru.crt
drwxr-xr-x. 14 oracle oinstall   4096 Jul 20 19:50 Stend
drwxr-xr-x. 21 oracle oinstall  45056 Jul 22 20:22 temp
drwxr-xr-x.  4 oracle oinstall   4096 Jul 22 17:47 webapps
drwxr-xr-x.  3 oracle oinstall   4096 Sep 26  2017 work

catalina .out shows its famous javax.naming.NameNotFoundException on both apps INFO: Deploying web application directory /opt/tomcat/Stend javax.naming.NameNotFoundException: Name [educ/uploadDir] is not bound in this Context. Unable to find [educ]. INFO: Deploying web application directory /opt/tomcat/Seminary javax.naming.NameNotFoundException: Name [educ/uploadDir] is not bound in this Context. Unable to find [educ].

java code that accesses jndi
import javax.servlet.*;
import javax.naming.*;
import javax.sql.*;
import com.ieml.*;
import com.ieml.menu.*;
import com.ieml.util.*;
import com.ieml.model.*;
import com.ieml.cache.*; 
import com.ieml.basedata.BirtService;



    public final class ContextListener implements ServletContextListener {

        public ContextListener() 
        {
        }

        public void contextInitialized(ServletContextEvent event) {
            ServletContext context = event.getServletContext();
            try {
                Context initContext = new InitialContext();
                Context envContext  = (Context)initContext.lookup("java:/comp/env");

                // Setting global data source
                Global.setDataSource((DataSource)envContext.lookup("jdbc/IEML_DB"));
                Global.setSchema(context.getInitParameter("schema"));
                Global.setUploadDirectory((String)envContext.lookup("educ/uploadDir"));
                Global.setExportDirectory((String)envContext.lookup("educ/exportDir"));
                Global.setOfficeExec((String)envContext.lookup("educ/officeExec"));
                Global.setKavExec((String)envContext.lookup("educ/kavExec"));
                String guiStyle = context.getInitParameter("guiStyle");
                Global.setGuiStyle(guiStyle == null ? "style.css" : guiStyle);

Am I missing something obvious?

1

1 Answers

0
votes

I've ended up Setting up separate tomcat for 2 applications