Skip to Content

Tomcat without global resource

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Jul 30, 2020 at 09:32 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Apr 07, 2020 at 09:33 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.