Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

Creating XML with JAXB KieServicesClient fails (KIE 6.5.0)

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);

Hence the console prints:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <com.Operation>
    <systemCode>1</systemCode>
    [...]

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)

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?

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.

Involved libraries are:

  • 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

Environment: - JBoss Developer Studio 10.4 - Wildfly 10.1 - JDK 1.8

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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); 

Hope it helps someone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...