问题
I could setup KIE Execution Server (6.3.0.Final) and Workbench (6.3.0.Final) on Wildfly 8.1.0.Final using information available in blog: http://mswiderski.blogspot.in/2015/10/installing-kie-server-and-workbench-on.html Both server and Workbench are working fine and Server is visible in Workbench under "Server Management Browser" tab.
My next step is to deploy a simple container on server and test REST GET and POST calls, hence I followed steps mentioned in Question: HelloWorld using Drools Workbench & KIE Server
The only change in Java and DRL code is with respect to package. Below is my Java code:
package test.myproject;
/**
* This class was automatically generated by the data modeler tool.
*/
public class HelloWorld implements java.io.Serializable
{
static final long serialVersionUID = 1L;
private java.lang.String message;
public HelloWorld()
{
}
public java.lang.String getMessage()
{
return this.message;
}
public void setMessage(java.lang.String message)
{
this.message = message;
}
public HelloWorld(java.lang.String message)
{
this.message = message;
}
}
DRL file code:
package test.myproject;
import test.myproject.HelloWorld;
rule "hello"
when
HelloWorld(message == "Joe");
then
System.out.println("Hello Joe!");
end
The code is built successfully and deployed as container on the server. A GET Query using RESTClient/PostMan/Advanced REST Client gives proper response.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response type="SUCCESS" msg="Info for container myproject">
<kie-container container-id="myproject" status="STARTED">
<release-id>
<artifact-id>MyProject</artifact-id>
<group-id>test</group-id>
<version>1.0</version>
</release-id>
<resolved-release-id>
<artifact-id>MyProject</artifact-id>
<group-id>test</group-id>
<version>1.0</version>
</resolved-release-id>
<scanner status="DISPOSED"/>
</kie-container>
</response>
However When I POST to container with below content:
<batch-execution lookup="defaultKieSession">
<insert out-identifier="message" return-object="true" entrypoint="DEFAULT">
<test.myproject.HelloWorld>
<message>Joe</message>
</test.myproject.HelloWorld>
</insert>
Note that I did make changes to XML as per change in code. I did try with different options like etc, but I get response as :
Status Code: 405 Method Not Allowed
Allow: HEAD, DELETE, GET, OPTIONS, PUT
Cache-Control: no-cache, no-store, must-revalidate
Connection: keep-alive
Content-Length: 0
Date: Thu, 10 Dec 2015 05:29:09 GMT
Expires: 0
Pragma: no-cache
Server: WildFly/8
X-Powered-By: Undertow/1
Looks like POST option is not allowed, Hence tried PUT but got response as:
Status Code: 415 Unsupported Media Type
Cache-Control: no-cache, no-store, must-revalidate
Connection: keep-alive
Content-Length: 0
Date: Thu, 10 Dec 2015 05:32:17 GMT
Expires: 0
Pragma: no-cache
Server: WildFly/8
X-Powered-By: Undertow/1
Can anyone tell me where I am going wrong. I also checked log file and see below error when POST is called:
2015-12-10 10:59:09,208 WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-48) failed to execute: javax.ws.rs.NotAllowedException: No resource method found for POST, return 405 with Allow header at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:375) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:114) [resteasy-jaxrs-3.0.8.Final.jar:]
and error when PUT is called:
2015-12-10 11:02:17,127 WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-50) failed to execute: javax.ws.rs.NotSupportedException: Cannot consume content type at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:380) [resteasy-jaxrs-3.0.8.Final.jar:] at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:114) [resteasy-jaxrs-3.0.8.Final.jar:]
回答1:
It is working now. Changes needed are as follows:
URL to call during POST is : http://localhost:8080/kie-server/services/rest/server/containers/instances/myproject
From 6.3.0 onward instances needs to be used (Make note of it :))
KIE Server in 6.3.0 supports JAXB, JSON and Xstream. Since default is JAXB you would need to provide JAXB valid content. Alternatively you could set HTTP header to inform KIE Server to use Xstream as marshaller: Header name: X-KIE-ContentType Header Value XSTREAM
Hence set proper header
Finally XML should be in the form:
<batch-execution lookup="defaultKieSession">
<insert out-identifier="test">
<test.myproject.HelloWorld>
<message>"Joe"</message>
</test.myproject.HelloWorld>
</insert>
<fire-all-rules/>
<get-objects out-identifier="test"/>
</batch-execution>
Watch out the output "Hello Joe!" in command prompt.
Thanks to Maciej Swiderski for all the support
来源:https://stackoverflow.com/questions/34194475/helloworld-on-kie-workbench-and-kie-server-version-6-3-0