REST API Json Cast Command Error

1,042 views
Skip to first unread message

Vicente Hidalgo Santamaria

unread,
Apr 20, 2016, 7:02:44 AM4/20/16
to Drools Usage
I'm getting a cast error when calling the Rest API with Json commands. The request body is very simple. The same request with XStream works perfectly. 

I'm using the following headers:
X-KIE-ContentType: json
Content-Type: application/json 

Json Request body:
{
   "batch-execution":{
      "lookup":"ksession1",
      "commands":[
         {
            "insert":{  
               "object":{  
                  "com.vicente.auto.Car":{  
                     "brand":"john",
                     "wheels":"25"
                  }
               }
            }
         },
         {
            "fire-all-rules":""
         }
      ]
   }
}

Java Class:
package com.vicente.auto;


import javax.annotation.Generated;

@Generated("org.jsonschema2pojo")
public class Car {

private String brand;
private String wheels;

/**
* No args constructor for use in serialization
*
*/
public Car() {
}

/**
*
* @param wheels
* @param brand
*/
public Car(String brand, String wheels) {
this.brand = brand;
this.wheels = wheels;
}

/**
*
* @return
* The brand
*/
public String getBrand() {
return brand;
}

/**
*
* @param brand
* The brand
*/
public void setBrand(String brand) {
this.brand = brand;
}

/**
*
* @return
* The wheels
*/
public String getWheels() {
return wheels;
}

/**
*
* @param wheels
* The wheels
*/
public void setWheels(String wheels) {
this.wheels = wheels;
}

}

Drl:
package com.vicente.auto;


rule "count Wheels"
dialect "mvel"
when
Car( $numWheels : getWheels())
then
System.out.println("Num Wheels: "+ $numWheels);
end




Error Trace:
12:14:02,741 ERROR [org.kie.server.services.drools.DroolsKieContainerCommandServiceImpl] (default task-10) Error calling container 'car': java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to org.kie.api.command.Command
at org.kie.server.services.drools.DroolsKieContainerCommandServiceImpl.callContainer(DroolsKieContainerCommandServiceImpl.java:59) [kie-server-services-drools-6.4.0.Final.jar:6.4.0.Final]
at org.kie.server.remote.rest.drools.CommandResource.manageContainer(CommandResource.java:72) [kie-server-rest-drools-6.4.0.Final.jar:6.4.0.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_65]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) [resteasy-jaxrs-3.0.10.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) [resteasy-jaxrs-3.0.10.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) [resteasy-jaxrs-3.0.10.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) [resteasy-jaxrs-3.0.10.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.10.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.10.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.10.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.10.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.10.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_65]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_65]


Vicente Hidalgo Santamaria

unread,
Apr 20, 2016, 7:04:25 AM4/20/16
to Drools Usage
Using KIE 6.4.0

Maciej Swiderski

unread,
Apr 20, 2016, 7:24:07 AM4/20/16
to drools...@googlegroups.com
the payload of your request should be:

{
      "lookup":"ksession1",
      "commands":[
         {
            "insert":{  
               "object":{  
                  "com.vicente.auto.Car":{  
                     "brand":"john",
                     "wheels":"25"
                  }
               }
            }
         },
         {
            "fire-all-rules":""
         }
      ]
   }
just skip the batch-execution part and it should work

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/becfa3aa-05c1-4b20-b408-b9d605cfd018%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Diego Mendez

unread,
Jun 29, 2016, 10:29:40 AM6/29/16
to Drools Usage
Hi,
I came across with the same problem. 
I have reassembled your code, and I'm still having the same error:
{
"org.kie.server.api.model.ServiceResponse": {
"type": "FAILURE"
"msg": "Error calling container vicenteDrools: java.util.LinkedHashMap cannot be cast to org.kie.api.command.Command"
"result": null
}-
}

I'm using wildfly 8.2.0 + kie-server-6.4.0.Final-ee7.war.

Here's my proyect and the server log. Please, take a look 
thx.

srinivas rao

unread,
Oct 16, 2016, 1:45:11 AM10/16/16
to Drools Usage
hey even ia m facing same issue from past 2 months maciej can u help on this  changed payload how u said but still the same error.

srinivas rao

unread,
Oct 16, 2016, 2:02:12 AM10/16/16
to Drools Usage

Maciej Swiderski

unread,
Oct 16, 2016, 12:24:33 PM10/16/16
to drools...@googlegroups.com
Describe what you have now and what errors 

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.

Alok Singh

unread,
Oct 27, 2016, 7:26:48 AM10/27/16
to Drools Usage

My Input to the KIE Server(ver: 6.4) is:
<batch-execution>
  <insert out-identifier="productBeanList" return-object="true" entry-point="DEFAULT">
    <hmorgunit.Discount>
      <userRole>C1</userRole>
      <organization>HM</organization>
    </hmorgunit.Discount>
  </insert>
</batch-execution>

and getting response as:


The filteredProductJson:<org.kie.server.api.model.ServiceResponse>
  <type>FAILURE</type>
  <msg>Error calling container Test:  : input contained no data</msg>
</org.kie.server.api.model.ServiceResponse>


Please suggest.

Marco De Luca

unread,
May 14, 2017, 5:36:41 PM5/14/17
to Drools Usage
same exception on my kie-server, even using the suggested json, such as

{     "lookup":"ksession1",
      "commands":[
       
         {
            "fire-all-rules":""
         }
      ]}

Emmanuel Bonnet

unread,
May 26, 2017, 10:45:00 AM5/26/17
to Drools Usage
Hi guys,
I ran into exactly the same problem and it took me a while to understand it. Basically it all comes to this : you model must be perfectly serializable.
  • implement properly serializable for classes
  • If you have fancy stuff like enum with codes or whatever, annotated them with jackson properties for ex.

I had the same symptom and it disappeared when I solved that model issue.

Best,
Emmanuel

trying drools

unread,
Aug 16, 2018, 6:00:45 PM8/16/18
to Drools Usage
Hi All,

I am also getting similar error.

"{
  "type" : "FAILURE",
  "msg" : "Error calling container drools_1.0.0: java.util.LinkedHashMap cannot be cast to org.kie.api.command.Command",
  "result" : null
}"

Please suggest.Thanks in advance.

Thanks,
Pradeep

Chris Taylor

unread,
Sep 17, 2018, 3:39:53 PM9/17/18
to Drools Usage
Have you received or determined a resolution for this?

Chris Taylor

unread,
Sep 19, 2018, 1:10:03 PM9/19/18
to Drools Usage
Not certain if all occurrences of the error "java.util.LinkedHashMap cannot be cast to org.kie.api.command.Command" when invoking rules over Rest/JSON API are the same cause, but in my case I believe it was due to some classloader issues. My project had Maven drools dependencies which I had to scope specifically as "provided" so my app did not build and provide them. This resolved the issue
Reply all
Reply to author
Forward
0 new messages