Need two services that share database in Tomcat 9 - database

I would like to run two tomcat services on two ports (8080,8181) with different codeBases, but sharing the same database resource. When I do this, I get "javax.naming.NameNotFoundException: Name [comp/env/jdbc/mydb] is not bound in this Context. Unable to find [comp]." when it tries to initialize the second Service.
My Services look like this in the server.xml:
...
<GlobalNamingResources>
<Resource auth="Container" name="jdbc/mydb" url="jdbc:db2://myserver:50000/mydb" username="xxx" password="xxx" .... />
</GlobalNamingResources>
...
<Service name="Catalina8080">
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
....
<Host name="localhost" appBase="webapps8080" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" .... />
</Host>
</Engine>
</Service>
<Service name="Catalina8181">
<Connector port="8181" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444" />
<Engine name="Catalina" defaultHost="localhost">
....
<Host name="localhost" appBase="webapps8181" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" .... />
</Host>
</Engine>
</Service>
My server level context file looks like :
<Context>
...
<ResourceLink name="jdbc/mydb" global="jdbc/mydb" type="javax.sql.DataSource" />
</Context>
I've tried adding and removing the Resource links at the application level context file, but nothing seems to change the outcome. Any thoughts are greatly appreciated.

You should change the name of your <Engine> in the second service: there can be only one naming context for each combination of engine name, host name and context name.
In your case the combination (Catalina, localhost, your application name) probably appears twice, hence you should be able to find an entry like this:
SEVERE [main] naming.namingContextCreationFailed
in the logs and JNDI doesn't work in the second context.

Related

Can't insert into SQL Server table with log4net AdoNetAppender

I am trying to understand how log4net works so I've added this to my app.config (I should add that Console Appender and FileAppender work perfectly, I only have trouble with the AdoNetAppender).
How can I debug this, to see if at least the connection to db succeeds?
The problem is the INSERT statement isn't executed.
I should add the
Data Source=MyWorkgroup\SQLEXPRESS;Initial Catalog=MyNewDatabase;User ID=juan;password=juan,
works perfectly when I try to connect to SQL Server manually, so not sure if that's the problem.
Also, the ConnectionType was taken from the official site:
https://logging.apache.org/log4net/log4net-1.2.11/release/sdk/log4net.Appender.AdoNetAppender.ConnectionType.html
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.log4netConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="AdoNetAppender"
type="log4net.Appender.AdoNetAppender">
<bufferSize value="10" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=MyWorkgroup\SQLEXPRESS;Initial Catalog=MyNewDatabase;User ID=juan;Password=juan;Pooling=False" />
<commandText value="INSERT INTO Logs([logDate],[logThread],[logMessage]) VALUES(getdate(),'1','1')" />
<commandType value="Text" />
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="AdoNetAppender"/>
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Later edit (after using the debug method recommended by David):
haacked.com is indeed extremely interesting, great tip! However, it seems that it's describing what I'm instructing log4net to log, but not the result of those actions(?), if I'm reading this well (no failed/or succeeded?)
e.g.
log4net: Setting Property [ConnectionType] to String value
[System.Data.SqlClien t.SqlConnection, System.Data,
Version=1.0.3300.0, Culture=neutral, PublicKeyToke n=b77a5c561934e089]
log4net: Setting Property [ConnectionString] to String value [Data
Source=MyWorkgroup\SQLEXPRESS; Initial
Catalog=MyNewDatabase;
User ID=juan; Password=juan;
Pooling=False] log4net: Setting Property [CommandText] to String value [INSERT INTO Logs([logDate],[logThread],[logMessage]) VALUES(getdate(),'1','1')] log4net:
Setting Property [CommandType] to CommandType value [Text] log4net:
Created Appender [AdoNetAppender] log4net: Adding appender named
[AdoNetAppender] to logger [root]. log4net: Hierarchy Threshold []
Piece of code that helped me obtain this info (in case the site should become unavailable) is:
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\temp\log4netdiagn.txt" />
</listeners>
</trace>
</system.diagnostics>

Different loops in tsung

Could someone please advise me what's the main difference between loops like for and <load loop="">?
I've figured out strange behavior.
I have the config file:
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="debug" dumptraffic="true" version="1.0">
<clients>
<client host="localhost" use_controller_vm="true" maxusers="1"/>
</clients>
<servers>
<server host="example.com" port="443" type="ssl"/>
</servers>
<load loop="100" duration="2" unit="minute">
<arrivalphase phase="1" duration="1" unit="second">
<users maxnumber="1" arrivalrate="1" unit="second"/>
</arrivalphase>
</load>
<sessions>
<session name="one" type="ts_http" probability="100">
<request>
<http url='/Service.asmx' version='1.0' contents_from_file="/home/user/file.xml" content_type='text/xml; charset=UTF-8' method='POST'>
<soap action="Retrieve"/>
</http>
</request>
</session>
</sessions>
</tsung>`
It produces about 1900 requests during the load process.
But if I remove the attribute loop="100" from the <load> tag and add the for loop the number of requests decreases to 70 requests. In this case the config file looks like so:
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="debug" dumptraffic="true" version="1.0">
<clients>
<client host="localhost" use_controller_vm="true" maxusers="1"/>
</clients>
<servers>
<server host="example.com" port="443" type="ssl"/>
</servers>
<load duration="2" unit="minute">
<arrivalphase phase="1" duration="1" unit="second">
<users maxnumber="1" arrivalrate="1" unit="second"/>
</arrivalphase>
</load>
<sessions>
<session name="one" type="ts_http" probability="100">
<for var="counter" from="1" to="100" incr="1">
<request>
<http url='/Service.asmx' version='1.0' contents_from_file="/home/user/file.xml" content_type='text/xml; charset=UTF-8' method='POST'>
<soap action="Retrieve"/>
</http>
</request>
</for>
</session>
</sessions>
</tsung>
Besides it creates 61 sessions, though the <client maxusers="1"/> and <users maxnumber="1"/> attributes doesn't change. Here's the screenshot of both reports: enter link description here
Why does it work in different ways? Logically they should work identically, just repeat the sequence of requests.
Loop on load section will generate new users, so new sessions, cookies and all users related. Loop inside a session will re-use same users.

DotCMS Connecting to the database

I downloaded dotcms_2.3.2.zip
I have followed this documentation http://dotcms.com/docs/latest/InstallingFromRelease
I changed the url, username and password in ROOT.xml
MSSQL
<Resource name="jdbc/dotCMSPool" auth="Container"
type="javax.sql.DataSource" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:jtds:sqlserver://servername:portnumber/databasename"
username="{xxxxx}" password="{xxxxx}" maxActive="60" maxIdle="10" maxWait="60000"
removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
testOnBorrow="true" validationQuery="SELECT 1" defaultTransactionIsolation="READ_COMMITTED"/>
</Context>
And in server.xml i changed port to 8080
<Connector maxThreads="75" connectionTimeout="3000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
And the main problem is I cant connect the ms sql database to dotCMS because when I go to localhost:8080/admin/ link does work.
Any help?
Maybe,
username="{xxxxx}" password="{xxxxx}"
should look like
username="xxxxx" password="xxxxx"
(without curly braces).

mod_jk not working with apache2.4 and tomcat7

linux
tomcat 7
apache 2.4
We already have tomcat6 and apache2.2 working on this server. I am attempting to get the newer versions running for out next project. Apache2.4 is working and listening on port 1904. Tomcat is working and listening on port 8081. The AJP is set to 8010.
I have compiled mod_jk against the apache server and it created the mod_jk.so file. I copied the file over to the modules folder.
My workers.properties
worker.list=worker3
worker.myworker.type=ajp13
worker.myworker.host=localhost
worker.myworker.port=8010
My http.conf has:
LoadModule jk_module modules/mod_jk.so
<IfModule jk_module>
Include conf/extra/mod_jk.conf
</IfModule>
The mod_jk.conf is in that directory and contains:
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkShmFile logs/jk-runtime-status
JkLogStampFormat "[%b %d %Y - %H:%M:%S] "
JkRequestLogFormat "%w %V %T"
JkAutoAlias /usr/local/tomcat7/webapps
JkMountCopy All
JkMount /* worker3
JkUnMount /cgi-bin/* worker3
JkUnMount /htdocs/* worker3
server.xml is:
<?xml version='1.0' encoding='utf-8'?>
<Server port="8015" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8444" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8444" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
I am under the assumption I should be able to goto [server]:1904/examples and get the same thing that I get when I goto [server]:8081/examples.
As another peice of configuration info I do have a xml file in tomcathome/conf/Catalina/localhost named srvc.xml
<Context path="" docBase="/usr/local/tomcat7/web"/>
This works when addressing the tomcat server. Thanks for eyeballing all this and for any help if provided.
Finally, found it with the help of a coworker. The worker.properties needs to look like:
worker.list=worker3
worker.worker3.type=ajp13
worker.worker3.host=localhost
worker.worker3.port=8010
The original had worker.myworker.type and so on.

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

Hi
When I try to connect to the datasource using JNDI, I am getting this error:
[org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.apache.roller.weblogger.business.DatabaseProvider.getConnection(DatabaseProvider.java:179)
at org.apache.roller.weblogger.business.DatabaseProvider.<init>(DatabaseProvider.java:141)
at org.apache.roller.weblogger.business.startup.WebloggerStartup.prepare(WebloggerStartup.java:171)
at org.apache.roller.weblogger.ui.core.RollerContext.contextInitialized(RollerContext.java:138)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
at java.sql.DriverManager.getDriver(DriverManager.java:253)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 30 more]
Context.xml
<Context path="/roller" docBase="c:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\roller" debug="0">
<Resource name="jdbc/rollerdb" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/rollerdb?autoReconnect=true&useUnicode=true&characterEncoding=utf8-&mysqlEncoding=utf8"
username="roller_user"
password="password"
maxActive="20" maxIdle="3" removeAbandoned="true"
maxWait="3000"
/>
<Resource name="mail/Session"
auth="Container"
type="javax.mail.Session"
username="username#gmail.com"
password="password"
mail.debug="false"
mail.user="username#gmail.com"
mail.password="password"
mail.smtp.from="username#gmail.com"
mail.transport.protocol="smtp"
mail.smtp.port="465"
mail.smtp.host="smtp.gmail.com"
mail.smtp.auth="true"
mail.smtp.starttls.enable="true"
mail.smtp.socketFactory.port="465"
mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
mail.smtp.socketFactory.fallback="false"
/>
</Context>
web.xml
<web-app .. >
...
<!-- jndi resources -->
<resource-ref>
<res-ref-name>jdbc/rollerdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
roller-custom.properties
installation.type=auto
database.configurationType=jndi
database.jndi.name=jdbc/rollerdb
mail.configurationType=jndi
mail.jndi.name=mail/Session
I've got mysql-connector-java-5.1.15-bin.jar, activation.jar and mail.jar in tomcat's lib diectory and the web application roller in tomcat's webapps folder.
I've not been able to understand what I am doing wrong here. Could someone help me understand what am I missing here?
Thanks.
Thanks.
I just got through a similar error and it turns out my context.xml file was slightly mangled. I think this most likely is where the problem resides.
My suggestion in comparing context.xml files between myself and you, I say try this
driverClass
In place of
driverClassName
I've solved this problem changing the import reference (in my case) from:
import org.apache.tomcat.dbcp.dbcp.BasicDataSource;
to
import org.apache.commons.dbcp.BasicDataSource;
My error was generated because I always use CRTL+o for import references, and when I made the import I had not the .jar in my references.
I hope this may be useful for others.
You could also encounter this error if your Tomcat version is different ..then ur context.xml would have to look different ...for detail go to this page ..a must read for this problem :
http://www.crazysquirrel.com/computing/java/connection-pooling.jspx
regs
Karthic
In my case helped following changes: in APPLICATION_PATH/WebContent/META_INF/context.xml
old code:
<resource name="jdbc/internships_db" auth="Container" type="javax.sql.DataSource">
<param name="username" value="my_user" />
<param name="password" value="my_password" />
<param name="url" value="jdbc:mysql://localhost:3306/internships_db" />
</resource>
new code:
<Resource name="jdbc/internships_db"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
username="my_user"
maxWait="10000"
driverClassName="com.mysql.jdbc.Driver"
password="my_password"
url="jdbc:mysql://localhost:3306/internships_db"/>
Jdbc-Driver class is placed under the path
/user_path/tomcat-instance_path/webapps/app_name/WEB-INF/lib/com.mysql.jdbc_5.1.5.jar

Resources