8 Replies Latest reply on Oct 14, 2005 10:41 AM by Matthias von Arx

    MissingResourceException :ActionHandler

    Alejandro Guizar Master

      You can get the process class loader this way:

      ClassLoader processClassLoader = ClassLoaderUtil.getProcessClassLoader(processDefinition);

      Use it to load your resource bundle:
      ResourceBundle scpBundle = ResourceBundle.getBundle("path/to/labels", Locale.getDefault(),
      processClassLoader);

      Note that you have to provide the full path to your property resource file within the process archive. Let me know if this works.

        • 1. Re: MissingResourceException :ActionHandler
          Ashwin Iyer Newbie

          Hi,
          I followed the process you have asked me to , but am still getting the same exception.
          I gave the full path of the properties file , it din't work
          so i changed the location of the properties file to folder containing the classes and tried using the path as :
          classes/com/sample/action/labels
          i also tried
          classes/com/sample/action/labels.properties

          but all this gives me the same issue
          Any clues?

          Thanks
          Ashwin

          • 2. Re: MissingResourceException :ActionHandler
            Ashwin Iyer Newbie

            Hi,
            all i need to do is read from a file the "Source" and "Destination" values.
            the file could even be a "XML"
            I have been stuck up with this issues for couple of days now ..
            Any help on this would be greatful,
            Thanks
            Ashwin

            • 3. Re: MissingResourceException :ActionHandler
              Peter Johnson Master

              Try "com.sample.action.labels". I think that the resource bundle uses class naming conventions, not directory locations, to locate properties files.

              • 4. Re: MissingResourceException :ActionHandler
                Alejandro Guizar Master

                If all you need is to load a properties file and do not need the localization features provided by ResourceBundle, you can do something like this in your action handler:

                package com.sample.action;
                // ...
                public class ResourceActionHandler implements ActionHandler {
                 // ...
                 public void execute(ExecutionContext exeContext) throws Exception {
                 // open a stream to a file within the process archive
                 FileDefinition fileDefinition = exeContext.getProcessDefinition().getFileDefinition();
                 InputStream labelStream = fileDefinition.getInputStream("classes/com/sample/action/labels.properties");
                 // read a property list from the stream
                 Properties labelProperties = new Properties();
                 labelProperties.load(labelStream);
                 labelStream.close();
                 // set the properties as variables
                 exeContext.getContextInstance().addVariables(labelProperties);
                 }
                }

                I put my properties file in the same directory as the ResourceActionHandler class, but you can put your file anywhere in the process archive. Here is my process definition:
                <process-definition name="resourceful">
                 <start-state name="start">
                 <transition name="t1" to="process resources"></transition>
                 </start-state>
                 <node name="process resources">
                 <transition name="t2" to="end"></transition>
                 <action class="com.sample.action.ResourceActionHandler" />
                 </node>
                 <end-state name="end"></end-state>
                </process-definition>

                and my test case:
                public void testSimpleProcess() throws Exception {
                
                 // Extract a process definition from the processdefinition.xml file.
                 ProcessDefinition definition = ProcessDefinition.parseParResource("process.par");
                
                 // Create an instance of the process definition.
                 ProcessInstance instance = new ProcessInstance(definition);
                 Token rootToken = instance.getRootToken();
                 assertEquals("instance is in start state",
                 "start", rootToken.getNode().getName());
                
                 // Move the process instance from its start state to the first state.
                 // The configured action should execute.
                 instance.signal();
                 assertEquals("instance is in 'process resources' state",
                 "process resources", rootToken.getNode().getName());
                
                 // The properties should now be in the data context.
                 ContextInstance contextInstance = instance.getContextInstance();
                 assertEquals("firstHandler variable exists",
                 "com.sample.action.GizmoHandler",
                 contextInstance.getVariable("firstHandler"));
                 assertEquals("secondHandler variable exists",
                 "com.sample.action.FunkyHandler",
                 contextInstance.getVariable("secondHandler"));
                
                 // Move the process instance to the end state.
                 instance.signal();
                 assertEquals("instance is in end state",
                 "end", rootToken.getNode().getName());
                 assertTrue("instance has ended", instance.hasEnded());
                 }

                Hope this helps.

                • 5. Re: MissingResourceException :ActionHandler
                  Ashwin Iyer Newbie

                  Hi Alex,
                  Thanks a lot for the help.
                  I could finally get the stuff working.
                  Is there any reason why ResourceBundle doesn't work ?
                  My only concern over using a Properties class is , may be in future we might need to use the Locale.

                  Thanks for the help,
                  Ashwin

                  • 6. Re: MissingResourceException :ActionHandler
                    Alejandro Guizar Master

                    There is a known reason. ProcessClassLoader does not override getResource(String), which ResourceBundle depends on.

                    The reason is that there is no direct way to create working URLs for files associated with a process definition when they are stored in the database. This limitation does not apply when they are stored in the file system, tough it requires some changes.

                    Please open a JIRA issue if you're interested in this feature, but consider it isn't a blocking problem so it won't be resolved in the near future.

                    • 7. JBPM GPD
                      Matthias von Arx Newbie

                       

                      "ashwin_4421" wrote:
                      Hi ,
                      I have posted this topic before , i am posting it again as i am not able to post a reply in the previous thread

                      Here goes my problem:
                      I will have to read from a .properties file from one of my ActionHandlers, the properties file supplies the "source" and "destination" path to the ActionHandler.

                      These are the steps i followed:
                      1.Included the labels.properties along with the gpd.xml ,processdefintion.xml in the simple.par folder

                      When i build the processArchive , i see the labels.properties included in the generated simple.par file ,in the same path as gpd.xml

                      2.I deployed the process.

                      2.The code in my ActionHandler was
                      ResourceBundle scpBundle = ResourceBundle.getBundle("labels",Locale.getDefault());

                      At this stage i get the MissingResourceException,
                      I am not very sure as to how to use the ProcessClassLoader,
                      Can you please explain
                      Thanks
                      Ashwin


                      • 8. Re: JBPM GPD
                        Matthias von Arx Newbie

                        sorry, wrong thread