HelloWorld using Drools Workbench & KIE Server



将KIE Drools Workbench 6.2.0 Final安装在JBoss 7 Application Server本地实例中,将KIE Server 6.2.0 Final安装在本地Tomcat 7实例中。

使用基于web的KIE工作台严格用于评估目的(我使用它来编码生成基于Java的Maven项目,我不使用特定的IDE,如Eclipse或IntelliJ IDEA):

  1. 创建一个名为testRepo的新存储库

  2. 创建一个名为HelloWorld的新项目

  3. 创建了一个名为HelloWorld的新数据对象,并带有一个名为message的字符串属性:

    package demo;
    /**
     * 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;
      }
    } 
    
  4. 创建一个包含以下内容的新DRL:

    package demo;
    import demo.HelloWorld;
    rule "hello"
    when 
        HelloWorld(message == "Joe");
    then
        System.out.println("Hello Joe!");
    end
    
  5. 当我把它部署到我的Kie服务器在这个URL下:

http://localhost: 8080/kie-server-6.2.0.Final-webc/服务/rest/服务器/集装箱/helloworld

当我在Google Chrome中复制并粘贴上述URL时,我得到以下响应:

<response type="SUCCESS" msg="Info for container hello">
<kie-container container-id="hello" status="STARTED">
    <release-id>
        <artifact-id>Hello</artifact-id>
        <group-id>demo</group-id>
        <version>1.0</version>
    </release-id>
    <resolved-release-id>
        <artifact-id>Hello</artifact-id>
        <group-id>demo</group-id>
        <version>1.0</version>
    </resolved-release-id>
    <scanner status="DISPOSED"/>
</kie-container>
</response>
  • 当我尝试使用以下有效载荷(使用Postman或SoapUI)做POST时:

    <batch-execution lookup="defaultKieSession">
    <insert out-identifier="message" return-object="true" entrypoint="DEFAULT">
        <demo.HelloWorld>
            <message>Joe</message>
        <demo.HelloWorld>
    </insert>
    

  • 收到以下信息:

    HTTP状态415 -不能使用内容类型状态报告消息不能使用内容类型

  • 服务器拒绝此请求,因为请求实体的格式不被所请求的资源所支持。

    我可能做错了什么?我进入部署->规则部署,注册了我的key -server,并创建了一个名为helloworld的容器,从步骤5中可以看到,它工作了。也许我没有正确地部署它?

    顺便说一句,我使用以下Stack Overflow帖子作为基础(在问这个问题之前)…

    大多数来自Google的搜索结果只是解释如何通过设置基于Maven的项目以编程方式创建Drools项目。我正在评估KIE Drools Workbench,以了解非技术人员如何轻松地使用KIE Drools Workbench生成基于Drools的规则并执行它们。

    我错过了一个步骤吗?在Tomcat 7下,它只包含apache-tomcat-7.0.64/webapps/kee -server-6.2.0. final -webc下的以下目录:

    meta - inf

    web - inf

    您在POST请求头中使用的内容类型是什么?据我所知,如果您没有在请求头中提供content-type: application/xml,则会发生错误消息。

    希望有帮助,

    你还好吗?

    Esteban的响应是正确的,但是,您应该添加另一个标头,您需要添加的标头是"Authorization",并且Authorization的值是您注册到您的应用程序领域到您的key -server的base64转换的用户。例如:

    kieserver:系统* 01

    转换为base64:

    a2llc2VydmVyOnN5c3RlbSowMQ = =

    无论如何,我的请求的完整头是这样的:
    Authorization : Basic a2llc2VydmVyOnN5c3RlbSowMQ==
    Content-Type  : application/xml
    

    希望对你有帮助。

    对不起我的英语!:)

    我得到了它的工作与使用邮差(Chrome应用程序/插件)与授权选项卡选择为No Auth。非常酷的回答!

    <response type="SUCCESS" msg="Container helloworld successfully called.">
         <results>
             <![CDATA[<execution-results>
               <result identifier="message">
                    <demo.HelloWorld>
                        <message>Joe</message>
                    </demo.HelloWorld>
               </result>
               <fact-handle identifier="message" external-form="0:4:1864164041:1864164041:4:DEFAULT:NON_TRAIT"/>
    </execution-results>]]>
               </results>
    </response>
    

    最新更新