I'm developing a Java/Spring/Hibernate/CXF/MySQL SOAP webservice and corresponding web Spring MVC client on my laptop. The plan is to eventually move the two resulting war-files over to my remote server hosted at mybiz.com .
Both laptop and server have an instance of MySQL version 5.x.x
Both laptop and server have a root#localhost user (duh)
The server also has three other users:
zzdb_admin#%
zzdb_admin#localhost
zzdb_admin#mybiz.com
all with the same password remotepw and which have all had assorted privileges granted and flushed.
Both instances of MySQL have a database named zzdb.
Both instances of MySQL have ##session.old_passwords, ##global.old_passwords and ##global.secure_auth set to 0; In all cases hashes of passwords are 41 characters wide.
While logged in to the remote server directly I can manually log in to all accounts on both machines
mysql --user=root --password=remoterootpw
mysql --user=zzdb_admin --password=remotepw
mysql --host=localhost --user=zzdb_admin --password=remotepw
On the laptop I can log in to the local mysql with
mysql --user=root --password=localrootpw
mysql --host=mybiz.com --user=zzdb_admin --password=remotepw
So all users and passwords are correct. And their hashes are all 41 characters. Important: note this last proves that connection can be made with the instance on the remote machine.
The webservice' pom has version 5.1.8 of mysql-connector-java.
Now it gets weird. With these lines in the webservice' properties file:
hibernate.connection.url=jdbc:mysql://localhost:3306/zzdb
hibernate.connection.username=root
hibernate.connection.password=localrootpw
the webapp can connect to the local db instance and all is peachy. But changing only these three lines to
hibernate.connection.url=jdbc:mysql://mybiz.com:3306/zzdb
hibernate.connection.username=zzdb_admin
hibernate.connection.password=remotepw
throws the dreaded "Access denied for user 'zzdb_admin'#'localhost' " error
This has got me pulling out what few hairs I have left. Doesn't look like I'm missing anything and everything is spelled correctly. Anybody have an idea of what's going on?
TIA,
Still-learning Steve
Addendum: trying a different, simpler approach WORKED!
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://mybiz.com/zzdb?user=zzdb_admin&password=remoteapw";
Connection conn = DriverManager.getConnection(connectionUrl);
Now how about that? Only change is the method of connecting. Crazy
MySQL remote link have a bind address. You should comment it. You can refer this blog.
Solved the problem, and oh what a subtle bugger it was!
The applicationContext.xml at the base of the web service uses an Atomikos bean for a data source
<bean id="dataSourceServerA" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="XADBMS_A" />
<property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
<property name="xaProperties"> <!-- properties will be different for different data sources ie MySQL/HSDB/DB2 etc -->
<props>
<prop key="uri">$dbServerA{hibernate.connection.uri}</prop>
<prop key="user">$dbServerA{hibernate.connection.username}</prop>
<prop key="password">$dbServerA{hibernate.connection.password}</prop>
</props>
</property>
<property name="poolSize"><value>20</value></property>
<property name="testQuery" value="SELECT 1" />
which in turn gets used in the EntityManagerFactor bean. This configuration works great as long as I'm pointing to the local instance of MySQL. Changing the configuration to point to the remote instance kept failing with references to zzdb_admin#localhost no matter what I did.
So I created a second, much simpler connectivity tester using only
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://mybiz.com/zzdb?user=zzdb_admin&password=removepw";
theApp.conn = DriverManager.getConnection(connectionUrl);
and EUREKA! It worked to make a remote connection. So that got me thinking the problem had to lie with the Atomikos bean configuration.
Turns out there's one crucial xaProperty I wasn't setting - serverName, which when not explictly set defaults to - you guessed it - localhost. Atomikos isn't "smart" enough to infer the hostname out of the uri passed to it.
So merely switching to
<bean id="dataSourceServerA" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="XADBMS_A" />
<property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
<property name="xaProperties"> <!-- properties will be different for different data sources ie MySQL/HSDB/DB2 etc -->
<props>
<prop key="serverName">mybiz.com</prop>
<prop key="port">3306</prop>
<prop key="databaseName">zzdb</prop>
<prop key="user">$dbServerA{hibernate.connection.username}</prop>
<prop key="password">$dbServerA{hibernate.connection.password}</prop>
</props>
</property>
<property name="poolSize"><value>20</value></property>
<property name="testQuery" value="SELECT 1" />
did the trick. So the problem was one of configuration. Fiendishly subtle indeed!
Thanks to all who replied!
CASE CLOSED!
Still-learning Steve
Related
I have a Java Program that was installed on an old Ubuntu machine and sent mail using javax.mail. However, that machine went down and I am now running the same Java app in a new CentOS machine.
However, I get an error "MessagingException: 501 Syntax: HELO hostname" when trying to send an email using mail.smtp.host = 127.0.0.1.
My guess is that the mailserver is not yet activated in this CentOS.
How would I go about configuring a mail server that javax.mail can use?
Thank you
Your machine host name must be mapped in /etc/hosts file.
Example:
Console shows: linux#
and cat /etc/hostname shows
linux.mydomain.com
Then edit your hosts file running as root . vi /etc/hosts
127.0.0.1 localhost linux linux.mydomain.com
Good detailed info can be found here: https://confluence.atlassian.com/display/CONFKB/Sending+Email+Fails+Due+to+501+Syntax%3A+HELO+Hostname+Error
I encountered the same issue "MessagingException: 501 Syntax: HELO hostname" when sending out email with Spring MailSender. What works for me is to add in extra property "mail.smtp.localhost" under javaMailProperties like below:
<!-- JAVA MAIL -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="" />
<property name="port" value="25" />
<property name="protocol" value="smtp" />
<property name="username" value="" />
<property name="password" value="" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtps.starttls.enable">true</prop>
<prop key="mail.smtps.debug">true</prop>
<prop key="mail.smtp.localhost">localhost</prop>
</props>
</property>
</bean>
The problem is that the naming service on the new machine is not properly configured and Java can't find the host name of the machine. The SMTP HELO command needs to include the host name. The server is complaining because it's missing. Turn on JavaMail Session debugging and you can see the actual command this is sent. You can work around this host configuration problem by setting the JavaMail property mail.smtp.localhost to be the host name you want to use in the HELO command.
You need to run sendmail. See here for more info. Configuring sendmail can be a chore and you may want to take the configuration sendmail.cf from the old machine if possible.
I suspect (also) that you should have some central MTA (mail transport agent) set up, such that all machines in your enterprise use this, rather than running one per host. i.e. not using localhost.
In my case etc/hostname was susetest(and not linux.company.com)
Modified etc/hosts from 127.0.0.1 localhost to 127.0.0.1 localhost susetest(also after localhost make sure to use tab, when modifying the file)
Make sure to save changes, postfix stop, postfix start to restart SMTP server.
Should work fine.
(adding properties.setProperty("mail.smtp.localhost", "ourcompany.com"); to the properties also solved the problem, but workaround should not be the fix, when you can find the root cause, even if it takes days in my case)
I have a project that uses EclipseLink 2.1.3 under Tomcat 7.
What's bugging me is that the connection to the server doesn't persist through all of the app's life.
For a ServerSession to start I have to access the application manually.
Is there a way to automatically start a ServerSession when the application deploys and keep it running at all times ? So that I can access the application after a long idle time without having to wait ?
Thank you!
EDIT:
I have the following lines in persistence.xml
<property name="eclipselink.jdbc.read-connections.min" value="5"/>
<property name="eclipselink.jdbc.read-connections.max" value="10"/>
<property name="eclipselink.jdbc.write-connections.min" value="6"/>
<property name="eclipselink.jdbc.write-connections.max" value="12"/>
Server applications usually use a JDBC connection pool to get connections and reuse them. Depending on the pool you use, you may configure it to keep a given number of connections open.
We need to make a connection to ms sql server from java persistence unit 1.0. I hace following code for oracle database.
<properties>
<property name="toplink.jdbc.url" value="jdbc:oracle:thin:#IP:PORT"/>
<property name="toplink.jdbc.user" value="####"/>
<property name="toplink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="toplink.jdbc.password" value="####"/>
<property name="toplink.ddl-generation" value="create-tables"/>
<property name="toplink.jdbc.read-connections.max" value="1"/>
<property name="toplink.jdbc.read-connections.min" value="1"/>
<property name="toplink.jdbc.write-connections.max" value="1"/>
<property name="toplink.jdbc.write-connections.min" value="1"/>
<property name="toplink.logging.level" value="SEVERE" />
</properties>
I need the changes that I have to make in the previous code for making a connection to MS Sql Server.
Finally I got the solution.....
Steps to make connection to ms sql from JPA persistence.xml are:
Download the jar files from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=21599
I chose sql server 2005 so I used sqljdbc4 jar file from the above link.
Change driver name to com.microsoft.sqlserver.jdbc.SQLServerDriver in above given xml file.
Provide necessary username and password at corresponding position in xml file.
In connection url, write jdbc:sqlserver://localhost:port;databaseName=<Database>
Microsoft SQL Server connection can be done in few ways. To use windows authentication, you need to place a dll file in your System 32 directory. After that, you can replace the
connection URL, and user credentials as required. You may need to configure your SQL server
by SQL Server Surface Configuration Manager to allow remote connections and connections through TCP IP.
After that you may try to connect through a plain java class. And after that connect using a persistence unit (in EJB?).
When you download the SQL Server - JDBC Connector ZIP file, you can find a HTML Documentation,
which you must read (it will take 20 minutes). It was a 2 day struggle for me to connect to SQL Server from JDBC.
my spring-hibernate application run without problem for the past 1 week, but suddenly i get below error. will this caused by configuration error in applicationContext.xml? there is no error on my oracle10g log files (i get below errror every 1-2weeks once)
28 Jul 2010 14:20:19,177 INFO [http-2020-19] - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
28 Jul 2010 14:20:19,224 INFO [http-2020-19] - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
28 Jul 2010 14:20:19,240 WARN [http-2020-19] - Error while extracting database product name - falling back to empty error codes
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Listener refused the connection with the following error:
ORA-12500, TNS:listener failed to start a dedicated server process
The Connection descriptor used by the client was:
10.1.0.23:1521:myserver
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:293)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:320)
at org.springframework.jdbc.support.SQLErrorCodesFactory.getErrorCodes(SQLErrorCodesFactory.java:216)
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.setDataSource(SQLErrorCodeSQLExceptionTranslator.java:140)
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.<init>(SQLErrorCodeSQLExceptionTranslator.java:103)
at org.springframework.orm.hibernate3.SessionFactoryUtils.newJdbcExceptionTranslator(SessionFactoryUtils.java:145)
at org.springframework.orm.hibernate3.HibernateAccessor.getDefaultJdbcExceptionTranslator(HibernateAccessor.java:453)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1055)
at com
my applicationcontext.xml hibernate config
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">false</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.c3p0.min_size">10</prop>
<prop key="hibernate.c3p0.max_size">100</prop>
<prop key="hibernate.c3p0.timeout">10</prop>
<prop key="hibernate.c3p0.acquireRetryAttempts">30</prop>
<prop key="hibernate.c3p0.acquireIncrement">5</prop>
<prop key="hibernate.c3p0.idleConnectionTestPeriod">100</prop>
<prop key="hibernate.c3p0.initialPoolSize">20</prop>
<prop key="hibernate.c3p0.maxPoolSize">100</prop>
<prop key="hibernate.c3p0.maxIdleTime">300</prop>
<prop key="hibernate.c3p0.maxStatements">50</prop>
<prop key="hibernate.c3p0.minPoolSize">10</prop>
<prop key="hibernate.c3p0.preferredTestQuery">SELECT 1 FROM DUAL</prop>
<prop key="hibernate.c3p0.testConnectionOnCheckout">true</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
</props>
</property>
This has little to do with Spring, Hibernate, this is a pure Oracle "problem". Here is what we can read about ORA-125000:
ORA-12500: TNS:listener failed to start a dedicated server process
Cause: The process of starting up a dedicated server process failed. The
executable could not be found or the
environment may be set up incorrectly.
Action: Turn on tracing at the ADMIN level and reexecute the
operation. Verify that the ORACLE
Server executable is present and has
execute permissions enabled. Ensure
that the ORACLE environment is
specified correctly in LISTENER.ORA.
The Oracle Protocol Adapter that is
being called may not be installed on
the local hard drive. Please check
that the correct Protocol Adapter are
successfully linked. If error
persists, contact Oracle Customer
Support.
According to Thread: ORA-12500: TNS:listener failed to start a dedicated server process:
This will occur
When the database is not open
When the maximum number of sessions has been exceeded.
When the Windows maximum number of threads has been exceeded.
More tips from Oracle listener ORA-12500 Tips:
The most common cause of a ORA-12500 is a busy system whereby PGA RAM is exhausted. The solutions are:
Reduce sort_area_size (pga_aggregate_target) and hash_area_size to make each default PGA size smaller.
Add additional server RAM
As a last resort, deploy shared servers (the Multithreaded Server (MTS).
Common syntax issues in the listener.ora file can cause numerous listener connection problems, most notably the "ORA-12500: TNS: listener failed to start a dedicated server process" error.
Sometimes this ORA-12500 is because of a PGA RAM shortage on the target database, based on the settings for pga_aggregate_target, sort_area_size and hash_area_size.
You can have a single listener, pointing to multiple Oracle instances, each on a different version.
In Windows, especially Oracle8 and Oracle8i, you may need to re-start the listener service using the Windows task manager.
See also
TNS: listener failed to start a dedicated server process
Thread: ORA-12500: TNS:listener failed to start a dedicated server process
Oracle listener ORA-12500 Tips
I have a machine running a java app talking to a mysql instance running on the same instance. the app
uses jdbc4 drivers from mysql. I keep getting com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
at random times.
Here is the whole message.
Could not open JDBC Connection for transaction; nested exception is
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was25899 milliseconds ago.The last packet sent successfully to the server was 25899 milliseconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
For mysql, the value of global 'wait_timeout' and 'interactive_timeout' is set to 3600 seconds and 'connect_timeout' is set to 60 secs. the wait timeout value is much higher than the 26 secs(25899 msecs). mentioned in the exception trace.
I use dbcp for connection pooling and here is spring bean config for the datasource.
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db"/>
<property name="username" value="xxx"/>
<property name="password" value="xxx" />
<property name="poolPreparedStatements" value="false" />
<property name="maxActive" value="3" />
<property name="maxIdle" value="3" />
</bean>
Any idea why this could be happening? Will using c3p0 solve the problem ?
Try setting up the Apache Commons DBCP correctly.
You need to set:
validationQuery to SELECT 1+1
testOnBorrow to true
That should fix the problem.
Can you describe how your app is handling connection pooling? I doubt that autoReconnect=true in the JDBC driver would re-pool connections from your app. The app needs to reconnect when it loses a connection.
I'd follow the advice in the exception. You should consider either:
expiring and/or testing connection validity before use in your application,
increasing the server configured values for client timeouts, or
using the Connector/J connection property 'autoReconnect=true' to avoid this problem. Try adding that to your connection URL (consult the docs for the exact syntax) and see if it helps.
I doubt that C3P0 will be that much better than the DBCP that you're already using. The exception is giving you some specific advice. You've tried #3. What about the other two?
I know how to ask WebLogic to check connections before using them. You should find out how to do the same with Tomcat.
I have seen before that Windows machines which have been moved on the network have had trouble with connecting to themselves.
Is there any connectivity problems outside the JVM - i.e. mysql client connecting to the server, and timing out, etc?