我有一个像这样的对象:
@XmlRootElement(name="com.Operation")
@XmlAccessorType(XmlAccessType.FIELD)
public class Operation implements java.io.Serializable
{
static final long serialVersionUID = 1L;
@org.kie.api.definition.type.Label("systemCode")
@XmlElement
private int systemCode;
[...]
当我使用以下代码手动编组时,它似乎运行良好:
[...]
JAXBContext jaxbContext =
DroolsJaxbHelperProviderImpl.createDroolsJaxbContext(classNames, null);
Marshaller marshaller = jaxbContext.createMarshaller();
StringWriter xml = new StringWriter();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(object, System.out);
因此控制台打印:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<com.Operation>
<systemCode>1</systemCode>
[...]
但是当我使用KieServerClient鼓励的代码时,我收到一个错误:
org.kie.server.client.KieServicesException: Error while serializing request data!
at org.kie.server.client.impl.AbstractKieServicesClientImpl.serialize(AbstractKieServicesClientImpl.java:514)
at org.kie.server.client.impl.AbstractKieServicesClientImpl.makeHttpPostRequestAndCreateServiceResponse(AbstractKieServicesClientImpl.java:234)
at org.kie.server.client.impl.RuleServicesClientImpl.executeCommandsWithResults(RuleServicesClientImpl.java:72)
[...]
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: class com.Operation ni ninguna de sus superclases se conocen en este contexto.
(这是西班牙语,但我想错误很容易翻译)
我用于KAXServerClient的JAXB的代码片段:
KieCommands commandsFactory = KieServices.Factory.get().getCommands();
List<Command<?>> cmds = new ArrayList<Command<?>>();
BatchExecutionCommand command = commandsFactory.newBatchExecution(cmds, SESSION_STATEFUL);
Command<?> insertObjectCommand = null;
insertObjectCommand = commandsFactory.newInsert(operation, operation.getClass().getName(), false, null);
cmds.add(insertObjectCommand);
[...]
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(KieServer.urlKieServer,
KieServer.name,
KieServer.password);
config.setMarshallingFormat(MarshallingFormat.JAXB);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
RuleServicesClient rulesClient = client.getServicesClient(RuleServicesClient.class);
ServiceResponse<ExecutionResults> response = rulesClient.executeCommandsWithResults("instances/"+containerName, command);
关于我做错了什么以及为什么一个编组工作而另一个没有工作的任何想法?
除了POJO,我目前还没有maven下的这个项目,因为我想知道我真正需要这些项目工作的maars和maven很多依赖项都会自动解决,我基本上不知道我是什么需要(我的.m2已满载下载的罐子,我不知道)。 一旦解决,我将把项目转换为maven。
涉及的库是:
环境: - JBoss Developer Studio 10.4 - Wildfly 10.1 - JDK 1.8
PS:我已经能够通过REST连接到KieServer,但它是由于气馁的代码,可能是因为(我猜,nobody has ever answered me)我没有得到我想要的响应。 / p>
答案 0 :(得分:1)
所以我得到了答案,感谢我在Business Central的RedHat网页上遇到的一些指导原则:FIRING RULES USING KIE SERVER JAVA CLIENT API
这种情况下的关键是将类添加到Kie客户端的配置选项中。使用Drools / Kie workbench 6.5.0时,以下代码适用于通过REST与KIE服务器连接。 command 是一个有效的BatchExecutionCommand:
KieServicesConfiguration config = KieServicesFactory.
newRestConfiguration(KieServer.urlKieServer,
KieServer.name,
KieServer.password);
config.setMarshallingFormat(MarshallingFormat.JAXB);
config.setTimeout(3000L); //optional
Set<Class<?>> allClasses = new HashSet<Class<?>>();
allClasses.add(YOURCLASS.class);
config.addExtraClasses(allClasses);
KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
RuleServicesClient rulesClient = client.getServicesClient(RuleServicesClient.class);
ServiceResponse<ExecutionResults> response = rulesClient.executeCommandsWithResults(containerName, command);
希望它有所帮助。