You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mihamina Rakotomandimby <mi...@lab.vectoris.fr> on 2009/02/03 05:25:47 UTC

tomcat only query localhost database

Hi,
A developper gave me a .war webapp.
When deploying it, it creates an xml file:
/etc/tomcat6/Catalina/localhost/webappName.xml
which is a copy of the one in
/var/lib/tomcat6/webapps/webappName/META-INF/context.xml

Then context.xml file contains the JDBC/MySQL host,login,pass
where host is NOT localhost

But the tomcat insist to connect to localhost.

after deployment, if I change (after stopping RMI & tomcat)
the content of
/etc/tomcat6/Catalina/localhost/webappName.xml
to another host (then start RMI & tomcat) tomcat still use localhost as 
database host.

It's an Ubuntu tomcat6 packaged install.

Any help?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by Gregor Schneider <rc...@googlemail.com>.
On Wed, Feb 4, 2009 at 8:28 AM, Mihamina Rakotomandimby (R12y)
<mi...@lab.vectoris.fr> wrote:
>
> So, my deduction is the Linux tomcat6 has a setting that avoid reading
> Catalina/localhost/webappName.xml
>
can you specify the Linux-distribution / version?

In case you are using package-distribution (apt, yast etc.), it's
pretty likely that the packaged tomcat-installation uses different
folders for the tomcat-config

Rgds

Gregor
-- 
just because your paranoid, doesn't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available @ http://pgpkeys.pca.dfn.de:11371

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by "Mihamina Rakotomandimby (R12y)" <mi...@lab.vectoris.fr>.
After further investigations:

If I install a tomcat6 windows binary, and edit the
Catalina/localhost/webappName.xml file in order to use a different 
database host, it's OK: the Windows tomcat6 go and use the other database.

So, my deduction is the Linux tomcat6 has a setting that avoid reading
Catalina/localhost/webappName.xml

Any hints? I begin to cry :-)

-- 
Chef de projet chez Vectoris
http://www.google.com/search?q=mihamina+rakotomandimby

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by "Mihamina Rakotomandimby (R12y)" <mi...@lab.vectoris.fr>.
Mihamina Rakotomandimby (R12y) wrote:
> Mihamina Rakotomandimby (R12y) wrote:
>>> DriverManager.getConnection("jdbc:mysql://localhost/baseName",
>>>                                             "login",
>>>                                             "password");
>> There, I see some hardcoded localhost.
>> Might it be the nasty evil code?
> Nope, it's in a catch bloc, the app finds the database

I mean, it finds the localhost database I dont want it to find...


-- 
Chef de projet chez Vectoris
http://www.google.com/search?q=mihamina+rakotomandimby

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by "Mihamina Rakotomandimby (R12y)" <mi...@lab.vectoris.fr>.
Mihamina Rakotomandimby (R12y) wrote:
>> DriverManager.getConnection("jdbc:mysql://localhost/baseName",
>>                                             "login",
>>                                             "password");
> There, I see some hardcoded localhost.
> Might it be the nasty evil code?

Nope, it's in a catch bloc, the app finds the database and there's no
(localhost,baseName,login,password) on the area.



-- 
Chef de projet chez Vectoris
http://www.google.com/search?q=mihamina+rakotomandimby

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by "Mihamina Rakotomandimby (R12y)" <mi...@lab.vectoris.fr>.
Mihamina Rakotomandimby (R12y) wrote:
> DriverManager.getConnection("jdbc:mysql://localhost/baseName",
>                                             "login",
>                                             "password");

There, I see some hardcoded localhost.
Might it be the nasty evil code?

-- 
Chef de projet chez Vectoris
http://www.google.com/search?q=mihamina+rakotomandimby

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: tomcat only query localhost database

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Dave Pawson [mailto:dave.pawson@gmail.com]
> Subject: Re: tomcat only query localhost database
>
> What are(or where can I find them) the rules on loading an app into
> localhost | webapps or ROOT?

In the Tomcat docs:
http://tomcat.apache.org/tomcat-6.0-doc/config/index.html

Note that you have mixed up three different concepts in the above question: host, appBase, and a specific webapp.  A <Host> (localhost) specifies a domain name that Tomcat should be serving.  The appBase attribute (webapps) of the <Host> element specifies the default deployment directory for that <Host>'s webapps.  ROOT is the name of the default webapp for a given <Host>.

> the O'Reilly Tomcat book talks about using localhost where in 5.x I
> used to use webapps directory.

Read the Tomcat docs first; I haven't read the O'Reilly book, so I can't comment on its veracity, but I seriously doubt that it has confused such basic concepts.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by Dave Pawson <da...@gmail.com>.
2009/2/3 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Mihamina Rakotomandimby (R12y)
>> [mailto:mihamina@lab.vectoris.fr]
>> Subject: Re: tomcat only query localhost database
>>
>> /etc/tomcat6/Catalina/localhost/webappName.xml
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Context path="/norpassWeb"
>>                  reloadable="true"
>>                  docBase="norpassWeb" >
>
> Note that the path attribute is not allowed in a <Context> element placed in META-INF/context.xml or in Catalina/[host]/[appName].xml; at best you will get double deployment, at worst your webapp won't function at all.  The name of the .xml file is used as the path.
>
> Also, for webapps deployed under the <Host> appBase directory, which this appears to be, the docBase attribute is not allowed.


What are(or where can I find them) the rules on loading an app into
localhost | webapps or ROOT?

the O'Reilly Tomcat book talks about using localhost where in 5.x I
used to use webapps directory.

TIA



-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: tomcat only query localhost database

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Mihamina Rakotomandimby (R12y)
> [mailto:mihamina@lab.vectoris.fr]
> Subject: Re: tomcat only query localhost database
>
> /etc/tomcat6/Catalina/localhost/webappName.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <Context path="/norpassWeb"
>                  reloadable="true"
>                  docBase="norpassWeb" >

Note that the path attribute is not allowed in a <Context> element placed in META-INF/context.xml or in Catalina/[host]/[appName].xml; at best you will get double deployment, at worst your webapp won't function at all.  The name of the .xml file is used as the path.

Also, for webapps deployed under the <Host> appBase directory, which this appears to be, the docBase attribute is not allowed.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mihamina,

Mihamina Rakotomandimby (R12y) wrote:
>     catch(Exception e)
>         {
>             try
>                 {
>                     Class.forName("org.gjt.mm.mysql.Driver");
>                 }
>             catch (ClassNotFoundException e1)
>                 {
>                     e1.printStackTrace();
>                 }
> 
>             Connection con =
> 
> DriverManager.getConnection("jdbc:mysql://localhost/baseName",
>                                             "login",
>                                             "password");
>             con.setAutoCommit(false);
>             return con;
>         }


I know you said "it's in a catch block so it's not the problem, but I
think your statement makes too many assumptions: primarily, that nothing
else is going wrong. You aren't logging any Exceptions caught by that
catch block, so you'd never know that the standard way of getting the
connection (using JNDI) isn't working.

For instance, if your JNDI DataSource isn't set up properly (which is my
guess), your code falls-back to using a Connection obtained from the
DriverManager and points to localhost.

I would argue that this is a stupid way to handle exceptions in your
getConnection method, but who am I to judge?

Anyhow, I suspect that you DO have a problem in your JNDI configuration
and that your code IS falling-back on the localhost JDBC connection. The
fact that it works on another system probably means that you have JNDI
properly configured there.

Try adding some logging statements to that catch block and I think
you'll find that you are silently swallowing an exception and then
getting a localhost connection instead.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmLcMUACgkQ9CaO5/Lv0PA+xgCeOvylBPgCP154lzEURSQY63jI
V1IAni9VgFA7Pyu1AOME1rX16FPZLlYo
=fryH
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by "Mihamina Rakotomandimby (R12y)" <mi...@lab.vectoris.fr>.
Gregor Schneider wrote:
> Sorry, but you're providing too few informations.
> 
> - please post the file /etc/tomcat6/Catalina/localhost/webappName.xml
> (masquerade the user-id / password!)

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/norpassWeb"
                 reloadable="true"
                 docBase="norpassWeb" >

         <Resource name="jdbc/norpassDBPool"
                   auth="Container"
                   type="javax.sql.DataSource"
                   maxActive="100"
                   maxIdle="100"
                   maxWait="30000"
                   removeAbandoned="true"
                   removeAbandonedTimeout="20"
                   logAbandoned="true"
                   autoCommit="true"
                   username="xxxxxxxx"
                   password="yyyyyyyy"
                   driverClassName="org.gjt.mm.mysql.Driver"
         url="jdbc:mysql://77.88.777.999:3306/dbname?autoReconnect=true"
/>
</Context>


> - please post the piece of code where the said webapp tries to create
> the database-connection.

(A more readable version is attached)

public static Connection getConnection() throws SQLException
{
     try {
         if (null == s_dataSource)
             {
                 try
                     {
                         Context envCtx = (Context) new InitialContext();
                         if(envCtx == null )
                             throw new Exception("ERROR - No Context");
                         s_dataSource = (DataSource) 
envCtx.lookup("java:comp/env/jdbc/norpassDBPool");
                     }
                 catch (NamingException e)
                     {
                         e.printStackTrace();
                         throw e;
                     }
             }
         return s_dataSource.getConnection();
     }
     catch(Exception e)
         {
             try
                 {
                     Class.forName("org.gjt.mm.mysql.Driver");
                 }
             catch (ClassNotFoundException e1)
                 {
                     e1.printStackTrace();
                 }

             Connection con =
 
DriverManager.getConnection("jdbc:mysql://localhost/baseName",
                                             "login",
                                             "password");
             con.setAutoCommit(false);
             return con;
         }
}

-- 
Chef de projet chez Vectoris
http://www.google.com/search?q=mihamina+rakotomandimby

Re: tomcat only query localhost database

Posted by Gregor Schneider <rc...@googlemail.com>.
Sorry, but you're providing too few informations.

- please post the file /etc/tomcat6/Catalina/localhost/webappName.xml
(masquerade the user-id / password!)

- please post the piece of code where the said webapp tries to create
the database-connection.
should looke similar to

<code>
	    try {
		Context env = (Context) new InitialContext()
			.lookup("java:comp/env");
		dbDS = (DataSource) env.lookup(dataSourceName);
		if (dbDS == null) {
		    logger.error("seems that '" + dataSourceName
			    + "' is an unknown DataSource");
		    throw new ServletException("'" + dataSourceName
			    + "' is an unknown DataSource");
		}
	    } catch (NamingException e) {
		logger.error("Exception caught:", e);
		throw new ServletException(e);
	    }
</code>

My guess is, that within the app's code, the connection to the
database is not established to the said datasource but that somewhere
"localhost" is hardcoded.... *sic*

So have a chat with the webapp-developer and let us have a look at the code.

Rgds

Gregor
-- 
just because your paranoid, doesn't mean they're not after you...
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available @ http://pgpkeys.pca.dfn.de:11371

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat only query localhost database

Posted by "Mihamina Rakotomandimby (R12y)" <mi...@lab.vectoris.fr>.
Mihamina Rakotomandimby wrote:

> Any help?

I suspect there is a system-wide configuration that tells not to 
consider the webapp-specific configuration, but I dont find where...

-- 
Chef de projet chez Vectoris
http://www.google.com/search?q=mihamina+rakotomandimby

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org