-1

I have an application in Java with Tomcat 7 (JBoss EWS 2.0), PostgreSQL 9.2 and Spring framework. It consists in a REST web service that get requests from an Android client and returns JSON objects.

I have deployed succesfully the pre compiled java applications (ROOT.war) in the Openshift's directory "~/app-root/runtime/repo/webapps/" by ssh and created the database in Openshift.

My application works fine in local, but it doesn't when I execute it in Openshift: http://jbossews-roteiro.rhcloud.com/usuarios/1. In the log appears an exception message of type "Could not get JDBC connection: nested exception is java.sql.Exception".

java.lang.Exception: Se ha producido un error al ejecutar el método UsuarioServiceImpl$verUsuario(1): Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:postgresql://$OPENSHIFT_POSTGRESQL_DB_HOST:$OPENSHIFT_POSTGRESQL_DB_PORT/jbossews
    at com.roteiro.services.usuario.UsuarioServiceImpl.verUsuario(UsuarioServiceImpl.java:115)
    at com.roteiro.controller.RoteiroController.verUsuarioAction(RoteiroController.java:193)
    at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    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:472)
    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:1008)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    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)

I was reading some related posts and I think that the problem is in the configuration of PostgreSQL included in Spring or in the file "~/app-root/repo/repo/.openshift/config/context.xml". I also check that the PostgreSQL connector is included in the library folder.

The content of ROOT.war is:

/img/*
/META-INF/MANIFEST.MF
/WEB-INF/classes/*
/WEB-INF/lib/*
/WEB-INF/applicationContext.xml
/WEB-INF/applicationDataSource.xml
/WEB-INF/applicationEntityBean.xml
/WEB-INF/web.xml

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>jbossews</display-name>
  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

/WEB-INF/applicationContext.xml (Spring):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="......................................................................">

    <context:component-scan base-package="com.roteiro.controller" />

    <mvc:annotation-driven />

    <mvc:resources mapping="/img/**" location="/img/" />

    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

    <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />

    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
            </list>
        </property>
    </bean>

    <import resource="applicationDatasource.xml" />
    <import resource="applicationEntityBean.xml" />

</beans>

/WEB-INF/applicationDatasource.xml (Spring):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

    <!-- development database -->
    <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://127.0.0.1:5432/jbossews" />
        <property name="username" value="adminvhhvpiq" />
        <property name="password" value="______________" />
    </bean> -->

    <!-- production database -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://$OPENSHIFT_POSTGRESQL_DB_HOST:$OPENSHIFT_POSTGRESQL_DB_PORT/$OPENSHIFT_APP_NAME" />
        <property name="username" value="$OPENSHIFT_POSTGRESQL_DB_USERNAME" />
        <property name="password" value="$OPENSHIFT_POSTGRESQL_DB_PASSWORD" />
    </bean>

</beans>

context.xml:

<Resource name="jdbc/PostgreSQLDS"
          url="jdbc:postgresql://${OPENSHIFT_POSTGRESQL_DB_HOST}:${OPENSHIFT_POSTGRESQL_DB_PORT}/${OPENSHIFT_APP_NAME}"
          driverClassName="org.postgresql.Driver"
          username="${OPENSHIFT_POSTGRESQL_DB_USERNAME}"
          password="${OPENSHIFT_POSTGRESQL_DB_PASSWORD}"
          auth="Container"
          type="javax.sql.DataSource"
          maxActive="20"
          maxIdle="5"
          maxWait="10000"/>
burus86
  • 1
  • 1

1 Answers1

0

I think you are trying to get username/password from properties file or some other place. you are putting username as "${OPENSHIFT_POSTGRESQL_DB_USERNAME}". remove " from value or put username/password directly here.

Neeraj
  • 327
  • 1
  • 8
  • Finally I solved my problem editing the Spring configuration file **/WEB-INF/applicationDatasource.xml** as: **jdbc/PostgreSQLDS** is already defined in the my Openshift's server file *context.xml*. – burus86 Jan 11 '14 at 21:01