我目前正在评估 KIE Server 而不使用 KIE Workbench。我正在评估的情况是,
1) 第三方会给我一个 drl 文件,它的值对象(将在 drl 中使用的 VO)。我需要通过标准的 maven 项目结构以编程方式创建一个 kjar 或 jar,并为该工件创建一个容器并将其存储在 maven repo 中。
2)当我收到执行请求以及输入数据时,针对该工件,通过REST
调用,我需要使用该输入数据执行上述创建的容器。
做一个简单的“HelloWorld”项目。
POM.XML
<modelVersion>4.0.0</modelVersion>
<groupId>demo</groupId>
<artifactId>Hello</artifactId>
<version>1</version>
<packaging>kjar</packaging>
<dependencies>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.4.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.4.0.Final</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
HelloWorld.java
package demo;
public class HelloWorld implements java.io.Serializable {
static final long serialVersionUID = 1L;
private java.lang.String message;
public HelloWorld()
{
}
public java.lang.String getMessage()
{
return this.message;
}
public void setMessage(java.lang.String message)
{
this.message = message;
}
public HelloWorld(java.lang.String message)
{
this.message = message;
}
}
HelloWorld.drl
package demo;
import demo.HelloWorld;
rule "hello"
when
HelloWorld(message == "Joe");
then
System.out.println("Hello Joe!");
end
kmodule.xml
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="demo" packages="demo">
<ksession name="demo.session"/>
</kbase>
</kmodule>
使用简单的maven项目结构:
Hello
|
|
|--src
| |--- main
| |--java
| | |---demo
| | |
| | |-- HelloWorld.java
| |
| |--resources
| |
| |--demo
| | |
| | |-- HelloWorld.drl
| |
| |--META-INF
| |
| |--kmodule.xml
|
|-- pom.xml
我可以为上面的 maven proj 结构创建一个容器“HelloworldContainer”GroupId: demo, Artifact: Hello, version: 1
但是当我尝试如下执行它时,得到内部服务器错误 URI: http://localhost:8080/kie-server/services/rest/server/containers/instances/HelloworldContainer
标题:
Content-Type: application/xml,
Authorization: Basic UWRtaWLkuTW5hZG1pbg==,
X-KIE-ContentType: XSTREAM
身体:
<batch-execution>
<insert out-identifier="helloworld" return-object="true">
<demo.HelloWorld>
<message>Joe</message>
</demo.HelloWorld>
</insert>
<fire-all-rules/>
</batch-execution>
错误堆栈跟踪:
java.lang.IncompatibleClassChangeError: com.google.common.collect.Maps and com.google.common.collect.Maps$TransformedValuesMap disagree on InnerClasses attribute
java.lang.Class.getDeclaringClass0(Native Method)
java.lang.Class.getDeclaringClass(Class.java:1101)
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:52)
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
sun.reflect.generics.repository.FieldRepository.getGenericType(FieldRepository.java:85)
java.lang.reflect.Field.getGenericType(Field.java:237)
com.thoughtworks.xstream.mapper.AnnotationMapper.processTypes(AnnotationMapper.java:212)
com.thoughtworks.xstream.mapper.AnnotationMapper.processAnnotations(AnnotationMapper.java:164)
com.thoughtworks.xstream.XStream.processAnnotations(XStream.java:1971)
com.thoughtworks.xstream.XStream.processAnnotations(XStream.java:1982)
org.kie.server.api.marshalling.xstream.XStreamMarshaller.<init>(XStreamMarshaller.java:86)
org.kie.server.api.marshalling.MarshallerFactory.getMarshaller(MarshallerFactory.java:37)
org.kie.server.services.impl.KieContainerInstanceImpl.getMarshaller(KieContainerInstanceImpl.java:111)
org.kie.server.services.drools.DroolsKieContainerCommandServiceImpl.callContainer(DroolsKieContainerCommandServiceImpl.java:59)
org.kie.server.remote.rest.drools.CommandResource.manageContainer(CommandResource.java:72)
除了这个“严重”问题外,服务器开始正常。
org.kie.server.services.impl.KieServerImpl.<init> Error when initializing server extension of type jBPM KIE Server extension
java.lang.RuntimeException: Unable to create EntityManagerFactory due to [PersistenceUnit: org.jbpm.domain] Unable to build EntityManagerFactory
at org.kie.server.services.jbpm.JbpmKieServerExtension.build(JbpmKieServerExtension.java:524)
at org.kie.server.services.jbpm.JbpmKieServerExtension.init(JbpmKieServerExtension.java:155)
at org.kie.server.services.impl.KieServerImpl.<init>(KieServerImpl.java:108)
at org.kie.server.services.impl.KieServerLocator.<clinit>(KieServerLocator.java:20)
at org.kie.server.services.Bootstrap.contextInitialized(Bootstrap.java:50)
at
...
Caused by: javax.naming.NameNotFoundException: Name [jboss/datasources/ExampleDS] is not bound in this Context. Unable to find [jboss].
at org.apache.naming.NamingContext.lookup(NamingContext.java:816)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:140)
at javax.naming.InitialContext.lookup(InitialContext.java:415)
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65)
... 33 more
和其他系列的警告,即使org.sonatype.guice
在我的 m2 存储库中可用
26-Sep-2016 11:37:21.346 WARNING [localhost-startStop-1] org.kie.server.services.drools.DroolsKieServerExtension.createContainer Unable to create instance of type org.sonatype.guice.asm.MethodVisitor due to org.sonatype.guice.asm.MethodVisitor
26-Sep-2016 11:37:21.352 WARNING [localhost-startStop-1] org.kie.server.services.drools.DroolsKieServerExtension.createContainer Unable to create instance of type org.sonatype.guice.asm.FieldVisitor due to org.sonatype.guice.asm.FieldVisitor
26-Sep-2016 11:37:21.357 WARNING [localhost-startStop-1] org.kie.server.services.drools.DroolsKieServerExtension.createContainer Unable to create instance of type org.sonatype.guice.asm.Type due to org.sonatype.guice.asm.Type
26-Sep-2016 11:37:21.363 WARNING [localhost-startStop-1] org.kie.server.services.drools.DroolsKieServerExtension.createContainer Unable to create instance of type org.sonatype.guice.asm.ClassWriter due to org.sonatype.guice.asm.ClassWriter
26-Sep-2016 11:37:21.368 WARNING [localhost-startStop-1] org.kie.server.services.drools.DroolsKieServerExtension.createContainer Unable to create instance of type org.sonatype.guice.asm.Edge due to org.sonatype.guice.asm.Edge