【发布时间】:2017-08-13 09:13:44
【问题描述】:
当使用 RuleServiceClient 从 Java 应用程序调用时,我从 Drools 执行服务器收到成功但为空的结果,尽管来自 Postman 的 REST 调用返回预期结果。
我的问题:我的 Java 代码中有什么不正确的地方?
请在下面找到详细信息。
我创建了示例规则(如果字段 Message.MyField == 1 然后将此字段设置为 400)并且我能够使用 Postmen 在 KIE 执行服务器上触发它:
向http://SERVER:8080/kie-server-webc/services/rest/server/containers/instances/kie-container发送请求:
{
"lookup": "defaultStatelessKieSession",
"commands": [{
"insert": {
"object": {
"Message": {
"myField": 1
}
},
"disconnected": false,
"out-identifier": "Message",
"return-object": true,
"entry-point": "DEFAULT"
}
}, {
"fire-all-rules": {
"max": -1,
"out-identifier": null
}
}]
}
回复(请注意"myField": 500):
{
"type": "SUCCESS",
"msg": "Container kie-container successfully called.",
"result": {
"execution-results": {
"results": [
{
"key": "Message",
"value": {
"bnym.test1.Message": {
"myField": 500
}
}
}
],
"facts": [
{
"key": "Message",
"value": {
"org.drools.core.common.DefaultFactHandle": {
"external-form": "0:1:1208207159:1208207159:2:DEFAULT:NON_TRAIT:myProj.test1.Message"
}
}
}
]
}
}
}
我从教程中借用的 Java 客户端代码是:
public class Message{
public Integer myField;
}
。 . .
private static String URL = "http://SERVER:8080/kie-server-webc/services/rest/server";
private static final String USER = "user";
private static final String PASSWORD = "pwd";
。 . .
public void transform() throws Exception {
Message m = new Message();
m.myField = 1;
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(URL, USER, PASSWORD);
config.setMarshallingFormat(MarshallingFormat.JSON);
kieServicesClient = KieServicesFactory.newKieServicesClient(config);
RuleServicesClient rulesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
KieCommands commandsFactory = KieServices.Factory.get().getCommands();
Command<?> insert = commandsFactory.newInsert(m);
Command<?> fireAllRules = commandsFactory.newFireAllRules();
Command<?> batchCommand = commandsFactory.newBatchExecution(Arrays.asList(insert, fireAllRules)); //0
ServiceResponse<String> executeResponse = rulesClient.executeCommands("kie-container", batchCommand);
if(executeResponse.getType() == ResponseType.SUCCESS) {
System.out.println("Commands executed with success! Response: ");
System.out.println(executeResponse.getResult());
}
}
结果:
Commands executed with success! Response:
{
"results" : [ ],
"facts" : [ ]
}
我的问题:我的 Java 代码有什么问题,所以结果是空的?
谢谢
【问题讨论】:
标签: drools kie kie-server