我有一个这样的对象:
@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.
(IS是西班牙语,但我猜该错误很容易翻译)
我用于kieserverclient的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的项目,因为我想知道我实际上需要哪些罐子才能使这些项目有效,并且在Maven的情况下,许多依赖项会自动解决,而且我基本上不知道我的知道需要(我的.m2满是我不知道的下载罐子)。解决后,我将把项目转换为Maven。
涉及的库是:
- droolsjbpm-integration-distribution-6.5.0.final
- droolsjbpm-tools-distribution-6.5.0.final
- httpclient-4.5.3
- httpcore-4.4.6
- javax.ws.rs-api2.0
- jaxb-xjc-2.3.0
- JMS-1.1
- kie-remote-client-6.5.0.final
- kie-remote-common-6.5.0.final
- kie-remote-jaxb-6.5.0.final
- kie-server-api-6.5.0.final
- kie-server-client-6.5.0.final
- optaplanner-core-6.5.0.final
环境: -JBOSS开发人员Studio 10.4 -Wildfly 10.1 -JDK 1.8
ps:我已经能够通过休息连接到Kieserver,但这是与灰心丧气的代码相关的,可能是因为(我想没有人回答过我),我没有得到我想要的响应。<<<<<<<<<<
所以我得到了答案,这要归功于我在redhat网页上遇到的一些准则:使用Kie Server Java Client api
触发规则在这种情况下,密钥是将类添加到KIE客户端的配置选项中。下面的代码对于使用Drools/Kie Workbench 6.5.0时与Kie服务器连接有效。命令是有效的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);
希望它对某人有帮助。