cancel
Showing results for 
Search instead for 
Did you mean: 

Tomcat without global resource

0 Kudos

Hello

I am getting this error when I startup SAP Commerce 1811 (with JNDI and Oracle DB) locally:

SCHWERWIEGEND: Exception sending context initialized event to listener instance of class [de.hybris.platform.spring.HybrisContextLoaderListener]
java.lang.RuntimeException: java.sql.SQLException: error looking up JNDI data source 'java:comp/env/jdbc/hybrisDS' due to Name [comp/env/jdbc/hybrisDS] is not bound in this Context. Unable to find [comp].
        at de.hybris.platform.jdbcwrapper.DataSourceImpl.adjustDatabaseInfos(DataSourceImpl.java:660)
        at de.hybris.platform.jdbcwrapper.DataSourceImpl.<init>(DataSourceImpl.java:218)
        at de.hybris.platform.jdbcwrapper.DataSourceImpl.<init>(DataSourceImpl.java:168)

My customer requires to not have a global resource defined in server.xml. Therefore I moved the resource definition to the context.xml. Here are the 2 files + ammendment tot the web.xml in my storefront:
server.xml

<Server port="-1" shutdown="SHUTDOWN">
<Listener className="de.hybris.tomcat.HybrisGlobalResourcesLifecycleListener"  dataSourceName="java:comp/env/jdbc/hybrisDS"/>
  <GlobalNamingResources></GlobalNamingResources>
  <Service name="Catalina" >
	<Executor     name="hybrisExecutor"
			        namePrefix="hybrisHTTP"
			        maxThreads="200"
			        minSpareThreads="40"
			        maxIdleTime="10000"/>
    <Connector port="9001"
			   maxHttpHeaderSize="8192"
			   maxPostSize="6291456"
               maxThreads="200"
               protocol="HTTP/1.1"
               executor="hybrisExecutor"
               enableLookups="false"
               acceptCount="100"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               disableUploadTimeout="true" />
    <Connector port="9002"
			   maxHttpHeaderSize="8192"
			   maxPostSize="6291456"
               maxThreads="150"
               protocol="HTTP/1.1"
               executor="hybrisExecutor"
               enableLookups="false"
               acceptCount="100"
               connectionTimeout="20000"
               disableUploadTimeout="true"
               URIEncoding="UTF-8"
               SSLEnabled="true"
					scheme="https"
					secure="true"
					clientAuth="false"
   				sslProtocol = "TLS"
   				keyAlias="1"
   				keystoreFile="${catalina.home}/lib/keystore"
   				keystorePass="123456"
                />
	<Connector  protocol="AJP/1.3"  URIEncoding="UTF-8"  port="8009" />	
    <Engine name="Catalina" defaultHost="localhost" startStopThreads="0">
			<Valve 	className="org.apache.catalina.valves.AccessLogValve"
             		directory="D:\Projekte\myproject\hybris\log/tomcat"
	      		 	prefix="access."
        	   		suffix=".log"
	      		 	pattern="combined"
          />
      <Host 	name="localhost"
      			appBase="webapps"
		       	unpackWARs="false"
		       	autoDeploy="false"
		       	startStopThreads="0">		       	
		        <Valve className="org.apache.catalina.valves.ErrorReportValve" 
		               showReport="false" 
		               showServerInfo="false"/>
.....
			<!-- 'hac' extension's context for tenant 'master' -->
			<Context path="/hac" docBase="D:\Projekte\myproject\hybris\bin\platform\ext\hac/web/webroot" >
				<Manager pathname="" />
				<Loader platformHome="D:\Projekte\myproject\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
				
				<JarScanner >
					<JarScanFilter defaultTldScan="false" tldScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,displaytag*.jar,javax.servlet.jsp.jstl-*.jar" defaultPluggabilityScan="false" pluggabilityScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,displaytag*.jar,javax.servlet.jsp.jstl-*.jar,*_hac.jar" />
				</JarScanner>
			</Context>
.....
			<!-- 'backoffice' extension's context for tenant 'master' -->
			<Context path="/backoffice" docBase="D:\Projekte\myproject\hybris\bin\ext-backoffice\backoffice/web/webroot" >
				<Manager pathname="" />
				<Loader platformHome="D:\Projekte\myproject\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
				
				<JarScanner >
					<JarScanFilter defaultTldScan="false" tldScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar" defaultPluggabilityScan="false" pluggabilityScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,webfragment*.jar" />
				</JarScanner>
			</Context>
.....
			<!-- 'myShop' extension's context for tenant 'master' -->
			<Context path="/myShop" docBase="D:\Projekte\myproject\hybris\bin\ext-storefront\myShop/web/webroot" useHttpOnly="true">
				<Manager pathname="" />
				<Loader platformHome="D:\Projekte\myproject\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
				
				<JarScanner >
					<JarScanFilter defaultTldScan="false" tldScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,json-taglib*.jar,jstl-impl*.jar" defaultPluggabilityScan="false" pluggabilityScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan},taglibs-standard-impl*.jar,spring-security-taglibs-*.jar,spring-webmvc*.jar,json-taglib*.jar,jstl-impl*.jar" />
				</JarScanner>
			</Context>
      </Host>
    </Engine>
  </Service>
</Server>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/app/NTQ" sessionCookiePath="/app/NTQ"
         docBase="D:\Projekte\myProject\hybris\bin\platform\..\ext-storefront\myShop\web\webroot"
         privileged="true" antiResourceLocking="false" unpackWAR="false" >

    <Manager pathName="" className="org.apache.catalina.session.StandardManager"/>
    <Loader platformHome="D:\Projekte\myProject\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
    <Resource name="jdbc/hybrisDS"
              auth="Container"
              type="oracle.jdbc.pool.OracleDataSource"
              username="hybris"
              password="hybris"
              driverClassName="oracle.jdbc.driver.OracleDriver"
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
              maxActive="90"
              maxIdle="90"
              maxWait="10000"
              testWhileIdle="true"
              timeBetweenEvictionRunsMillis="10000"
              minEvictableIdleTimeMillis="300000"
              numTestsPerEvictionRun="100"
              testOnBorrow="true"
              testOnReturn="true"
              whenExhaustedAction="1"
              url="jdbc:oracle:thin:@localhost:1521:xe"
    />
</Context>

web.xml (added resource registry):

<resource-ref>
   <description>This is a reference to the global Resource for MySQL database connetion.</description>
   <res-ref-name>jdbc/hybrisDS</res-ref-name>
   <res-type>oracle.jdbc.pool.OracleDataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

local.properties (db properties)

db.pool.name=hybrisDS
db.pool.fromJNDI=java:comp/env/jdbc/${db.pool.name}
db.pool.fromJNDI.dbtype=oracle

Am I missing here some configuration?

Regards

Andy

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello

This was the official statement from SAP which I received by end of May 2020 in my support ticket:

We do not support JNDI datasource in context.xml. We do not see security concern because tomcat should be used only for hybris.

Hope this helps anyone struggling with this question.

Best regards

Andy

Answers (1)

Answers (1)

former_member624549
Participant

Solution 1: since you must do a non standard setup ask your customer to create a ticket with SAP and SAP shall give you the configuration.

Analysis: It looks like the data source is only configured for web context "/app/NTQ" . The access to the DB however happens earlier.

Solution 2: register the jdbc data source globally somehow via tomcat configuration. Maybe this link helps:

http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#Global_configuration

Solution 3: Your customer might have this policy because - usually - multiple applications are deployed on a tomcat. Therefore from the security point of view you may forbid a global data source declaration. Explain to the customer that this tomcat instance is dedicated to hybris. You cannot deploy anything else on it. A global data source declaration is no security threat in this case.