问题描述
我有一个像这样的对象:
I have an Object like this:
@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;
[...]
当我使用以下代码手动编组时,它似乎有效好吧:
When I marshall this manually with following code it seems it works well:
[...]
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鼓励的代码时出现错误:
But when I use the KieServerClient encouraged code I get an error:
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.
(这是西班牙语,但我想错误很容易翻译)
(The is in Spanish but I guess the error is pretty easy translated)
我用于KAXServerClient的JAXB代码片段:
A snippet of the code I use for JAXB with KieServerClient:
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);
关于我做错了什么以及为什么一个编组工作但另一个不工作的任何想法?
Any ideas of what I am doing wrong and why one marshalling works but the other does not?
除了POJO,我目前还没有maven下的这个项目,因为我想知道我真正需要这些项目工作的maars和maven有很多依赖项自动解决,我基本上不知道我需要什么(我的.m2已满载下载的罐子,我不知道)。
一旦解决,我会将项目转换为maven。
Except for the POJO, I currently do not have this project under maven since I want to know what jars I actually need to have these projects working and with maven a lot of dependencies are automatically resolved and I basically have no clue what I need (my .m2 is full with downloaded jars I have no idea of).Once resolved I will convert the project to 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
- 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
Environment: - JBoss Developer Studio 10.4 - Wildfly 10.1 - JDK 1.8
PS:我已经能够通过REST连接到KieServer,但它是由于气馁的代码,可能是因为(我猜,)我没有得到我想要的回复。
PS: I have been able to connect to the KieServer via REST, but it is with the discouraged code and probably because of that (I guess, nobody has ever answered me) I don't obtain the response I want.
推荐答案
所以我得到了答案,感谢我在Business Central的RedHat网页上遇到的一些指导原则:
So I got the answer thanks to some guidelines I encountered on the RedHat webpage on Business Central: FIRING RULES USING KIE SERVER JAVA CLIENT API
此处的关键case是将类添加到Kie客户端的配置选项中。使用Drools / Kie workbench 6.5.0时,以下代码适用于通过REST与KIE服务器连接。 command 是一个有效的BatchExecutionCommand:
Key in this case was adding the classes to the configuration options for the Kie client. Code below is valid for connecting with KIE server via REST when using Drools/Kie workbench 6.5.0. command is a valid 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);
希望它有所帮助。
这篇关于使用JAXB KieServicesClient创建XML失败(KIE 6.5.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!