Drools REST CannotResolveClassException

Using Drools 5.5.0.Final with Guvnor 5.5.0.Final with a sample mortgage package.

When sending a json REST request with the following package execution command:

{ "batch-execution": { "lookup":"ksession1", "commands":[ { "insert":{ "out-identifier":"outApplicant", "return-object":"true", "object": { "Applicant":{ "age":17 } } } }, { "fire-all-rules":"" } ] } } 

returns: 500 Internal server error

 com.thoughtworks.xstream.converters.ConversionException: Applicant : Applicant ---- Debugging information ---- message : Applicant cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException cause-message : Applicant class : org.drools.command.runtime.rule.InsertObjectCommand required-type : org.drools.command.runtime.rule.InsertObjectCommand converter-type : org.drools.runtime.help.impl.XStreamJson$JsonInsertConverter line number : -1 class[1] : org.drools.command.runtime.BatchExecutionCommandImpl converter-type[1] : org.drools.runtime.help..XSt...$JsonBatchExecutionCommandConverter version : null 

The Applicant's class is defined in the mortgage loan package in XSD, for example:

 age:Whole number (integer) applicationDate:Date creditRating:Text name:Text approved:True or False 

How can I tell drools where to find the candidate class? (which is defined in the mortgage sample as an XSD file)

Knowledge-services.xml now looks like this:

 <drools:grid-node id="node1"/> <drools:kbase id="kbase1" node="node1"> <drools:resources> <drools:resource type="PKG" source="http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/packages/mortgages"/> </drools:resources> </drools:kbase> 

I suspect that changing the json REST request to fully specify the package name for the Applicant class may work.

  ... "object": { "something.somethingelse.Applicant":{ "age":17 } } ... 

But, it seems, can’t find where the full package name for the Applicant is declared?

A valid answer should show an example that works without having to write java code, since the whole point of the REST interface is access to drooling through the web service interface.

Is there a spring configuration or some other way to write a json request that will work?

+1
source share
1 answer

Since no one answered, I am sending an answer that worked for me along with the root cause and the step-by-step procedure that I used to debug the problem. Please make a comment if there is a better way.

Firstly, here is the complete and correct format of the Json REST request for inserting the Applicant instance into the rules engine using the drools server when the model was defined in the drools-guvnor GUI and was not loaded as a POJO model.

 { "batch-execution": { "lookup":"ksession1", "commands":[ { "insert":{ "out-identifier":"outApplicant", "return-object":"true", "object": { "mortgages.Applicant":{ "age":17 } } } }, { "fire-all-rules":"" } ] } } 

Root cause: $ TOMCAT_HOME / webapps / drools-server / WEB-INF / classes / knowledge-services.xml has the wrong resource.

Relevant parts of my patched knowledge-services.xml:

 <drools:grid-node id="node1"/> <drools:kbase id="kbase1" node="node1"> <drools:resources> <drools:resource type="PKG" source="http://localhost:8080/drools-guvnor/rest/packages/mortgages/binary" basic-authentication="enabled" username="admin" password="admin" /> </drools:resources> </drools:kbase> 

Secondary Problem: Authentication credentials were not specified in Knowledge-services.xml, which led to this error:

 Exception: java.io.IOException: Servier returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/rest/packages/mortgages/binary 

Third question: An example mortgage package was not created as a binary package in Guvnor.

 ERROR: java.io.lang.RunTimeException: jav.io.StreamCorruptionException: Invalid Stream Header 

To fix: In Guvnor ... Packages .. mortgages .. package .dd..build

Additional note: Registration of the INFO level is not enabled by default in the drools server. To enable additional logging so you can see detailed debugging messages in $ TOMCAT_HOME / logs / catalina.log, follow these steps:

  • Go to $ TOMCAT_HOME / webapps / drools-server / WEB_INF / classes
  • create logging.properties file
  • add the following lines:

    org.apache.catalina.core.ContainerBase. [Catalina] .level = INFO org.apache.catalina.core.ContainerBase. [Catalina] .handlers = java.util.logging.ConsoleHandler

NTN

+1
source

Source: https://habr.com/ru/post/1443270/


All Articles