lundi 7 avril 2014

mise en veille prolongée - amazon aws ubuntu java mysql webservice "erreur composant le pilote #connecter"-Stack Overflow


we have some web services running on tomcat 7 / java7 / hibernate / mysql5. Everything is running perfectly on localhost tomcat server on my pc but when we deploy the application on the AWS Ubuntu server, we get this error message:




Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://ec2-54-197-214-209.compute-1.amazonaws.com:3306/ChronoMetriq] Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000046: Connection properties: {user=root, password=**} Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000006: Autocommit mode: false Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 10 (min=1) Error Creating SessionFactory: **Error calling Driver#connect null Mar 25, 2014 9:59:52 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container java.lang.NullPointerException at ca.chronometriq.webterm.restapi.Process.getQueueName(Process.java:132) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1024) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744)




Here is my hibernate.cfg.xml file content:


    <?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://myaddress.compute-1.amazonaws.com:3306/ChronoMetriq</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">********</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="show_sql">true</property>

<mapping class="ca.chronometriq.webterm.model.Clinic" />
...

</session-factory>
</hibernate-configuration>

And here is our session factory code:


public class DataObjectFactory {
@SuppressWarnings({ "rawtypes" })
private static final ThreadLocal threadLocal = new ThreadLocal();

private static ServiceRegistry serviceRegistry;
private static SessionFactory sessionFactory;

private static Configuration configuration;


private static final Logger logger = Logger.getLogger(DataAccessInterface.class.getName());


static {
try {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();

serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);


} catch (Exception e) {
System.err.println("Failed to create sessionFactory object." + e);
}
}

private DataObjectFactory(){
}

@SuppressWarnings("unchecked")
public static Session getSession() throws HibernateException {

Session session = (Session) threadLocal.get();

if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession() : null;

threadLocal.set(session);
}
return session;
}

public static void rebuildSessionFactory() {
try {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();

serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

} catch (HibernateException e) {
System.err.println("Error Creating SessionFactory: " + e.getMessage());
}
}

@SuppressWarnings("unchecked")
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.flush();
session.close();
}
}

public static SessionFactory getSessionFactory() {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();

serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

return sessionFactory;
}

public static Configuration getConfiguration() {
return configuration;
}


public static void closeRegistry() throws Exception{
if(serviceRegistry!= null) {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
}

Any idea why this happens?




'Error calling Driver#connect' is normally an error you get when Tomcat isn't able to reach you database. It may be because you provided the wrong username/password combination or because your database (or Amazon in that case) might be blocking the connection from the source IP.


I recommend you find the source IP and port from where you make the requests and add it to the user privileges in mysql. Grant all privileges for the 'root' user with the IP.


You can do so by calling:


GRANT ALL PRIVILEGES ON . TO 'root'@'x.x.x.x' IDENTIFIED BY 'the_password' WITH GRANT OPTION;


where x.x.x.x is the source IP (if mysql and tomcat are on the same server, and it's an Amazon EC2 instance, make sure to execute that query with the private ip of your EC2 instance as well as the private DNS, like ip-x-x-x-x.ec2.internal).


In the end, the granted users in your MySQL database should be 'root' from hosts: 127.0.0.1 / localhost / ::1 / your EC2 private IP / your EC2 private DNS (and other external IPs if you plan on calling it from outside the localhost).


Hope it helps. Max



we have some web services running on tomcat 7 / java7 / hibernate / mysql5. Everything is running perfectly on localhost tomcat server on my pc but when we deploy the application on the AWS Ubuntu server, we get this error message:




Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://ec2-54-197-214-209.compute-1.amazonaws.com:3306/ChronoMetriq] Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000046: Connection properties: {user=root, password=**} Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000006: Autocommit mode: false Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 10 (min=1) Error Creating SessionFactory: **Error calling Driver#connect null Mar 25, 2014 9:59:52 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container java.lang.NullPointerException at ca.chronometriq.webterm.restapi.Process.getQueueName(Process.java:132) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1024) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744)




Here is my hibernate.cfg.xml file content:


    <?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://myaddress.compute-1.amazonaws.com:3306/ChronoMetriq</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">********</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="show_sql">true</property>

<mapping class="ca.chronometriq.webterm.model.Clinic" />
...

</session-factory>
</hibernate-configuration>

And here is our session factory code:


public class DataObjectFactory {
@SuppressWarnings({ "rawtypes" })
private static final ThreadLocal threadLocal = new ThreadLocal();

private static ServiceRegistry serviceRegistry;
private static SessionFactory sessionFactory;

private static Configuration configuration;


private static final Logger logger = Logger.getLogger(DataAccessInterface.class.getName());


static {
try {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();

serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);


} catch (Exception e) {
System.err.println("Failed to create sessionFactory object." + e);
}
}

private DataObjectFactory(){
}

@SuppressWarnings("unchecked")
public static Session getSession() throws HibernateException {

Session session = (Session) threadLocal.get();

if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession() : null;

threadLocal.set(session);
}
return session;
}

public static void rebuildSessionFactory() {
try {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();

serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

} catch (HibernateException e) {
System.err.println("Error Creating SessionFactory: " + e.getMessage());
}
}

@SuppressWarnings("unchecked")
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.flush();
session.close();
}
}

public static SessionFactory getSessionFactory() {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();

serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

return sessionFactory;
}

public static Configuration getConfiguration() {
return configuration;
}


public static void closeRegistry() throws Exception{
if(serviceRegistry!= null) {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
}

Any idea why this happens?



'Error calling Driver#connect' is normally an error you get when Tomcat isn't able to reach you database. It may be because you provided the wrong username/password combination or because your database (or Amazon in that case) might be blocking the connection from the source IP.


I recommend you find the source IP and port from where you make the requests and add it to the user privileges in mysql. Grant all privileges for the 'root' user with the IP.


You can do so by calling:


GRANT ALL PRIVILEGES ON . TO 'root'@'x.x.x.x' IDENTIFIED BY 'the_password' WITH GRANT OPTION;


where x.x.x.x is the source IP (if mysql and tomcat are on the same server, and it's an Amazon EC2 instance, make sure to execute that query with the private ip of your EC2 instance as well as the private DNS, like ip-x-x-x-x.ec2.internal).


In the end, the granted users in your MySQL database should be 'root' from hosts: 127.0.0.1 / localhost / ::1 / your EC2 private IP / your EC2 private DNS (and other external IPs if you plan on calling it from outside the localhost).


Hope it helps. Max


0 commentaires:

Enregistrer un commentaire