문제

Using Drools 5.5.0.Final with Guvnor 5.5.0.Final with the sample mortgages package.

When submitting REST json request with the following Batch 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 class is defined in the mortgages package within an XSD like so:

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

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

knowledge-services.xml currently 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 REST json request to fully specify the package name for Applicant class might work.

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

But can't seem to find where the fully qualified package name for Applicant is declared?

Acceptable answer must show an example which works without having to write java code, since the whole point of the REST interface is to access drools through a web service interface.

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

도움이 되었습니까?

해결책

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

First, here is the complete and correct format for the REST Json request to insert an Applicant instance to the rules engine using drools-server when the model been defined in drools-guvnor GUI interface and not uploaded 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 had incorrect resource.

The relevant parts of my corrected 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 issue: The authentication credentials were not specified in knowledge-services.xml which resulted in this error:

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

Third issue: The example mortgage package was not built as a binary package in Guvnor.

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

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

Additional note: INFO level logging is not enabled by default in drools-server. To enable extra logging, so that you can see detailed debug messages in $TOMCAT_HOME/logs/catalina.log follow these steps:

  1. Go to $TOMCAT_HOME/webapps/drools-server/WEB_INF/classes
  2. create a file logging.properties
  3. add these lines:

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

HTH

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top