Search code examples
javadroolskie

UnsupportedOperationException from KieSession.startProcess


I am trying to switch our project from Drools 6.5.0.CR2 to 7.7.0.Final. (Don't ask me who had the idea to use a CR version in a production environment)

I had no problems changing my dependencies (no compilation errors) but I am now having problems running my drools network. I am now getting an UnnsupportedOperationException from KieSession.startProcess.

java.lang.UnsupportedOperationException
    at org.drools.core.impl.StatefulKnowledgeSessionImpl$DummyInternalProcessRuntime.startProcess(StatefulKnowledgeSessionImpl.java:2166)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:1839)

I create my kie session like so in a KieHelper class we have created with the following constructor and getter:

public KieHelper(Collection<File> resources) throws ResolverException {
    this();
    KieFileSystem kfs = this.services.newKieFileSystem();

    for(File f : resources) {
        System.out.println(f.getPath());
        try{
            FileInputStream fis = new FileInputStream(f);

            kfs.write(
                    f.getPath(),
                    this.services.getResources().newInputStreamResource(fis));
        }catch (Exception e) {
            throw new ResolverException(e);
        }
    }

    KieBuilder kieBuilder = this.services.newKieBuilder(kfs).buildAll();

    if (kieBuilder.getResults().hasMessages(Level.ERROR)) {
        List<Message> errors = kieBuilder.getResults().getMessages(Level.ERROR);
        StringBuilder sb = new StringBuilder("Errors:");
        for (Message msg : errors) {
            sb.append("\n  " + prettyBuildMessage(msg));
        }

        throw new ResolverException(sb.toString());
    }

    KieContainer container = services.newKieContainer(services.getRepository().getDefaultReleaseId());
    this.base = container.getKieBase();
}

public KieSession newKieSession() {
    return this.base.newKieSession();
}

Then I try and start the session like so in the class that uses the KieHelper:

KieSession wm = this.kieHelper.newKieSession();

//insert facts into the session

wm.startProcess(this.getRuleId()); //this is throwing the exception

In Drools 6 this works fine. In drools 7 it does not. I am hoping someone knows what is going on.


EDIT1:

With Tibor's answer I double checked the classpath. We are also switching from an ant only build system, where we were placing all the jar files in the binaries folder using the Drools Engine distribution zip on the classpath manually to Maven. I added the dependencies to our pm as described by the documentation here.

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>drools-bom</artifactId>
      <type>pom</type>
      <version>7.7.0.Final</version>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-api</artifactId>
  </dependency>
  <dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-compiler</artifactId>
  </dependency>
</dependencies>

But looking at the dependencies from maven the list is much smaller:

From maven:

antlr-runtime-3.5.2.jar
commons-codec-1.10.jar
drools-compiler-7.7.0.Final.jar
drools-core-7.7.0.Final.jar
ecj-4.4.2.jar
kie-api-7.7.0.Final.jar
kie-internal-7.7.0.Final.jar
kie-soup-commons-7.7.0.Final.jar
kie-soup-maven-support-7.7.0.Final.jar
kie-soup-project-datamodel-api-7.7.0.Final.jar
kie-soup-project-datamodel-commons-7.7.0.Final.jar
mvel2-2.4.0.Final.jar
protobuf-java-2.6.0.jar
slf4j-api-1.7.25.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.10.jar

From the Drools Engine Distribution Zip

activation-1.1.1.jar
aether-api-1.1.0.jar
aether-connector-basic-1.1.0.jar
aether-impl-1.1.0.jar
aether-spi-1.1.0.jar
aether-transport-file-1.1.0.jar
aether-transport-http-1.1.0.jar
aether-transport-wagon-1.1.0.jar
aether-util-1.1.0.jar
ant-1.8.4.jar
ant-launcher-1.8.4.jar
antlr-runtime-3.5.2.jar
aopalliance-1.0.jar
cdi-api-1.2.jar
commons-codec-1.10.jar
commons-collections4-4.1.jar
commons-lang3-3.4.jar
curvesapi-1.04.jar
drools-beliefs-7.7.0.Final.jar
drools-compiler-7.7.0.Final.jar
drools-core-7.7.0.Final.jar
drools-decisiontables-7.7.0.Final.jar
drools-persistence-api-7.7.0.Final.jar
drools-persistence-jpa-7.7.0.Final.jar
drools-pmml-7.7.0.Final.jar
drools-scorecards-7.7.0.Final.jar
drools-templates-7.7.0.Final.jar
drools-verifier-7.7.0.Final.jar
ecj-4.4.2.jar
guava-20.0.jar
guice-4.0-no_aop.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
httpclient-4.5.3.jar
httpcore-4.4.6.jar
itext-2.1.7.jar
javassist-3.20.0-GA.jar
javax.inject-1.jar
javax.interceptor-api-1.2.jar
jaxb-core-2.2.11.jar
jaxb-impl-2.2.11.jar
jboss-jaxb-api_2.2_spec-1.0.4.Final.jar
jboss-transaction-api_1.2_spec-1.0.1.Final.jar
jcl-over-slf4j-1.7.25.jar
jsoup-1.8.3.jar
kie-api-7.7.0.Final.jar
kie-ci-7.7.0.Final.jar
kie-internal-7.7.0.Final.jar
kie-soup-commons-7.7.0.Final.jar
kie-soup-maven-integration-7.7.0.Final.jar
kie-soup-maven-support-7.7.0.Final.jar
kie-soup-project-datamodel-api-7.7.0.Final.jar
kie-soup-project-datamodel-commons-7.7.0.Final.jar
maven-aether-provider-3.3.9.jar
maven-artifact-3.3.9.jar
maven-builder-support-3.3.9.jar
maven-compat-3.3.9.jar
maven-core-3.3.9.jar
maven-model-3.3.9.jar
maven-model-builder-3.3.9.jar
maven-plugin-api-3.3.9.jar
maven-repository-metadata-3.3.9.jar
maven-settings-3.3.9.jar
maven-settings-builder-3.3.9.jar
mvel2-2.4.0.Final.jar
org.eclipse.sisu.inject-0.3.2.jar
org.eclipse.sisu.plexus-0.3.2.jar
plexus-cipher-1.7.jar
plexus-classworlds-2.5.2.jar
plexus-component-annotations-1.6.jar
plexus-interpolation-1.21.jar
plexus-sec-dispatcher-1.3.jar
plexus-utils-3.0.22.jar
poi-3.15.jar
poi-ooxml-3.15.jar
poi-ooxml-schemas-3.15.jar
protobuf-java-2.6.0.jar
slf4j-api-1.7.25.jar
stax-api-1.0-2.jar
wagon-http-3.0.0.jar
wagon-http-shared-3.0.0.jar
wagon-provider-api-3.0.0.jar
xmlbeans-2.6.0.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar
xstream-1.4.10.jar

I must be missing something for the maven dependencies which is not in the documentation.


EDIT2

So as a test I went back to building in our old ant only style and adding all the jars from the drools engine distribution zip to the dependencies and the runtime classpath but I still get the same error...

Looking at the lists though neither contains anything from jBPM from the looks of it. Looking at our old source control system we do have jbpm jars there for 6.5.0. Are these these distributed separately I am guessing?


Solution

  • (Damn I cannot comment till I have 15 rep.)

    It could be you don't have jBPM dependencies in your project. In such case I think Drools uses a dummy provider for processes that has no capabilities. But I am not 100% sure about this.