我是流口水的新手,使用带有kie-server和rest client的poc。我使用eclipse(已安装drools)开发了示例poc,并经过了正常测试,但使用kie-workbench ui部署在drools服务器上,然后我使用Rest Client进行呼叫以获取异常
SEVERE [http-nio-8080-exec-5] org.kie.server.services.drools.DroolsKieContainerCommandServiceImpl.callContainer Error calling container 'com.lambda.st.drl:simple-test:1.0.4'
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to org.kie.api.command.Command
at org.kie.server.services.drools.DroolsKieContainerCommandServiceImpl.callContainer(DroolsKieContainerCommandServiceImpl.java:60)
at org.kie.server.remote.rest.drools.CommandResource.manageContainer(CommandResource.java:86)
at sun.reflect.GeneratedMethodAccessor256.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:209)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.kie.server.services.impl.security.web.CaptureHttpRequestFilter.doFilter(CaptureHttpRequestFilter.java:42)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:608)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1156)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
代码:
package com.lambda.st.drl;
public class Person implements java.io.Serializable {
static final long serialVersionUID = 1L;
@org.kie.api.definition.type.Label(value = "Name")
private java.lang.String name;
@org.kie.api.definition.type.Label(value = "Time")
private java.lang.Integer time;
@org.kie.api.definition.type.Label(value = "Greet")
private java.lang.String greet;
public Person() {
}
public java.lang.String getName() {
return this.name;
}
public void setName(java.lang.String name) {
this.name = name;
}
public java.lang.Integer getTime() {
return this.time;
}
public void setTime(java.lang.Integer time) {
this.time = time;
}
public java.lang.String getGreet() {
return this.greet;
}
public void setGreet(java.lang.String greet) {
this.greet = greet;
}
public Person(java.lang.String name, java.lang.Integer time,
java.lang.String greet) {
this.name = name;
this.time = time;
this.greet = greet;
}
}
package com.lambda.st.drl
import com.lambda.st.drl.Person
rule "Good Morning"
when
person: Person(time >= 0, time < 12)
then
person.setGreet("Good Morning " + person.getName());
end
rule "Good Afternoon"
when
person: Person(time >= 12, time < 16)
then
person.setGreet("Good Afternoon " + person.getName());
end
rule "Good Night"
when
person: Person(time >= 16, time <= 24)
then
person.setGreet("Good Night " + person.getName());
end
Person person = new Person();
person.setName("Kie-Server");
person.setTime(12);
String container = "com.lambda.st.drl:simple-test:1.0.4";
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(url, username, password);
//Set<Class<?>> allClasses = new HashSet<Class<?>>();
//allClasses.add(Person.class);
//config.addJaxbClasses(allClasses);
config.setMarshallingFormat(MarshallingFormat.JSON);
//config.setTimeout(300L);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);
List<Command<?>> commands = new LinkedList<Command<?>>();
commands.add(KieServices.Factory.get().getCommands().newInsert(person, "Person"));
commands.add(KieServices.Factory.get().getCommands().newFireAllRules());
BatchExecutionCommand batchCommand = KieServices.Factory.get().getCommands().newBatchExecution(commands, session);
ServiceResponse<String> response = ruleClient.executeCommands(container, batchCommand);
System.out.println(response.getResult());