我有一个像这样的对象:
@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.
(这是西班牙语,但我想这个错误很容易翻译)
我使用 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 下没有这个项目,因为我想知道让这些项目正常工作实际上需要哪些 jars,并且使用 maven 会自动解决很多依赖项,我基本上不知道我需要什么(我的.m2 充满了我不知道的下载 jar)。一旦解决,我会将项目转换为 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-api-2.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 Developer Studio 10.4 - Wildfly 10.1 - JDK 1.8
PS:我已经能够通过 REST 连接到 KieServer,但它使用了不鼓励的代码,可能正因为如此(我想,没有人回答过我)我没有得到我想要的响应。