You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Krapacs Ambrose <ak...@gmail.com> on 2008/11/18 13:21:46 UTC

Servlets / JSP can't connect to MySQL in Ubuntu Server

I have tried many different configurations and I have been unable to  
get my Servlets / JSP to connect to MySQL server running. I am trying  
to get this set up on my main server which is running Ubuntu 8.10  
Server with MySQL 5 and Tomcat6. I also tried setting up a Ubuntu 8.04  
server with Tomcat 5.5 and MySQL 5. I have even configured Tomcat  
running on the 8.10 server to try to connect to MySQL running on the  
8.04 server. Still no luck!

The exception that is thrown is here:
	com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:  
Communications link failure
Last packet sent to the server was 0 ms ago.(jdbc:mysql://localhost? 
user=invuser&password=admin))
	 
org 
.apache 
.jasper 
.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
	org.apache.jasper.runtime.PageContextImpl.access 
$1100(PageContextImpl.java:71)
	org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java: 
768)
	java.security.AccessController.doPrivileged(Native Method)
	 
org 
.apache 
.jasper 
.runtime.PageContextImpl.handlePageException(PageContextImpl.java:766)
	org.apache.jsp.install_jsp._jspService(install_jsp.java:141)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	 
org 
.apache 
.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: 
342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	 
sun 
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
57)
	 
sun 
.reflect 
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 
43)
	java.lang.reflect.Method.invoke(Method.java:616)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:537)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java: 
276)
	 
org 
.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java: 
162)
I have verified that MySQL is running and everything with Tomcat seems  
to be configured correctly because I can execute servlets and JSP just  
fine it's just the connections to MySql to that fail. I have also  
executed a standalone java application using the MySQL Connector/J and  
that worked fine. I've even tried different ways of deploying the  
MySql Connector/J (which is the newest version available) to see if it  
was a permissions problem with the library.
The key to this is that the web applications that I am trying to  
deploy run flawlessly on my Mac OS X development machine with MySQL. I  
haven't tried Windows yet but if I can get this set up to host my web  
application I may have to set up a Windows machine to try it.

Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Ambrose Krapacs <ak...@gmail.com>.
On Nov 19, 2008, at 11:13 , David Smith wrote:

> If you have command line access on the system, can you test your MySQL
> connectivity by connecting this way?:
>
> mysql -u inventory -h localhost -p
>
> The -h option forces mysql command to connect via TCP/IP instead of  
> unix
> sockets.
>
> --David

Yes I can log into mysql using the command terminal fro the system and  
specifying the -h parameter. Again, my test using the standard j2se  
application to connect to MySQL using the JDBC connector proves that  
the problem does not have to do with MySQL.

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by David Smith <dn...@cornell.edu>.
If you have command line access on the system, can you test your MySQL
connectivity by connecting this way?:

mysql -u inventory -h localhost -p

The -h option forces mysql command to connect via TCP/IP instead of unix
sockets.

--David

Ambrose Krapacs wrote:
>
> On Nov 18, 2008, at 7:58 , David Smith wrote:
>
>> Can you post your database config and code snippet for accessing the
>> db?  Obfuscate the username/password info.
>>
>> One immediate observation is the JDBC url should have the name of the
>> database you are trying to access like this:
>>
>> jdbc:mysql://localhost/myDatabase?user= ....
>>
>> --David
>>
>> <TRIMMED>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
>
> Here is the test JSP page that I have been using to test multiple
> urls. On my OS X machine they all pass and on the Ubuntu machine they
> all fail with the CommunicationException. As for the url without the
> database, my application attempts to connect to the specific database
> and if that fails it will then try to connect without the database
> specified in the url so it can create the database. Therefore, the
> connection to the url database is only attempted after the connection
> to the url with the database has failed. This method seems to work
> flawlessly on my OS X machine so I dont think that it should cause a
> problem. You will see in my test JSP though, that I'm trying multiple
> different url variations and they all fail with the exact same exception.
>
> <%--
>     Document   : index
>     Created on : Nov 16, 2008, 1:19:22 PM
>     Author     : ambrose
> --%>
>
> <%@page contentType="text/html" pageEncoding="UTF-8"%>
>
> <%@page import="java.sql.*" %>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>    "http://www.w3.org/TR/html4/loose.dtd">
>
> <html>
>     <head>
>         <meta http-equiv="Content-Type" content="text/html;
> charset=UTF-8">
>         <title>JSP Page</title>
>     </head>
>     <body>
>
>         <%
>
>             Class.forName("com.mysql.jdbc.Driver").newInstance();
>
>             String[] url = new String[] {
> "jdbc:mysql://localhost/testdb?user=inventory&password=password",
>                                          
> "jdbc:mysql://localhost/testdb?user=root&password=admin",
>                                          
> "jdbc:mysql://127.0.0.1/testdb?user=inventory&password=password",
>                                          
> "jdbc:mysql://127.0.0.1/testdb?user=root&password=admin",
>                                          
> "jdbc:mysql://localhost:3306/testdb?user=inventory&password=password",
>                                          
> "jdbc:mysql://localhost:3306/testdb?user=root&password=admin",
>                                          
> "jdbc:mysql://127.0.0.1:3306/testdb?user=inventory&password=password",
>                                          
> "jdbc:mysql://127.0.0.1:3306/testdb?user=root&password=admin",
>
>                                          
> "jdbc:mysql://localhost?user=inventory&password=password",
>                                          
> "jdbc:mysql://localhost?user=root&password=admin",
>                                          
> "jdbc:mysql://127.0.0.1?user=inventory&password=password",
>                                          
> "jdbc:mysql://127.0.0.1?user=root&password=admin",
>                                          
> "jdbc:mysql://localhost:3306?user=inventory&password=password",
>                                          
> "jdbc:mysql://localhost:3306?user=root&password=admin",
>                                          
> "jdbc:mysql://127.0.0.1:3306?user=inventory&password=password",
>                                          
> "jdbc:mysql://127.0.0.1:3306?user=root&password=admin",
>
>                                          
> "jdbc:mysql://localhost/?user=inventory&password=password",
>                                          
> "jdbc:mysql://localhost/?user=root&password=admin",
>                                          
> "jdbc:mysql://127.0.0.1/?user=inventory&password=password",
>                                          
> "jdbc:mysql://127.0.0.1/?user=root&password=admin",
>                                          
> "jdbc:mysql://localhost:3306/?user=inventory&password=password",
>                                          
> "jdbc:mysql://localhost:3306/?user=root&password=admin",
>                                          
> "jdbc:mysql://127.0.0.1:3306/?user=inventory&password=password",
>                                          
> "jdbc:mysql://127.0.0.1:3306/?user=root&password=admin",
>
>                                          
> "jdbc:mysql:///?user=inventory&password=password",
>                                          
> "jdbc:mysql:///testdb?user=inventory&password=password"
>                                         };
>
>             for( int i = 0; i < url.length; i++ )
>             {
>                 String retVal = openConnection(url[i]);
>
>                 if( retVal == null )
>                 {
>                     out.write("Successful: " + url[i] + "<br/>");
>                 }
>                 else
>                 {
>                     out.write("Failed: " + url[i] + "(" + retVal +
> ")<br/>");
>                 }
>             }
>
>         %>
>
>         <%!
>         public String openConnection(String url)
>         {
>             String retVal = null;
>             Connection c = null;
>             try
>             {
>                 c = DriverManager.getConnection(url);
>             }
>             catch( Exception e )
>             {
>                 retVal = e.toString();
>             }
>             finally
>             {
>                 if( c != null )
>                 {
>                     try
>                     {
>                         c.close();
>                     }
>                     catch( Exception e ) {}
>                 }
>             }
>
>             return retVal;
>         }
>         %>
>     </body>
> </html>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Ambrose Krapacs <ak...@gmail.com>.
On Nov 20, 2008, at 10:30 , Christopher Schultz wrote:
>
> Len is absolutely right: the exception is being thrown by MySQL, so  
> it's
> their error message. Was there a "root cause" printed with this stack
> trace? That certainly would have helped.
>
> I checked the source for Connector/J 5.1.6 and that exception is only
> thrown in a single place: SQLError.java:1070. When that exception is
> created, the underlying exception is, in fact, passed up to
> java.lang.Throwable via the initCause method. So, there should have  
> been
> a "caused by" line in that stack trace.

I hadn't thought about the MSQL connector consuming the exception and  
then throwing one of its own. Now this make perfect sense.

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

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

All,

Christopher Schultz wrote:
> There was (from your original post):
> 
>>     com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Steps to reproduce this conclusion:

1. Turn off brain.
2. Open mouth.

Sorry about that. I spouted complete nonsense in that last post. The
exception was being thrown within the doHandlePageException method,
which is pretty much where it will always be thrown, no matter what.

Len is absolutely right: the exception is being thrown by MySQL, so it's
their error message. Was there a "root cause" printed with this stack
trace? That certainly would have helped.

I checked the source for Connector/J 5.1.6 and that exception is only
thrown in a single place: SQLError.java:1070. When that exception is
created, the underlying exception is, in fact, passed up to
java.lang.Throwable via the initCause method. So, there should have been
a "caused by" line in that stack trace.

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

iEYEARECAAYFAkklgpgACgkQ9CaO5/Lv0PC1/ACcCSetD4FrO8FIHLFSCd/WGdbl
4OIAn0V6fdrx8C7tbnv+AnnqgcvEM+Iq
=cBJ4
-----END PGP SIGNATURE-----

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Ambrose Krapacs <ak...@gmail.com>.
On Nov 20, 2008, at 10:15 , Christopher Schultz wrote:
>
> SecurityManagers are such a pain in the ass IMO. If you're writing  
> your
> own applications and deploying them yourself, I say give up on the
> SecurityManager because you're not protecting yourself from anyone but
> yourself. SecurityManagers are best used when either untrusted or
> partially-trusted code will be running in your Tomcat instance. I'm  
> sure
> a lot of folks will disagree with me on this one, but the
> SecurityManager is more trouble than it's worth if you ask me.
>

Yea I have been reading more about the SecurityManager and I think  
that I will probably go without the security manager enabled since  
this server is only going to be running this particular application  
and I am the only one that is going to be maintaining it.

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

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

Krapacs,

Krapacs Ambrose wrote:
> I have to say that I do not think Tomcat is doing the right thing in
> this particular situation. There should be some sort of security
> exception being thrown indicating that the socket connection was being
> block by tomcat's security manager.

There was (from your original post):

>     com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
> Last packet sent to the server was 0 ms ago.(jdbc:mysql://localhost?user=invuser&password=admin))
>     org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
>     org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:71)
>     org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:768)
>     java.security.AccessController.doPrivileged(Native Method)
>     org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:766)
>     org.apache.jsp.install_jsp._jspService(install_jsp.java:141)
>     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
>     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
>     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>     java.lang.reflect.Method.invoke(Method.java:616)
>     org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
>     java.security.AccessController.doPrivileged(Native Method)
>     javax.security.auth.Subject.doAsPrivileged(Subject.java:537)
>     org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
>     org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

Note the "CommunicationsException" being thrown from the doAsPrivilege()
method: that's a dead giveaway that it's a security error (at least to
those of us who have seen them before). You're right: the error message
could have been a bit better, but it's no shock that's what happened.

> I did play around a little bit with
> the policy files in my /var/lib/tomcat6/conf/policy.d directory and I
> believe I found where I need to do this because I found an example
> policy very similar to what you suggested. I got it to work without too
> much trouble but then I ran into other security problems with my
> application reading and writing files within its WEB-INF directory so I
> will have to spend some more time with the tomcat docs and figure out
> what permissions my application requires. After days of troubleshooting
> this I'm more than happy with turning off the security manager and
> spending some time learning how to actually configure it properly.

SecurityManagers are such a pain in the ass IMO. If you're writing your
own applications and deploying them yourself, I say give up on the
SecurityManager because you're not protecting yourself from anyone but
yourself. SecurityManagers are best used when either untrusted or
partially-trusted code will be running in your Tomcat instance. I'm sure
a lot of folks will disagree with me on this one, but the
SecurityManager is more trouble than it's worth if you ask me.

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

iEYEARECAAYFAkklfwAACgkQ9CaO5/Lv0PA5JQCglwxr+H2oT9nofNh9531p82r8
EMoAoLmNKRJGM/1GC7prMzgOYtNOr2Dz
=Wkon
-----END PGP SIGNATURE-----

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Len Popp <le...@gmail.com>.
On Thu, Nov 20, 2008 at 07:37, Krapacs Ambrose <ak...@gmail.com> wrote:
> I have to say that I do not think Tomcat is doing the right thing in this
> particular situation. There should be some sort of security exception being
> thrown indicating that the socket connection was being block by tomcat's
> security manager.

Unfortunately, the exception is coming from MySQL, not Tomcat, and
it's a MySQL exception type, not the standard SecurityException.
There's no way for Tomcat to know that this particular exception was
caused by a SecurityManager violation.
-- 
Len

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by André Warnier <aw...@ice-sa.com>.
Krapacs Ambrose wrote:
[...]
> 
> I have to say that I do not think Tomcat is doing the right thing in 
> this particular situation. There should be some sort of security 
> exception being thrown indicating that the socket connection was being 
> block by tomcat's security manager. 

Indeed. I was a bit surprised also that this turned out to be the 
problem, because it seems to me that when I had similar issues in the 
past (due to the security manager), the exception in the logfile did say 
clearly that it was due to a permission problem.
But your own logfile did not.
Maybe the JDBC driver is catching the original exception and showing it 
as something else ? (I don't know this stuff enough to be sure of that, 
but I imagine it's possible).



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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Krapacs Ambrose <ak...@gmail.com>.
On Nov 20, 2008, at 5:16 , André Warnier wrote:

> So, you see, in the end it was a TCP/IP connection issue.
> But it was not at the level of your MySQL server, but at the  
> source : your JVM would not let your webapp do a "connect" to that  
> port.
>
> Now here comes a complication : finding where in the configuration  
> you need to change this thing.
> That depends a bit on where you got your Tomcat from.
> In the end, you should find a file named like "(tomcat_dir)/conf/ 
> catalina.policy", which contains the permissions given to different  
> webapps.
> You should find enough examples in there to guess what you need to  
> add to make it work. (*)
> But, the file "catalina.policy" may be a file that is re-created  
> each time you start Tomcat, from bits and pieces located somewhere  
> else.
> So check you Tomcat startup script carefully, and see whether it is  
> doing something like that.  It may be that different bits related to  
> permissions are located in a series of files under /etc/tomcat/ 
> policy.d for example.  If so, then add  a new file there, with the  
> required permissions, and it will be picked up and concatenated with  
> the others at the next startup, into a new catalina.policy file.
> (And re-enable the security manager of course).
>
> Maybe someone else will want to comment on the usefulness criteria  
> of the security manager.  It does slow things down, so you may not  
> necessarily want to enable it.
>
>
>
> (*) something like :
> grant codeBase "file:/var/lib/tomcat/webapps/yourwebapp/WEB-INF/ 
> classes/-" {
>      permission java.net.SocketPermission "localhost",  
> "connect,resolve";
>      permission java.net.SocketPermission "*:3636", "connect,resolve";
> };
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

I have to say that I do not think Tomcat is doing the right thing in  
this particular situation. There should be some sort of security  
exception being thrown indicating that the socket connection was being  
block by tomcat's security manager. I did play around a little bit  
with the policy files in my /var/lib/tomcat6/conf/policy.d directory  
and I believe I found where I need to do this because I found an  
example policy very similar to what you suggested. I got it to work  
without too much trouble but then I ran into other security problems  
with my application reading and writing files within its WEB-INF  
directory so I will have to spend some more time with the tomcat docs  
and figure out what permissions my application requires. After days of  
troubleshooting this I'm more than happy with turning off the security  
manager and spending some time learning how to actually configure it  
properly.

Thanks again!
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by André Warnier <aw...@ice-sa.com>.
Krapacs Ambrose wrote:
> 
> Well I thought that I had tried turning off the security manager but I 
> couldn't remember how I did it. I tried again by modifying 
> /etc/init.d/tomcat and set TOMCAT_SECURITY to "no". I executed the JSP 
> again and EVERY TEST SUCCESSFULLY CONNECTED! Wow, finally!
> 
> So now I guess I need to determine the proper way to do this because I'm 
> guessing that disabling the security mangager is not smart. I really do 
> not know anything about the tomcat security  manager so I'm not sure how 
> to properly allow this in security  manager without disabling it 
> completely.
> 
So, you see, in the end it was a TCP/IP connection issue.
But it was not at the level of your MySQL server, but at the source : 
your JVM would not let your webapp do a "connect" to that port.

Now here comes a complication : finding where in the configuration you 
need to change this thing.
That depends a bit on where you got your Tomcat from.
In the end, you should find a file named like 
"(tomcat_dir)/conf/catalina.policy", which contains the permissions 
given to different webapps.
You should find enough examples in there to guess what you need to add 
to make it work. (*)
But, the file "catalina.policy" may be a file that is re-created each 
time you start Tomcat, from bits and pieces located somewhere else.
So check you Tomcat startup script carefully, and see whether it is 
doing something like that.  It may be that different bits related to 
permissions are located in a series of files under /etc/tomcat/policy.d 
for example.  If so, then add  a new file there, with the required 
permissions, and it will be picked up and concatenated with the others 
at the next startup, into a new catalina.policy file.
(And re-enable the security manager of course).

Maybe someone else will want to comment on the usefulness criteria of 
the security manager.  It does slow things down, so you may not 
necessarily want to enable it.



(*) something like :
grant codeBase "file:/var/lib/tomcat/webapps/yourwebapp/WEB-INF/classes/-" {
       permission java.net.SocketPermission "localhost", "connect,resolve";
       permission java.net.SocketPermission "*:3636", "connect,resolve";
};

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Krapacs Ambrose <ak...@gmail.com>.
On Nov 19, 2008, at 14:53 , Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Ambrose,
>
> Ambrose Krapacs wrote:
>>            catch( Exception e )
>>            {
>>                retVal = e.toString();
>>            }
>
> And this gives you "CommunicationLinkFailure" for every URL you are  
> trying?
>
> A few things about the URLs:
>
> 1. Don't bother testing 127.0.0.1 /and/ "localhost". If your machine
> hasn't been misconfigured, "localhost" should point to 127.0.0.1.
>
> 2. You must specify the name of a database, so URLs like
>   jdbc:mysql://localhost?foo=bar are malformed.
>
> 3. Consider picking a single username/password and sticking with it.
>   If you can't open a connection, the use of multiple sets of
>   credentials is just complicating your script and gathering excess
>   (useless) data.
>
> 4. The default port is 3306, so you don't need to specify it in your
>   URLs.
>
> Are you running Tomcat under a security manager? That would certainly
> prevent you from communicating. Can you use 'ps' to show us the  
> command
> line that is being used to start Tomcat? That would help.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkkkbtMACgkQ9CaO5/Lv0PAYHgCePuPp3zaFS5DzTWPZkWztE0f5
> sx8An3YE1nwEsX3Sadmq4qBwsSPFS2Q1
> =EI1G
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

Well I thought that I had tried turning off the security manager but I  
couldn't remember how I did it. I tried again by modifying /etc/init.d/ 
tomcat and set TOMCAT_SECURITY to "no". I executed the JSP again and  
EVERY TEST SUCCESSFULLY CONNECTED! Wow, finally!

So now I guess I need to determine the proper way to do this because  
I'm guessing that disabling the security mangager is not smart. I  
really do not know anything about the tomcat security  manager so I'm  
not sure how to properly allow this in security  manager without  
disabling it completely.

Thanks Christopher!

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

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

Ambrose,

Ambrose Krapacs wrote:
>             catch( Exception e )
>             {
>                 retVal = e.toString();
>             }

And this gives you "CommunicationLinkFailure" for every URL you are trying?

A few things about the URLs:

1. Don't bother testing 127.0.0.1 /and/ "localhost". If your machine
hasn't been misconfigured, "localhost" should point to 127.0.0.1.

2. You must specify the name of a database, so URLs like
   jdbc:mysql://localhost?foo=bar are malformed.

3. Consider picking a single username/password and sticking with it.
   If you can't open a connection, the use of multiple sets of
   credentials is just complicating your script and gathering excess
   (useless) data.

4. The default port is 3306, so you don't need to specify it in your
   URLs.

Are you running Tomcat under a security manager? That would certainly
prevent you from communicating. Can you use 'ps' to show us the command
line that is being used to start Tomcat? That would help.

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

iEYEARECAAYFAkkkbtMACgkQ9CaO5/Lv0PAYHgCePuPp3zaFS5DzTWPZkWztE0f5
sx8An3YE1nwEsX3Sadmq4qBwsSPFS2Q1
=EI1G
-----END PGP SIGNATURE-----

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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Ambrose Krapacs <ak...@gmail.com>.
On Nov 18, 2008, at 7:58 , David Smith wrote:

> Can you post your database config and code snippet for accessing the
> db?  Obfuscate the username/password info.
>
> One immediate observation is the JDBC url should have the name of the
> database you are trying to access like this:
>
> jdbc:mysql://localhost/myDatabase?user= ....
>
> --David
>
> <TRIMMED>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


Here is the test JSP page that I have been using to test multiple  
urls. On my OS X machine they all pass and on the Ubuntu machine they  
all fail with the CommunicationException. As for the url without the  
database, my application attempts to connect to the specific database  
and if that fails it will then try to connect without the database  
specified in the url so it can create the database. Therefore, the  
connection to the url database is only attempted after the connection  
to the url with the database has failed. This method seems to work  
flawlessly on my OS X machine so I dont think that it should cause a  
problem. You will see in my test JSP though, that I'm trying multiple  
different url variations and they all fail with the exact same  
exception.

<%--
     Document   : index
     Created on : Nov 16, 2008, 1:19:22 PM
     Author     : ambrose
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="java.sql.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
     <head>
         <meta http-equiv="Content-Type" content="text/html;  
charset=UTF-8">
         <title>JSP Page</title>
     </head>
     <body>

         <%

             Class.forName("com.mysql.jdbc.Driver").newInstance();

             String[] url = new String[] { "jdbc:mysql://localhost/ 
testdb?user=inventory&password=password",
                                           "jdbc:mysql://localhost/ 
testdb?user=root&password=admin",
                                           "jdbc:mysql://127.0.0.1/ 
testdb?user=inventory&password=password",
                                           "jdbc:mysql://127.0.0.1/ 
testdb?user=root&password=admin",
                                           "jdbc:mysql://localhost: 
3306/testdb?user=inventory&password=password",
                                           "jdbc:mysql://localhost: 
3306/testdb?user=root&password=admin",
                                           "jdbc:mysql:// 
127.0.0.1:3306/testdb?user=inventory&password=password",
                                           "jdbc:mysql:// 
127.0.0.1:3306/testdb?user=root&password=admin",

                                           "jdbc:mysql://localhost? 
user=inventory&password=password",
                                           "jdbc:mysql://localhost? 
user=root&password=admin",
                                           "jdbc:mysql://127.0.0.1? 
user=inventory&password=password",
                                           "jdbc:mysql://127.0.0.1? 
user=root&password=admin",
                                           "jdbc:mysql://localhost: 
3306?user=inventory&password=password",
                                           "jdbc:mysql://localhost: 
3306?user=root&password=admin",
                                           "jdbc:mysql:// 
127.0.0.1:3306?user=inventory&password=password",
                                           "jdbc:mysql:// 
127.0.0.1:3306?user=root&password=admin",

                                           "jdbc:mysql://localhost/? 
user=inventory&password=password",
                                           "jdbc:mysql://localhost/? 
user=root&password=admin",
                                           "jdbc:mysql://127.0.0.1/? 
user=inventory&password=password",
                                           "jdbc:mysql://127.0.0.1/? 
user=root&password=admin",
                                           "jdbc:mysql://localhost: 
3306/?user=inventory&password=password",
                                           "jdbc:mysql://localhost: 
3306/?user=root&password=admin",
                                           "jdbc:mysql:// 
127.0.0.1:3306/?user=inventory&password=password",
                                           "jdbc:mysql:// 
127.0.0.1:3306/?user=root&password=admin",

                                           "jdbc:mysql:///? 
user=inventory&password=password",
                                           "jdbc:mysql:///testdb? 
user=inventory&password=password"
                                         };

             for( int i = 0; i < url.length; i++ )
             {
                 String retVal = openConnection(url[i]);

                 if( retVal == null )
                 {
                     out.write("Successful: " + url[i] + "<br/>");
                 }
                 else
                 {
                     out.write("Failed: " + url[i] + "(" + retVal +  
")<br/>");
                 }
             }

         %>

         <%!
         public String openConnection(String url)
         {
             String retVal = null;
             Connection c = null;
             try
             {
                 c = DriverManager.getConnection(url);
             }
             catch( Exception e )
             {
                 retVal = e.toString();
             }
             finally
             {
                 if( c != null )
                 {
                     try
                     {
                         c.close();
                     }
                     catch( Exception e ) {}
                 }
             }

             return retVal;
         }
         %>
     </body>
</html>


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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by David Smith <dn...@cornell.edu>.
Can you post your database config and code snippet for accessing the
db?  Obfuscate the username/password info.

One immediate observation is the JDBC url should have the name of the
database you are trying to access like this:

jdbc:mysql://localhost/myDatabase?user= ....

--David

Krapacs Ambrose wrote:
> I have tried many different configurations and I have been unable to
> get my Servlets / JSP to connect to MySQL server running. I am trying
> to get this set up on my main server which is running Ubuntu 8.10
> Server with MySQL 5 and Tomcat6. I also tried setting up a Ubuntu 8.04
> server with Tomcat 5.5 and MySQL 5. I have even configured Tomcat
> running on the 8.10 server to try to connect to MySQL running on the
> 8.04 server. Still no luck!
>
> The exception that is thrown is here:
>     com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
> Communications link failure
> Last packet sent to the server was 0 ms
> ago.(jdbc:mysql://localhost?user=invuser&password=admin))
>     org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
>
>     org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:71)
>
>     org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:768)
>
>     java.security.AccessController.doPrivileged(Native Method)
>     org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:766)
>
>     org.apache.jsp.install_jsp._jspService(install_jsp.java:141)
>     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
>
>     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
>
>     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
>     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>
>     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
>     java.lang.reflect.Method.invoke(Method.java:616)
>     org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
>
>     java.security.AccessController.doPrivileged(Native Method)
>     javax.security.auth.Subject.doAsPrivileged(Subject.java:537)
>     org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
>
>     org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
>
> I have verified that MySQL is running and everything with Tomcat seems
> to be configured correctly because I can execute servlets and JSP just
> fine it's just the connections to MySql to that fail. I have also
> executed a standalone java application using the MySQL Connector/J and
> that worked fine. I've even tried different ways of deploying the
> MySql Connector/J (which is the newest version available) to see if it
> was a permissions problem with the library.
> The key to this is that the web applications that I am trying to
> deploy run flawlessly on my Mac OS X development machine with MySQL. I
> haven't tried Windows yet but if I can get this set up to host my web
> application I may have to set up a Windows machine to try it.


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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Ambrose Krapacs <ak...@gmail.com>.
On Nov 18, 2008, at 7:36 , Antonio Vidal Ferrer wrote:

> Hi,
>
> It's your mysql listening on Localhost?
> Have you tried to use the ip address instead of Localhost?
>
>
> Best,
>
> Toni
>
> -----Original Message-----
> From: Krapacs Ambrose [mailto:akrapacs@gmail.com]
> Sent: martes, 18 de noviembre de 2008 13:22
> To: users@tomcat.apache.org
> Subject: Servlets / JSP can't connect to MySQL in Ubuntu Server
>
> I have tried many different configurations and I have been unable to
> get my Servlets / JSP to connect to MySQL server running. I am trying
> to get this set up on my main server which is running Ubuntu 8.10
> Server with MySQL 5 and Tomcat6. I also tried setting up a Ubuntu 8.04
> server with Tomcat 5.5 and MySQL 5. I have even configured Tomcat
> running on the 8.10 server to try to connect to MySQL running on the
> 8.04 server. Still no luck!
>
> The exception that is thrown is here:
> 	com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
> Communications link failure
> Last packet sent to the server was 0 ms ago.(jdbc:mysql://localhost?
> user=invuser&password=admin))
> 	
> org
> .apache
> .jasper
> .runtime.PageContextImpl.doHandlePageException(PageContextImpl.java: 
> 852)
> 	org.apache.jasper.runtime.PageContextImpl.access
> $1100(PageContextImpl.java:71)
> 	
> org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:
> 768)
> 	java.security.AccessController.doPrivileged(Native Method)
> 	
> org
> .apache
> .jasper
> .runtime.PageContextImpl.handlePageException(PageContextImpl.java:766)
> 	org.apache.jsp.install_jsp._jspService(install_jsp.java:141)
> 	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> 	
> org
> .apache
> .jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
> 	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
>
> 342)
> 	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> 	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	
> sun
> .reflect 
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> 57)
> 	
> sun
> .reflect
> .DelegatingMethodAccessorImpl 
> .invoke(DelegatingMethodAccessorImpl.java:
> 43)
> 	java.lang.reflect.Method.invoke(Method.java:616)
> 	
> org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
> 	java.security.AccessController.doPrivileged(Native Method)
> 	javax.security.auth.Subject.doAsPrivileged(Subject.java:537)
> 	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:
>
> 276)
> 	
> org
> .apache 
> .catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:
> 162)
> I have verified that MySQL is running and everything with Tomcat seems
> to be configured correctly because I can execute servlets and JSP just
> fine it's just the connections to MySql to that fail. I have also
> executed a standalone java application using the MySQL Connector/J and
> that worked fine. I've even tried different ways of deploying the
> MySql Connector/J (which is the newest version available) to see if it
> was a permissions problem with the library.
> The key to this is that the web applications that I am trying to
> deploy run flawlessly on my Mac OS X development machine with MySQL. I
> haven't tried Windows yet but if I can get this set up to host my web
> application I may have to set up a Windows machine to try it.
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


Yes I'm sure it is listening on localhost. In /etc/mysql/my.cnf the  
bind-address is set to 127.0.0.1 and also I explained that the  
standalone j2se java application successfully connected to the MySQL  
server via the MySQL JDBC connector. However I have tried using the ip  
address, and I have also tried different combinations specifying and  
omitting the port. Still no luck :(

RE: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Antonio Vidal Ferrer <an...@globalia-sistemas.com>.
Hi,

It's your mysql listening on Localhost?
Have you tried to use the ip address instead of Localhost?


Best,

Toni

-----Original Message-----
From: Krapacs Ambrose [mailto:akrapacs@gmail.com] 
Sent: martes, 18 de noviembre de 2008 13:22
To: users@tomcat.apache.org
Subject: Servlets / JSP can't connect to MySQL in Ubuntu Server

I have tried many different configurations and I have been unable to  
get my Servlets / JSP to connect to MySQL server running. I am trying  
to get this set up on my main server which is running Ubuntu 8.10  
Server with MySQL 5 and Tomcat6. I also tried setting up a Ubuntu 8.04  
server with Tomcat 5.5 and MySQL 5. I have even configured Tomcat  
running on the 8.10 server to try to connect to MySQL running on the  
8.04 server. Still no luck!

The exception that is thrown is here:
	com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:  
Communications link failure
Last packet sent to the server was 0 ms ago.(jdbc:mysql://localhost? 
user=invuser&password=admin))
	 
org 
.apache 
.jasper 
.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
	org.apache.jasper.runtime.PageContextImpl.access 
$1100(PageContextImpl.java:71)
	
org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java: 
768)
	java.security.AccessController.doPrivileged(Native Method)
	 
org 
.apache 
.jasper 
.runtime.PageContextImpl.handlePageException(PageContextImpl.java:766)
	org.apache.jsp.install_jsp._jspService(install_jsp.java:141)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	 
org 
.apache 
.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:

342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	 
sun 
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
57)
	 
sun 
.reflect 
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 
43)
	java.lang.reflect.Method.invoke(Method.java:616)
	
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:537)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:

276)
	 
org 
.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java: 
162)
I have verified that MySQL is running and everything with Tomcat seems  
to be configured correctly because I can execute servlets and JSP just  
fine it's just the connections to MySql to that fail. I have also  
executed a standalone java application using the MySQL Connector/J and  
that worked fine. I've even tried different ways of deploying the  
MySql Connector/J (which is the newest version available) to see if it  
was a permissions problem with the library.
The key to this is that the web applications that I am trying to  
deploy run flawlessly on my Mac OS X development machine with MySQL. I  
haven't tried Windows yet but if I can get this set up to host my web  
application I may have to set up a Windows machine to try it.


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


RE: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Chandra Madhumanchi (cmadhuma) [mailto:cmadhuma@cisco.com]
> Subject: RE: Servlets / JSP can't connect to MySQL in Ubuntu Server
>
> I am implementing 2way SSL over https on tamcat server through .Net
> client (C# code as given below)

And what does that have to do with the thread you just hijacked?

If you have a new question, start a new thread.

 - 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 start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by "Chandra Madhumanchi (cmadhuma)" <cm...@cisco.com>.
Hi

I am implementing 2way SSL over https on tamcat server through .Net
client (C# code as given below)

When iam validating server certificate,it's througing error like SSPI
failed while executing following method.


sslStream.AuthenticateAsClient(serverName,clientCertificatecollection,Ss
lProtocols.Ssl3,true);
 
Please suggest me....

using System;

using System.Collections;

using System.Net;

using System.Net.Security;

using System.Net.Sockets;

using System.Security.Authentication;

using System.Text;

using System.Security.Cryptography.X509Certificates;

using System.IO;




namespace SSLClient

{

class Program

{

private static Hashtable certificateErrors = new Hashtable();

// The following method is invoked by the
RemoteCertificateValidationDelegate.

public static bool ValidateServerCertificate(

object sender,

X509Certificate certificate,

X509Chain chain,

SslPolicyErrors sslPolicyErrors)

{

SslPolicyErrors errors = sslPolicyErrors;

if (errors != SslPolicyErrors.None)

{

Console.WriteLine("Certificate error: {0} ", errors);

}

if (((errors & SslPolicyErrors.RemoteCertificateChainErrors) ==

SslPolicyErrors.RemoteCertificateChainErrors))

{

//Console.WriteLine("Certificate error: {0} Certificate chain empty.
Self signed certificate? butstill continued");

errors -= SslPolicyErrors.RemoteCertificateChainErrors;

}

if (((errors & SslPolicyErrors.RemoteCertificateNameMismatch) ==

SslPolicyErrors.RemoteCertificateNameMismatch))

{

errors -= SslPolicyErrors.RemoteCertificateNameMismatch;

}

if (errors == SslPolicyErrors.None)

return true;

Console.WriteLine("Certificate error: {0}", sslPolicyErrors);

// Do not allow this client to communicate with unauthenticated servers.

return false;

}

public static void RunClient(string machineName, string serverName)

{

// Create a TCP/IP client socket.

// machineName is the host running the server application.

TcpClient client = new TcpClient(machineName, 8443);

Console.WriteLine("Client connected.");

// Create an SSL stream that will close the client's stream.

SslStream sslStream = new SslStream(

client.GetStream(),

false,

new RemoteCertificateValidationCallback(ValidateServerCertificate),

null

);

// The server name must match the name on the server certificate.

try

{

//X509Certificate clientCertificate;

X509CertificateCollection clientCertificatecollection = new
X509CertificateCollection();

X509Certificate clientCertificate =
X509Certificate.CreateFromCertFile(@"C:\project_securent\securent\lib\ap
ache-tomcat-5.5.17\ajay.cer");

clientCertificatecollection.Add(clientCertificate);

clientCertificatecollection.Add(clientCertificate);

sslStream.AuthenticateAsClient(serverName,clientCertificatecollection,Ss
lProtocols.Ssl3,true);

Console.WriteLine("hi");

}

catch (AuthenticationException e)

{

Console.WriteLine("Exception: {0}", e.Message);

if (e.InnerException != null)

{

Console.WriteLine("Inner exception: {0}", e.InnerException.Message);

}

Console.WriteLine("Authentication failed - closing the connection.");

client.Close();

return;

}

// Encode a test message into a byte array.

// Signal the end of the message using the "<EOF>".

byte[] messsage = Encoding.UTF8.GetBytes("Hello from the client.<EOF>");

// Send hello message to the server. 

sslStream.Write(messsage);

sslStream.Flush();

// Read message from the server.

string serverMessage = ReadMessage(sslStream);

Console.WriteLine("Server says: {0}", serverMessage);

// Close the client connection.

client.Close();

Console.WriteLine("Client closed.");

}

static string ReadMessage(SslStream sslStream)

{

// Read the message sent by the server.

// The end of the message is signaled using the

// "<EOF>" marker.

byte[] buffer = new byte[2048];

StringBuilder messageData = new StringBuilder();

int bytes = -1;

do

{

bytes = sslStream.Read(buffer, 0, buffer.Length);

// Use Decoder class to convert from bytes to UTF8

// in case a character spans two buffers.

Decoder decoder = Encoding.UTF8.GetDecoder();

char[] chars = new char[decoder.GetCharCount(buffer, 0, bytes)];

decoder.GetChars(buffer, 0, bytes, chars, 0);

messageData.Append(chars);

// Check for EOF.

if (messageData.ToString().IndexOf("<EOF>") != -1)

{

break;

}

} while (bytes != 0);

return messageData.ToString();

}

private static void DisplayUsage()

{

Console.WriteLine("To start the client specify:");

Console.WriteLine("clientSync machineName [serverName]");

Environment.Exit(1);

}

public static int Main(string[] args)

{

string serverCertificateName = "server.cer";

string machineName = "localhost";

Program.RunClient(machineName, serverCertificateName);

return 0;

}

}

}


-----Original Message-----
From: Martin Gainty [mailto:mgainty@hotmail.com] 
Sent: Tuesday, November 18, 2008 10:35 PM
To: Tomcat Users List
Subject: RE: Servlets / JSP can't connect to MySQL in Ubuntu Server


Andre

If not otherwise specified 3306 is the default port for mysql check to
see if its occupied with netstat -a | grep 3306 If it is reconfig your
port in my.conf to an available port

Martin Gainty
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official
business of Sender. This transmission is of a confidential nature and
Sender does not endorse distribution to any party other than intended
recipient. Sender does not necessarily endorse content contained within
this transmission. 




> Date: Tue, 18 Nov 2008 13:37:49 +0100
> From: aw@ice-sa.com
> To: users@tomcat.apache.org
> Subject: Re: Servlets / JSP can't connect to MySQL in Ubuntu Server
> 
> Krapacs Ambrose wrote:
> > I have tried many different configurations and I have been unable to

> > get my Servlets / JSP to connect to MySQL server running. I am 
> > trying to get this set up on my main server which is running Ubuntu 
> > 8.10 Server with MySQL 5 and Tomcat6. I also tried setting up a 
> > Ubuntu 8.04 server with Tomcat 5.5 and MySQL 5. I have even 
> > configured Tomcat running on the 8.10 server to try to connect to 
> > MySQL running on the 8.04 server. Still no luck!
> > 
> > The exception that is thrown is here:
> >     com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
> > Communications link failure
> Hi.
> I know little about MySQL and JDBC, but the above seems to be purely 
> at the TCP/IP level : your JDBC driver cannot connect to your MySQL
server.
> 
> It seems from the above that you are connecting to "localhost" without

> indicating a port. I thus suppose that JDBC is going to try the 
> "standard port" on which MySQL is supposed to be listening.
> 1) So first of all, is that the case ? Is MySQL really listening on 
> that port ? (and first of all, is MySQL started ?) (Try "netstat -n | 
> grep LISTEN" to see all ports being listened on)
> 
> 2) are your Tomcat and your MySQL server on the same system ? (since 
> you're trying to connect to "localhost")
> 
> 3) if yes, on that system, when you try "ping localhost", what does it

> show you ?
> 
> 4) finally, on the same system, try "telnet localhost xxxx", where 
> xxxx is the port where MySQL is supposedly listening.  What do you see
then ?
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, 
> e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

_________________________________________________________________
Access your email online and on the go with Windows Live Hotmail.
http://windowslive.com/Explore/Hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_acc
ess_112008

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


RE: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Martin Gainty <mg...@hotmail.com>.
Andre

If not otherwise specified 3306 is the default port for mysql
check to see if its occupied with netstat -a | grep 3306
If it is reconfig your port in my.conf to an available port

Martin Gainty 
______________________________________________ 
Disclaimer and confidentiality note 
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. 




> Date: Tue, 18 Nov 2008 13:37:49 +0100
> From: aw@ice-sa.com
> To: users@tomcat.apache.org
> Subject: Re: Servlets / JSP can't connect to MySQL in Ubuntu Server
> 
> Krapacs Ambrose wrote:
> > I have tried many different configurations and I have been unable to get 
> > my Servlets / JSP to connect to MySQL server running. I am trying to get 
> > this set up on my main server which is running Ubuntu 8.10 Server with 
> > MySQL 5 and Tomcat6. I also tried setting up a Ubuntu 8.04 server with 
> > Tomcat 5.5 and MySQL 5. I have even configured Tomcat running on the 
> > 8.10 server to try to connect to MySQL running on the 8.04 server. Still 
> > no luck!
> > 
> > The exception that is thrown is here:
> >     com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
> > Communications link failure
> Hi.
> I know little about MySQL and JDBC, but the above seems to be purely at 
> the TCP/IP level : your JDBC driver cannot connect to your MySQL server.
> 
> It seems from the above that you are connecting to "localhost" without 
> indicating a port. I thus suppose that JDBC is going to try the 
> "standard port" on which MySQL is supposed to be listening.
> 1) So first of all, is that the case ? Is MySQL really listening on that 
> port ? (and first of all, is MySQL started ?)
> (Try "netstat -n | grep LISTEN" to see all ports being listened on)
> 
> 2) are your Tomcat and your MySQL server on the same system ? (since 
> you're trying to connect to "localhost")
> 
> 3) if yes, on that system, when you try "ping localhost", what does it 
> show you ?
> 
> 4) finally, on the same system, try "telnet localhost xxxx", where xxxx 
> is the port where MySQL is supposedly listening.  What do you see then ?
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

_________________________________________________________________
Access your email online and on the go with Windows Live Hotmail.
http://windowslive.com/Explore/Hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_access_112008

Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by André Warnier <aw...@ice-sa.com>.
Ambrose Krapacs wrote:
[...]
> I have tried using telnet to connect to port 3306 and it does appear 
> that the server is listening because it refuses the telnet connection.

Well, that would tend to indicate exactly the opposite : either MySQL is 
*not* listening on that port, or something is blocking your telnet from 
connecting to that port.
Otherwise, it would accept to connect.

But try what David suggested first.  If that does not connect, then you 
do have a TCP/IP problem connecting to the MySQL port.
And then maybe there is some kind of firewall or other port-blocking 
software active there.


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


Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by Ambrose Krapacs <ak...@gmail.com>.
On Nov 18, 2008, at 7:37 , André Warnier wrote:

> Krapacs Ambrose wrote:
>> I have tried many different configurations and I have been unable  
>> to get my Servlets / JSP to connect to MySQL server running. I am  
>> trying to get this set up on my main server which is running Ubuntu  
>> 8.10 Server with MySQL 5 and Tomcat6. I also tried setting up a  
>> Ubuntu 8.04 server with Tomcat 5.5 and MySQL 5. I have even  
>> configured Tomcat running on the 8.10 server to try to connect to  
>> MySQL running on the 8.04 server. Still no luck!
>> The exception that is thrown is here:
>> com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:  
>> Communications link failure
> Hi.
> I know little about MySQL and JDBC, but the above seems to be purely  
> at the TCP/IP level : your JDBC driver cannot connect to your MySQL  
> server.
>
> It seems from the above that you are connecting to "localhost"  
> without indicating a port. I thus suppose that JDBC is going to try  
> the "standard port" on which MySQL is supposed to be listening.
> 1) So first of all, is that the case ? Is MySQL really listening on  
> that port ? (and first of all, is MySQL started ?)
> (Try "netstat -n | grep LISTEN" to see all ports being listened on)
>
> 2) are your Tomcat and your MySQL server on the same system ? (since  
> you're trying to connect to "localhost")
>
> 3) if yes, on that system, when you try "ping localhost", what does  
> it show you ?
>
> 4) finally, on the same system, try "telnet localhost xxxx", where  
> xxxx is the port where MySQL is supposedly listening.  What do you  
> see then ?
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

I have verified that MySQL is running on the correct port. In /etc/ 
conf/my.cnf the bind-address is 127.0.0.1 and the port specified is  
3306. I was able to get the standalone j2se application to connect to  
the MySQL server using the JDBC connector so tomcat should be running.  
I'm trying to set up both Tomcat and MySQL on the same system but  
during my troubleshooting I tried to set up another server with MySQL  
and I could not connect to that server either through Tomcat (same  
result). I've checked the /etc/hosts file to make sure that there is  
an entry for localhost, and pinging localhost seems to return expected  
results. Also, I have tried using telnet to connect to port 3306 and  
it does appear that the server is listening because it refuses the  
telnet connection.

Re: Servlets / JSP can't connect to MySQL in Ubuntu Server

Posted by André Warnier <aw...@ice-sa.com>.
Krapacs Ambrose wrote:
> I have tried many different configurations and I have been unable to get 
> my Servlets / JSP to connect to MySQL server running. I am trying to get 
> this set up on my main server which is running Ubuntu 8.10 Server with 
> MySQL 5 and Tomcat6. I also tried setting up a Ubuntu 8.04 server with 
> Tomcat 5.5 and MySQL 5. I have even configured Tomcat running on the 
> 8.10 server to try to connect to MySQL running on the 8.04 server. Still 
> no luck!
> 
> The exception that is thrown is here:
>     com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
> Communications link failure
Hi.
I know little about MySQL and JDBC, but the above seems to be purely at 
the TCP/IP level : your JDBC driver cannot connect to your MySQL server.

It seems from the above that you are connecting to "localhost" without 
indicating a port. I thus suppose that JDBC is going to try the 
"standard port" on which MySQL is supposed to be listening.
1) So first of all, is that the case ? Is MySQL really listening on that 
port ? (and first of all, is MySQL started ?)
(Try "netstat -n | grep LISTEN" to see all ports being listened on)

2) are your Tomcat and your MySQL server on the same system ? (since 
you're trying to connect to "localhost")

3) if yes, on that system, when you try "ping localhost", what does it 
show you ?

4) finally, on the same system, try "telnet localhost xxxx", where xxxx 
is the port where MySQL is supposedly listening.  What do you see then ?


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