Menu

Calling a standalone Java application from openxava

Kabongo
2024-06-27
2024-07-03
  • Kabongo

    Kabongo - 2024-06-27

    Greetings , as i am still waiting on steps so i can upgrade our system to the recent version of OX, i came across a small problem with one of our application. using OX 6.3.2 i have to call a java stand alone application that read my psql database and copy some of the data that i have saved in the system and use it separetely.
    So when i pass in the actual paramater using the stand alone application alone it works perfectly. but when i call the application from my openxava system. i am getting the folowing error:
    SQLState: 08001
    Error Code: 0
    Message: No suitable driver found for jdbc:postgresql://localhost:5432/testdb

    error code, come from my stand alone application letting me know that the data were not uploaded.

    so i have added the postgresjdbc jar file into my tomcat library and also added a copy in my application web-inf folder.
    i have also checked that the persistence is working properly and include the psql driver:

    <persistence-unit name="default">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>java://comp/env/jdbc/TestDS</non-jta-data-source>
    <class>org.openxava.session.GalleryImage</class>
    <class>org.openxava.web.editors.AttachedFile</class>
    <properties>
    <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver">
    <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/testdb">
    <property name="javax.persistence.jdbc.user" value="postgres">
    <property name="javax.persistence.jdbc.password" value="">
    <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect">
    </property></property></property></property></property></properties>
    </persistence-unit>

    please assist what else can i do to get it to work properly?
    regards
    
     
  • Javier Paniza

    Javier Paniza - 2024-07-01

    Hi Kabongo,

    When you say "standalone application" is a aplication package in a JAR, with a class with a main that you call from commnad line? Is it?
    In that case put here the command line you use when call to your standalone application from command line.

    How do you call to your standalone application? With Runtime.getRuntime().exec()?
    Please put the Java code in your OpenXava application that calls to your standalone application.
    Also the pom.xml of your OpenXava application and the complete stacktrace of the error.


    Help others in this forum as I help you.

     

    Last edit: Javier Paniza 2024-07-01
  • Kabongo

    Kabongo - 2024-07-01

    here is my action class:
    import org.openxava.actions.ViewBaseAction;

    public class MyClassAction extends ViewBaseAction{

    @Override
    public void execute() throws Exception {
        // TODO Auto-generated method stub
        Object customerId = getView().getValue("customerId");
         String clientCode=customerId.toString();
          try {
    
            Class<?> myClass = Class.forName("myClass.MyClass");
            java.lang.reflect.Method mainMethod = myClass.getMethod("main", String[].class);
            String[] params = { clientCode };
            mainMethod.invoke(null, (Object) params);
            addMessage("Data was saved to MyClass");
         }catch(Exception ex) {
             addError(ex.getMessage());
         }
    }
    

    }

    and the stacktrace:
    01-Jul-2024 15:12:04.438 SEVERE [main] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [naviox]
    java.lang.ExceptionInInitializerError
    at com.openxava.naviox.Modules.init(Modules.java:40)
    at com.openxava.naviox.web.NaviOXFilter.init(NaviOXFilter.java:36)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:270)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:251)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:102)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4538)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5177)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1133)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1867)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1045)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:429)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
    at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474)
    Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
    at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:109)
    at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136)
    at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:254)
    at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:262)
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:236)
    at org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:86)
    at org.openxava.jpa.XPersistence.openManager(XPersistence.java:129)
    at org.openxava.jpa.XPersistence.getManager(XPersistence.java:97)
    at com.openxava.naviox.impl.DB.<clinit>(DB.java:30)
    ... 46 more
    Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (java.net.ConnectException: Connection refused: connect)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:669)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:544)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:753)
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
    at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)
    at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106)
    ... 54 more
    Caused by: java.sql.SQLTransientConnectionException: java.net.ConnectException: Connection refused: connect
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
    at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
    at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
    at org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:55)
    at org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:355)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:115)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:665)
    ... 59 more
    Caused by: org.hsqldb.HsqlException: java.net.ConnectException: Connection refused: connect
    at org.hsqldb.ClientConnection.openConnection(Unknown Source)
    at org.hsqldb.ClientConnection.initConnection(Unknown Source)
    at org.hsqldb.ClientConnection.<init>(Unknown Source)
    ... 66 more
    Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at java.net.Socket.<init>(Socket.java:434)
    at java.net.Socket.<init>(Socket.java:211)
    at org.hsqldb.server.HsqlSocketFactory.createSocket(Unknown Source)
    ... 69 more</init></init></init></init></clinit></init>

     
  • Javier Paniza

    Javier Paniza - 2024-07-03

    Hi Kabongo,

    As I see in your calling code you're using instrospection, so you don't call a external Java standalone application, but you call a class that is included in your web application. So you have added the code of your "no-longer standadalone" application to your web application. That's correct, why not.

    However, the problem is not on calling your application, is that your OpenXava application does not start because of this:

    Caused by: org.hsqldb.HsqlException: java.net.ConnectException: Connection refused: connect
    

    That is, it tries to connect to HSQLDB server that is not up.

    Maybe you standalong application has a database configuration different that the one that uses your OpenXava application, and you mix all in the same application and one overwrite the other.
    Look for persistence.xml and context.xml files in all your jars.

    BTW, do you application be able of being called from command line with java -jar?


    Help others in this forum as I help you.

     
  • Kabongo

    Kabongo - 2024-07-03

    Hi Javier,
    apologies for the mistake in wording , yes i meant external class that i was calling. and yes the program works when i call it from the command line.
    and thanks to your insight i have managed to find the problem; i needed to specify the postgres driver name from my class for it to work.
    in case any one comes accross such it is :
    Class.forName("org.postgresql.Driver");
    and with this line my error is no more. thanks again
    regards

     

Log in to post a comment.