使用JAXB KieServicesClient创建XML失败(KIE 6.5.0)

使用JAXB KieServicesClient创建XML失败(KIE 6.5.0),xml,jaxb,kie,kie-server,drools-kie-server,Xml,Jaxb,Kie,Kie Server,Drools Kie Server,我有一个这样的物体: @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") @XmlE

我有一个这样的物体:

@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>
    [...]
(这是西班牙语的,但我想这个错误很容易翻译)

我用于JAXB和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); 
kieCommandsCommandsFactory=KieServices.Factory.get().getCommands();
列表>();
BatchExecutionCommand=commandsFactory.newBatchExecution(cmds,会话\u有状态);
命令insertObjectCommand=null;
insertObjectCommand=commandsFactory.newInsert(操作,操作.getClass().getName(),false,null);
add(insertObjectCommand);
[...]
KieServicesConfiguration配置=KieServicesFactory.newRestConfiguration(KieServer.urlkeServer,
KieServer.name,
密码);
config.setMarshallingFormat(MarshallingFormat.JAXB);
KieServicesClient=KieServicesFactory.newKieServicesClient(配置);
RuleServicesClient rulesClient=client.getServicesClient(RuleServicesClient.class);
ServiceResponse-response=rulesClient.executeCommandsWithResults(“实例/”+containerName,命令);
有没有关于我做错了什么以及为什么一个编组有效而另一个无效的想法

除了POJO之外,我目前在maven下没有这个项目,因为我想知道我实际需要哪些JAR来让这些项目工作,并且使用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
环境: -JBossDeveloperStudio 10.4 -Wildfly 10.1 -JDK1.8


PS:我已经能够通过REST连接到KieServer,但它使用了不推荐的代码,可能正因为如此(我想),我没有得到我想要的响应。

所以我得到了答案,这要感谢我在Business Central的RedHat网页上遇到的一些指导原则:

本例中的关键是将类添加到Kie客户端的配置选项中。当使用Drools/KIE workbench 6.5.0时,下面的代码对于通过REST连接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); 
KieServicesConfiguration配置=KieServicesFactory。
newRestConfiguration(KieServer.urlkeserver,
KieServer.name,
密码);
config.setMarshallingFormat(MarshallingFormat.JAXB);
配置设置超时(3000L)//可选择的
Set>();
添加(YOURCLASS.class);
配置AddExtraClass(所有类);
KieServicesClient=KieServicesFactory.newKieServicesClient(配置);
RuleServicesClient rulesClient=client.getServicesClient(RuleServicesClient.class);
ServiceResponse response=rulesClient.executeCommandsWithResults(containerName,command);

希望它能帮助别人。

我在github上有一个示例项目。使用KieServicesClient with config进行连接是一个不错的选择。在版本7中都是一样的,只是一些来自远程库的代码被移动到kie服务器客户端api,因为工作台没有版本7中的内部服务器。感谢您的评论和确认!我需要很快切换到版本7。去年,口水的进化非常迅速。
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);