null in Camunda variables

18 views Asked by At

I have trouble with Camunda 7.17.0 on docker

I want to use datasource from Camunda context for my delegates, but in result I have null object

Dockerfile

FROM camunda/camunda-bpm-platform:7.17.0

COPY context.xml /camunda/conf/
COPY camunda_test_engine.jar /camunda/lib/
COPY server.xml /camunda/conf
COPY web.xml /camunda/webapps/camunda/WEB-INF/
ENV JAVA_OPTS="-Xmx4096m -Xms2024m"

I made this:

  1. define datasource in tomcat context.xml
<Context>
    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
    <Resource name="jdbc/tstECOM" auth="Container"
          type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://database:3306/ecom"
          username="user" password="pass" maxTotal="20" maxIdle="10"
          maxWaitMillis="-1"/>
    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
</Context>
  1. define global JNDI in server.xml (/camunda/conf)
<GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml"/>
    <!-- Additional properties can be set to avoid a common exception
         regarding connection timeout in the connection pool:
          testOnBorrow="true"
          validationQuery="SELECT 1"
    -->
    <Resource name="jdbc/ProcessEngine" auth="Container" type="javax.sql.DataSource" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" uniqueResourceName="process-engine" driverClassName="org.h2.Driver" url="jdbc:h2:./camunda-h2-dbs/process-engine;TRACE_LEVEL_FILE=0;DB_CLOSE_ON_EXIT=FALSE" defaultTransactionIsolation="READ_COMMITTED" username="sa" password="sa" maxActive="20" minIdle="5" maxIdle="20" testOnBorrow="false" validationQuery="SELECT 1"/>
    <Resource name="global/camunda-bpm-platform/process-engine/ProcessEngineService!org.camunda.bpm.ProcessEngineService" auth="Container" type="org.camunda.bpm.ProcessEngineService" description="Camunda Platform Process Engine Service" factory="org.camunda.bpm.container.impl.jndi.ProcessEngineServiceObjectFactory"/>
    <Resource name="global/camunda-bpm-platform/process-engine/ProcessApplicationService!org.camunda.bpm.ProcessApplicationService" auth="Container" type="org.camunda.bpm.ProcessApplicationService" description="Camunda Platform Process Application Service" factory="org.camunda.bpm.container.impl.jndi.ProcessApplicationServiceObjectFactory"/>
     <Resource name="jdbc/tstECOM" auth="Container"
          type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://database:3306/ecom"
          username="user" password="pass" maxTotal="20" maxIdle="10"
          maxWaitMillis="-1"/>
  </GlobalNamingResources>
  1. define it in web.xml (/camunda/webapps/camunda/WEB-INF/)
  <resource-ref>
  <description>ECOM</description>
  <res-ref-name>jdbc/tstECOM</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

delegate method

public void execute(DelegateExecution execution) throws Exception {
        InitialContext ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/tstECOM");
        try (Connection connection = ds.getConnection()) {
            try {
                Store store = new Store(connection);
                store.getStoreFromECOM(); 
                store.getStocksForStore();
                //store.getHubForThisStore();
                try {
                    ObjectValue typedStoreValue = Variables.objectValue(store)
                            .serializationDataFormat(SerializationDataFormats.JSON)
                            .create();
                    execution.setVariable("store", typedStoreValue);
                } catch (Exception e) {
                    // Log exception message
                    System.err.println("Serialization Exception: " + e.getMessage());
                }
            } catch (Exception e) {
                // Log exception message and throw BpmnError
                System.err.println("Store Creation Exception: " + e.getMessage());
                throw new BpmnError("cantCreateInstanceOfStore", "cant create obj");
            }
        } catch (SQLException e) {
            // Log SQL exception message and throw BpmnError
            System.err.println("SQL Exception: " + e.getMessage());
            throw new BpmnError("cantGetStoreFromECOM", "cant reach to DB!");
        }
    }

process deployed and running currently, but in camunda history i see null object Camunda screenshot First i think it was a db error, but there are not sqlexceptions and db host pings correctly from container. Please help)

i'll try run code without packing objectvaue in try block, but in this case history is empty, there are no null object

0

There are 0 answers