1

I have a Spring MVC Web application with MySQL database running on tomcat. I have configured Tomcat 7 (JBoss EWS 2.0), MySQL 5.5 and phpMyAdmin 4.0 on openshift. Then I have deployed my .war file following this tutorial. But my .war file doesn't work, I have renamed it to ROOT.war, and in root of openshift application it shows me a blank page. When I used some sample .war file from internet(for example this one), everything works perfect.

I thougt maybe the problem is in the database connection, so this is how my datasource in mvc-dipatcher-servlet.xmllooks like with OpenShift's environment variables:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_MYSQL_DB_PORT}/${OPENSHIFT_APP_NAME}?characterEncoding=UTF-8"/>
    <property name="username" value="${OPENSHIFT_MYSQL_DB_USERNAME}"/>
    <property name="password" value="${OPENSHIFT_MYSQL_DB_PASSWORD}"/>
</bean>

I have also tried with hardcoded version but the same result - pretty simple blank page:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://127.0.0.1:3306/myDatabaseName?characterEncoding=UTF-8"/>
    <property name="username" value="myRootUserName"/>
    <property name="password" value="MyPassword"/>
</bean>

Is there any solutions for this problem?

UPDATE With the suggestion of @Artur Malinowski I ran rhc tail - a <appname> command: This is what I got:

DL is deprecated, please use Fiddle
==> app-root/logs/jbossews.log <==
Dec 30, 2014 7:06:06 AM org.apache.catalina.loader.WebappClassLoader clearRefere
ncesJdbc
SEVERE: The web application [/quiz] registered the JDBC driver [com.mysql.jdbc.D
river] but failed to unregister it when the web application was stopped. To prev
ent a memory leak, the JDBC Driver has been forcibly unregistered.
Dec 30, 2014 7:06:06 AM org.apache.catalina.loader.WebappClassLoader clearRefere
ncesThreads
SEVERE: The web application [/quiz] appears to have started a thread named [Aban
doned connection cleanup thread] but has failed to stop it. This is very likely
to create a memory leak.
Dec 30, 2014 7:06:06 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /var/lib/openshift/54a274c6e0b8cd33d
10000a4/app-root/runtime/dependencies/jbossews/webapps/quiz.war has finished in
15,066 ms
Dec 30, 2014 7:06:06 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-127.4.37.1-8080"]
Dec 30, 2014 7:06:06 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 15415 ms

==> app-root/logs/phpmyadmin.log <==
[Tue Dec 30 07:03:35 2014] [notice] caught SIGWINCH, shutting down gracefully
- - - [30/Dec/2014:07:03:35 -0500] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.2.15
 (Red Hat) (internal dummy connection)"
[Tue Dec 30 07:04:06 2014] [notice] SELinux policy enabled; httpd running as con
text unconfined_u:system_r:openshift_t:s0:c2,c79
[Tue Dec 30 07:04:06 2014] [notice] Digest: generating secret for digest authent
ication ...
[Tue Dec 30 07:04:06 2014] [notice] Digest: done
[Tue Dec 30 07:04:06 2014] [notice] Apache/2.2.15 (Unix) PHP/5.3.3 configured --
 resuming normal operations
[Tue Dec 30 07:05:31 2014] [notice] SIGHUP received.  Attempting to restart
[Tue Dec 30 07:05:32 2014] [notice] Digest: generating secret for digest authent
ication ...
[Tue Dec 30 07:05:32 2014] [notice] Digest: done
[Tue Dec 30 07:05:32 2014] [notice] Apache/2.2.15 (Unix) PHP/5.3.3 configured --
 resuming normal operations

==> app-root/logs/mysql.log <==
141230  7:05:12 InnoDB: highest supported file format is Barracuda.
141230  7:05:13  InnoDB: Waiting for the background threads to start
141230  7:05:14 InnoDB: 5.5.40 started; log sequence number 1755443
141230  7:05:14 [Note] Server hostname (bind-address): '127.4.37.2'; port: 3306
141230  7:05:14 [Note]   - '127.4.37.2' resolves to '127.4.37.2';
141230  7:05:14 [Note] Server socket created on IP: '127.4.37.2'.
141230  7:05:14 [Warning] 'proxies_priv' entry '@ root@ex-std-node501.prod.rhclo
ud.com' ignored in --skip-name-resolve mode.
141230  7:05:14 [Note] Event Scheduler: Loaded 0 events
141230  7:05:14 [Note] /opt/rh/mysql55/root/usr/libexec/mysqld: ready for connec
tions.
Version: '5.5.40'  socket: '/var/lib/openshift/54a274c6e0b8cd33d10000a4/mysql//s
ocket/mysql.sock'  port: 3306  MySQL Community Server (GPL)
gdrt
  • 3,160
  • 4
  • 37
  • 56
  • 1
    Try checking for errors in log files ([howto](https://help.openshift.com/hc/en-us/articles/202328880-How-do-I-troubleshoot-application-issues-using-the-logs-)). – Artur Malinowski Dec 30 '14 at 13:13
  • Can you please look at the updated question? I did what you suggested. – gdrt Dec 30 '14 at 14:16
  • 1
    `rhc tail` is not enough - posted part includes only shutting down info. Use `rhc ssh` according to the link provided in the first comment. – Artur Malinowski Dec 30 '14 at 15:18

1 Answers1

1

Finally I have solved the problem which was actually stated here. I have solved this with the help of this answer. And here is my implementation:

I have added a listener-class in my web.xml:

<listener>
    <listener-class>
        az.quiz.utils.MyServletContext
    </listener-class>
</listener>

And added the listener class:

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

public class MyServletContext implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("Context created");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

        Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            Driver driver = drivers.nextElement();
            try {
                DriverManager.deregisterDriver(driver);
                System.out.println(String.format("deregistering jdbc driver: %s", driver));
            } catch (SQLException e) {
                System.out.println(String.format("Error deregistering driver %s", driver));
            }

        }
        System.out.println("Context destroyed");
    }
}
Community
  • 1
  • 1
gdrt
  • 3,160
  • 4
  • 37
  • 56