6 Replies Latest reply on Jun 16, 2007 10:10 AM by gogoasa

    loading resource from process class

    gogoasa

      Hello,

      I wonder if there is some "good practice" to recommend concerning loading properties files inside a process archive.

      My process actions call EJBs on a remote cluster and must have access to cluster location properties located in a file called jndi-services.properties.

      Some time ago I tried to deploy the .properties file with the process but if I remember correctly, jBPM 3.2.0 did not store resources in database along .classes.

      I now tried including my .properties file in the jbpm-configs.jar deployed with my jBPM 3.2.1-CVS ear. It doesn't seem to work either :

      17:02:38,269 ERROR [OnErrorAction] caught exception
      org.jbpm.JbpmException: couldn't get value for file 'jndi-services.properties'
       at org.jbpm.file.def.FileDefinition.getBytes(FileDefinition.java:196)
       at org.jbpm.instantiation.ProcessClassLoader.getResourceAsStream(ProcessClassLoader.java:43)
       at fr.bnf.entrychain.jbpm.actions.ServiceClusterJndiProperties.<init>(ServiceClusterJndiProperties.java:31)
       at fr.bnf.entrychain.jbpm.actions.OnStartAction.execute(OnStartAction.java:24)
       at org.jbpm.graph.def.Action.execute(Action.java:122)
      
      ...
      
      Caused by: java.lang.NullPointerException
       at org.jbpm.file.def.FileDefinition.getBytesFromDb(FileDefinition.java:213)
       at org.jbpm.file.def.FileDefinition.getBytes(FileDefinition.java:193)
       ... 79 more
      


      If I understand correctly the upper stacktrace, ProcessClassLoader does not find the resource in the database, which is normal, since it is not deployed there. Why does it not delegate then to its parent, which, in the case of my jBoss deployment, is org.jboss.mx.loading.UnifiedClassLoader3 ?

      Thank you,
      Adrian.

        • 1. Re: loading resource from process class
          gogoasa

          I have just tried to include the .properties file inside the .par again, same result :

          org.jbpm.JbpmException: couldn't get value for file 'jndi-services.properties'
           at org.jbpm.file.def.FileDefinition.getBytes(FileDefinition.java:196)
           at org.jbpm.instantiation.ProcessClassLoader.getResourceAsStream(ProcessClassLoader.java:43)
           at fr.bnf.entrychain.jbpm.actions.ServiceClusterJndiProperties.<init>(ServiceClusterJndiProperties.java:31)
           at fr.bnf.entrychain.jbpm.actions.OnStartAction.execute(OnStartAction.java:24)
           at org.jbpm.graph.def.Action.execute(Action.java:122)
          
          ...
          
          Caused by: java.lang.NullPointerException
           at org.jbpm.file.def.FileDefinition.getBytesFromDb(FileDefinition.java:213)
           at org.jbpm.file.def.FileDefinition.getBytes(FileDefinition.java:193)
           ... 74 more
          


          Has anyone succeeded in doing this ? To me, as BPM typically orchestrates distant clusters, it looks like a very common thing to do.

          • 2. Re: loading resource from process class
            gogoasa

            I fixed the class ProcessClassLoader in order to correctly load resources.

            Either it is a bug it has always been there and nobody ever loaded a resource in a .par, or I don't get resource location inside par archives at all...


            ### Eclipse Workspace Patch 1.0
            #P jbpm.3_HEAD
            Index: jpdl/jar/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java
            ===================================================================
            RCS file: /cvsroot/jbpm/jbpm.3/jpdl/jar/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java,v
            retrieving revision 1.1
            diff -u -r1.1 ProcessClassLoader.java
            --- jpdl/jar/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java 28 Apr 2006 15:09:22 -0000 1.1
            +++ jpdl/jar/src/main/java/org/jbpm/instantiation/ProcessClassLoader.java 10 Jun 2007 20:02:19 -0000
            @@ -28,7 +28,8 @@
            import org.jbpm.graph.def.*;

            public class ProcessClassLoader extends ClassLoader {
            -
            + final static protected String CLASSES_SUBDIR = "classes/";
            +
            private ProcessDefinition processDefinition = null;

            public ProcessClassLoader( ClassLoader parent, ProcessDefinition processDefinition ) {
            @@ -37,10 +38,11 @@
            }

            public InputStream getResourceAsStream(String name) {
            + String filename = CLASSES_SUBDIR + name;
            InputStream inputStream = null;
            FileDefinition fileDefinition = processDefinition.getFileDefinition();
            if (fileDefinition!=null) {
            - byte[] bytes = fileDefinition.getBytes(name);
            + byte[] bytes = fileDefinition.getBytes(filename);
            if (bytes!=null) {
            inputStream = new ByteArrayInputStream(bytes);
            }
            @@ -53,7 +55,7 @@

            FileDefinition fileDefinition = processDefinition.getFileDefinition();
            if (fileDefinition!=null) {
            - String fileName = "classes/" + name.replace( '.', '/' ) + ".class";
            + String fileName = CLASSES_SUBDIR + name.replace( '.', '/' ) + ".class";
            byte[] classBytes;
            try {
            classBytes = fileDefinition.getBytes(fileName);

            • 3. Re: loading resource from process class
              gogoasa

              Still hanging to this issue : do you think this is actually a bug ? Should I open a Jira ? Should I post more information ?

              Thank you,
              Adrian.

              • 4. Re: loading resource from process class
                gogoasa
                • 5. Re: loading resource from process class
                  kukeltje

                  file a jira issue

                  • 6. Re: loading resource from process class
                    gogoasa