Loading RuleApps in the memory persistence explicitly

You can manually load a RuleApp in a repository that is in the memory of your Java™ SE application.

Default strategies workflow
The following examples show some of the situations where you must load a RuleApp manually:
  • A RuleApp is coming from an external URL, such as a web application.
  • Your application tries to execute a ruleset in the myRuleApp/myRuleSet ruleset path, and the RuleApp archive is packaged as a resource with a different name other than /myRuleApp.jar.
  • Your application tries to execute a ruleset in the myRuleApp/myRuleSet ruleset path, and the RuleApp archive is not packaged as a resource at the default package level; for example, /ruleapp/myRuleApp.jar, instead of /myRuleApp.jar.
  • Your application tries to execute a ruleset in the myRuleApp/myRuleSet ruleset path, and the RuleApp archive is packaged as a resource with a different extension; for example, /myRuleApp.zip instead of /myRuleApp.jar.
You can manually load the RuleApp and add it to the repository through a management session:

// Load the RuleApp from classLoader resource "my-ruleapp.jar"
URL ruleAppArchiveURL = sample.getClass().getClassLoader().getResource("my-ruleapp.jar");
IlrArchiveManager archiveManager = new IlrArchiveManager();
IlrRepositoryFactory repositoryFactory = factory.createManagementSession().getRepositoryFactory();
// Retrieve RuleApps from URL
try (InputStream inputStream = ruleAppArchiveURL.openStream()) {
    if (inputStream != null) {
        try (JarInputStream jarInputStream = new JarInputStream(inputStream)) {
            Set<IlrMutableRuleAppInformation> ruleApps = archiveManager.read(repositoryFactory, jarInputStream);
            if (!ruleApps.isEmpty()) {
                IlrMutableRepository ruleAppRepository = repositoryFactory.createRepository();
                for (IlrMutableRuleAppInformation ruleApp : ruleApps) {
                    try {
                        ruleAppRepository.addRuleApp(ruleApp);
                    } catch (IlrAlreadyExistException exception) {
                        exception.printStackTrace();
                    }
                }
            }   
        }
    }
} catch (IOException exception) {
    exception.printStackTrace();
} catch (IlrArchiveException exception) {
    exception.printStackTrace();
}

When the target ruleset is not found, one of the default strategies is triggered. For more information, see Loading RuleApps in the memory persistence implicitly.