RuleServiceClient
当来自 Java 应用程序的调用使用来自 Postman 的 REST 调用返回预期结果时,我收到了来自 Drools 执行服务器的成功但 EMPTY结果。
我的问题:我的 Java 代码中有什么不正确的地方?
请在下面找到详细信息。
我创建了示例规则(如果字段Message.MyField == 1
然后将此字段设置为400
),我能够使用 Postmen 在 KIE 执行服务器上触发它:
POST 请求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 代码中有什么不正确的,所以结果是空的?
谢谢