JSON Request Error

160 views
Skip to first unread message

vijay yadav

unread,
Jul 7, 2017, 5:24:28 AM7/7/17
to Drools Usage
I have following json request

{"batch-execution":
{
    "lookup": "defaultStatelessKieSession",
    "insert": [
      {
        "out-identifier": "out",
        "return-object": "true",
        "entrypoint": "DEFAULT",
        "com.redhat.loandemo.Applicant": {
          "cc": "7",
          "age": "52"
        }
      },
      {
        "out-identifier": "out",
        "return-object": "true",
        "entrypoint": "DEFAULT",
        "com.redhat.loandemo.Loan": {
          "tenure": "5"
        }
      },
      {
        "out-identifier": "out",
        "return-object": "true",
        "entrypoint": "DEFAULT",
        "com.redhat.loandemo.Coapplicant": {
          "income": "0"
        }
      },
      {
        "out-identifier": "out",
        "return-object": "true",
        "entrypoint": "DEFAULT",
        "com.redhat.loandemo.Coapplicant": {
          "income": "0"
        }
      }
    ],
    "get-objects": { "out-identifier": "output" }
  }
}

and headers are ContentType: application/json, Accept: application/json.

when I post , I get following error

{
  "type": "FAILURE",
  "msg": "Bad request, no commands to be executed - either wrong format or no data",
  "result": null
}


Would anyone please help me out here?
Thanks

Maciej Swiderski

unread,
Jul 7, 2017, 5:39:47 AM7/7/17
to drools...@googlegroups.com
use individual insert as commands instead of single array

Maciej
--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/c0e32232-7c4a-4767-b6e9-3eccb7a05943%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vijay yadav

unread,
Jul 7, 2017, 5:56:40 AM7/7/17
to Drools Usage
I get following error now.

{
  "type": "FAILURE",
  "msg": "Error calling container loasd: Error unmarshalling input",
  "result": null
Message has been deleted

Abhijit Humbe

unread,
Jul 9, 2017, 9:14:08 PM7/9/17
to drools...@googlegroups.com
you are using incorrect json request format. With JSON request payload no need to use ''batch-execution", remove that. And correct JSON request will look like as:
-------
{
      "commands":[
             {
            "insert":{
               "out-identifier":"topicLevel",
               "object":{
                  "example.project4_91839699.Person":{
                     "firstName":"abc",
                     "lastName":"abc", 
                     "hourlyRate":22,
                     "wage":100    
                  }
               }
            }
         },{
            "insert":{
               "out-identifier":"topicLevel",
               "object":{
                  "example.project4_91839699.Person":{
                     "firstName":"xyz",
                     "lastName":"xyz", 
                     "hourlyRate":24,
                     "wage":100    
                  }
               }
            }
         }
         {
            "fire-all-rules":""
         }
      ]
}


-------

Abhijit Humbe

On Fri, Jul 7, 2017 at 3:44 PM, <vijay...@rupeepower.com> wrote:


On Friday, July 7, 2017 at 3:26:40 PM UTC+5:30, vijay yadav wrote:
I get following error now.

{
  "type": "FAILURE",
  "msg": "Error calling container loasd: Error unmarshalling input",
  "result": null
}

and I am already using version 6.4

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

vijay yadav

unread,
Jul 12, 2017, 7:07:35 AM7/12/17
to Drools Usage
Not working. Still got the same error!!!


On Friday, July 7, 2017 at 2:54:28 PM UTC+5:30, vijay yadav wrote:

Maciej Swiderski

unread,
Jul 12, 2017, 9:25:27 AM7/12/17
to drools...@googlegroups.com
please pay attention what other reply to you as there is already all answers included - don’t use array for individual commands to insert multiple objects:

    "get-objects": { "out-identifier": "output" }
  }

Maciej

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

vijay yadav

unread,
Jul 15, 2017, 2:15:38 AM7/15/17
to Drools Usage
following is json request
{ 
   "lookup":"defaultStatelessKieSession",
   "commands":[ 
      { 
         "insert":{ 
            "object":{ 
               "com.redhat.demos.loandemo.Applicant":{ 
                "applicant_age":12.0
               }
            },
            "out-identifier":"applicant",
            "return-object":true

         }
      },
{ 
         "insert":{ 
            "object":{ 
               "com.redhat.demos.loandemo.CoApplicant":{ 
                "age":12.0
               }
            },
            "out-identifier":"applicant",
            "return-object":true

         }
      },
      { 
         "insert":{ 
            "out-identifier":"loan",
            "object":{ 

               "com.redhat.demos.loandemo.Loan":{ 
                  "tenure":5

               }
            },
            "return-object":true

         }
      },
      { 
         "fire-all-rules":""
 
      },
{ 
         "get-objects":{ 
            "out-identifier":"result"
         }
 
      }
   ]
}
 and following is the output i am getting.

{
  "type": "SUCCESS",
  "msg": "Container loandemo successfully called.",
  "result": {
    "execution-results": {
      "results": [
        {
          "key": "",
          "value": 1
        },
        {
          "key": "output",
          "value": [
            {
              "com.redhat.demos.loandemo.Loan": {
                "tenure": 5
              }
            },
            {
              "com.redhat.demos.loandemo.CoApplicant": {
                "age": 12
              }
            },
            {
              "com.redhat.demos.loandemo.Applicant": {
                "applicant_age": 12
              }
            }
          ]
        },
        {
          "key": "loan",
          "value": {
            "com.redhat.demos.loandemo.Loan": {
              "tenure": 5
            }
          }
        },
        {
          "key": "applicant",
          "value": {
            "com.redhat.demos.loandemo.CoApplicant": {
              "age": 12
            }
          }
        }
      ],
      "facts": [
        {
          "key": "loan",
          "value": {
            "org.drools.core.common.DefaultFactHandle": {
              "external-form": "0:3:368188141:-1807407624:3:DEFAULT:NON_TRAIT:java.util.LinkedHashMap"
            }
          }
        },
        {
          "key": "applicant",
          "value": {
            "org.drools.core.common.DefaultFactHandle": {
              "external-form": "0:2:99174126:-901609297:2:DEFAULT:NON_TRAIT:java.util.LinkedHashMap"
            }
          }
        }
      ]
    }
  }
}

Rules are not getting fired. please anyone help me.

Thanks




On Friday, July 7, 2017 at 2:54:28 PM UTC+5:30, vijay yadav wrote:

Daniel Paredes

unread,
Sep 28, 2017, 3:46:29 PM9/28/17
to Drools Usage
Hello, Could you find the error? I have a similar problem with arrays....

vijay yadav

unread,
Sep 29, 2017, 5:02:00 AM9/29/17
to Drools Usage

Yes,
please share your json format. I will tell you how to do it.

Daniel Paredes

unread,
Sep 29, 2017, 8:39:47 AM9/29/17
to Drools Usage
Hello Vijay thanks for your response.

I have this basic rules... y want to know how can I test it when, for e,xample I have 2 flights? it is possible?
package example.flights3;

//from row number: 1
//REGLA 1
rule "Row 1 test1TD"
    activation-group "first-hit-policy-group test1TD"
    dialect "mvel"
    when
        f1 : Flight( marketingCarrier == "AA" , number < "911" )
        f2 : Flight( marketingCarrier == "BB" )
    then
        f1.setMarketingCarrier( "ZZZ" );
end

//from row number: 2
//REGLA 2
rule "Row 2 test1TD"
    activation-group "first-hit-policy-group test1TD"
    dialect "mvel"
    when
        f1 : Flight( marketingCarrier == "BB" , number < "1100" )
    then
        f1.setMarketingCarrier( "YYY" );
end

and another thing is if it is possible to send and array of, in this case flights. This is my simple object:
package example.flights3;

/**
 * This class was automatically generated by the data modeler tool.
 */

public class Flight implements java.io.Serializable {

    static final long serialVersionUID = 1L;

    private java.lang.String marketingCarrier;

    private java.lang.String number;

    public Flight() {
    }

    public java.lang.String getMarketingCarrier() {
        return this.marketingCarrier;
    }

    public void setMarketingCarrier(java.lang.String marketingCarrier) {
        this.marketingCarrier = marketingCarrier;
    }

    public java.lang.String getNumber() {
        return this.number;
    }

    public void setNumber(java.lang.String number) {
        this.number = number;
    }

    public Flight(java.lang.String marketingCarrier, java.lang.String number) {
        this.marketingCarrier = marketingCarrier;
        this.number = number;
    }

}




Sorry, I am beginning with Drools. I work with KIE Workbench and the Kie Server and I also use Postman for send the request.
Thanks.





El viernes, 7 de julio de 2017, 6:24:28 (UTC-3), vijay yadav escribió:

Daniel Paredes

unread,
Sep 29, 2017, 10:00:18 AM9/29/17
to Drools Usage
Or here I have an example of a rule with a list:

package example.pruebapersona;

import example.pruebapersona.Persona;
import example.pruebapersona.Direccion;


rule "rule 1"
when
    person: Persona($d:dire)
    Direccion(ciudad=="jujuy",pais=="argentina") from $d
then
    person.setNombre("juan");
end

how can I send the information in the Json, Something like this give me an error:

{
    "commands":[
      {
         "insert":{
            "out-identifier":"Cliente",
            "return-object":"true",
            "object":{
                 "example.pruebapersona.Persona":
                     {
                         "dire":[
                                {
                                    "ciudad":"jujuy",
                                    "pais":"argentina"
                                }
                                ]
                    }
                   
            }
          }
      },
      {
         "fire-all-rules":
         {
            "out-identifier": "firedActivations"
         }
      }
    ]

 }



El viernes, 7 de julio de 2017, 6:24:28 (UTC-3), vijay yadav escribió:
Reply all
Reply to author
Forward
0 new messages