Optaplanner 7.9.0无法解组输入字符串错误,调用REST API

时间:2018-08-07 15:10:22

标签: rest drools optaplanner kie

您好,我是关于optaplanner的新手,因此在wildfly 11上安装了最新版本的kie-wb和kie-server(7.9)之后,我尝试通过示例项目来了解如何使用Optaplanner功能。 我安装了两个内置示例:optaCloud和Employee_rostering示例。首先,一切正常,然后在其余客户端运行良好的情况下,通过SOAPUI安装,配置并部署到kie-server和REST api调用(还提交xml|json示例数据以获取解决方案)。

对于第二个,安装和部署也可以,但是主要问题在于,官方文档中没有示例数据(xml|json),无法通过邮寄方式提交给求解器以请求解决方案。

在Google搜索之后,终于,我在红帽网站(Employee Rostering sample)上找到了这篇文章...阅读内容,我可以看到它是相同的示例(数据模型,数据对象和drl规则) )出现在我上面使用的kie-wb示例项目“ Employee_rostering”中。 因此,我尝试使用本文中的xml数据示例将解决方案请求提交给求解器。问题似乎与该xml示例数据有关,实际上当我使用xml主体以SOAPUI提交其余请求时,kie-server的响应为500 Internal Server Error,主体为:

<data contentType="text/plain;charset=UTF-8" contentLength="2950">
  <![CDATA["Unexpected error during processing: Can't unmarshall input string: 
    <employeerostering.employeerostering.EmployeeRoster>
        <employeeList>
          <employeerostering.employeerostering.Employee>
            <name>John</name>
              <skills>
        ....

有人对此有经验吗?任何建议/信息都非常感谢

谢谢

1 个答案:

答案 0 :(得分:0)

[已解决] REST请求必须包含以下标头

authorization: Basic cGxhbm5lcjpQbGFubmVyMTIzXw==
X-KIE-ContentType: xstream
content-type: application/xml

在SOAP-UI中,我添加了一个自定义标头X-KIE-ContentType: xstream(基本身份验证和内容类型已经可以)。 这是我成功提交给求解器的示例XML正文内容

        <employeerostering.employeerostering.EmployeeRoster>
          <employeeList>
            <employeerostering.employeerostering.Employee>
              <name>John</name>
              <skills>
                <employeerostering.employeerostering.Skill>
                  <name>reading</name>
                </employeerostering.employeerostering.Skill>
              </skills>
            </employeerostering.employeerostering.Employee>
            <employeerostering.employeerostering.Employee>
              <name>Mary</name>
              <skills>
                <employeerostering.employeerostering.Skill>
                  <name>writing</name>
                </employeerostering.employeerostering.Skill>
              </skills>
            </employeerostering.employeerostering.Employee>
            <employeerostering.employeerostering.Employee>
              <name>Petr</name>
              <skills>
                <employeerostering.employeerostering.Skill>
                  <name>speaking</name>
                </employeerostering.employeerostering.Skill>
              </skills>
            </employeerostering.employeerostering.Employee>
          </employeeList>
          <shiftList>
            <employeerostering.employeerostering.Shift>
              <timeslot>
                <startTime>2017-01-01T00:00:00</startTime>
                <endTime>2017-01-01T01:00:00</endTime>
              </timeslot>
              <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/>
            </employeerostering.employeerostering.Shift>
            <employeerostering.employeerostering.Shift>
              <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/>
              <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/>
            </employeerostering.employeerostering.Shift>
            <employeerostering.employeerostering.Shift>
              <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/>
              <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/>
            </employeerostering.employeerostering.Shift>
          </shiftList>
          <skillList>
            <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/>
            <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/>
            <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/>
          </skillList>
          <timeslotList>
            <employeerostering.employeerostering.Timeslot reference="../../shiftList/employeerostering.employeerostering.Shift/timeslot"/>
          </timeslotList>
          <dayOffRequestList/>
          <shiftAssignmentList>
            <employeerostering.employeerostering.ShiftAssignment>
                <shift reference="../../../shiftList/employeerostering.employeerostering.Shift" />
            </employeerostering.employeerostering.ShiftAssignment>
            <employeerostering.employeerostering.ShiftAssignment>
                <shift reference="../../../shiftList/employeerostering.employeerostering.Shift[2]" />
            </employeerostering.employeerostering.ShiftAssignment>
          </shiftAssignmentList>
        </employeerostering.employeerostering.EmployeeRoster>

解决方案响应(作为JSON):

        {
            "container-id": "employeerostering_1.0.0-SNAPSHOT",
            "solver-id": "solver-1",
            "solver-config-file": "employeerostering/employeerostering/EmployeeRosteringSolverConfig.solver.xml",
            "status": "SOLVING",
            "score": {
                "value": "0hard/-2soft",
                "scoreClass": "org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore"
            },
            "best-solution": {
                "employeerostering.employeerostering.EmployeeRoster": {
                    "employeeList": [
                        {
                            "name": "John",
                            "skills": [
                                {
                                    "name": "reading"
                                }
                            ]
                        },
                        {
                            "name": "Mary",
                            "skills": [
                                {
                                    "name": "writing"
                                }
                            ]
                        },
                        {
                            "name": "Petr",
                            "skills": [
                                {
                                    "name": "speaking"
                                }
                            ]
                        }
                    ],
                    "shiftList": [
                        {
                            "timeslot": {
                                "startTime": {
                                    "dayOfYear": 1,
                                    "dayOfWeek": "SUNDAY",
                                    "dayOfMonth": 1,
                                    "monthValue": 1,
                                    "year": 2017,
                                    "month": "JANUARY",
                                    "hour": 0,
                                    "minute": 0,
                                    "second": 0,
                                    "nano": 0,
                                    "chronology": {
                                        "calendarType": "iso8601",
                                        "id": "ISO"
                                    }
                                },
                                "endTime": {
                                    "dayOfYear": 1,
                                    "dayOfWeek": "SUNDAY",
                                    "dayOfMonth": 1,
                                    "monthValue": 1,
                                    "year": 2017,
                                    "month": "JANUARY",
                                    "hour": 1,
                                    "minute": 0,
                                    "second": 0,
                                    "nano": 0,
                                    "chronology": {
                                        "calendarType": "iso8601",
                                        "id": "ISO"
                                    }
                                }
                            },
                            "requiredSkill": {
                                "name": "reading"
                            }
                        },
                        {
                            "timeslot": {
                                "startTime": {
                                    "dayOfYear": 1,
                                    "dayOfWeek": "SUNDAY",
                                    "dayOfMonth": 1,
                                    "monthValue": 1,
                                    "year": 2017,
                                    "month": "JANUARY",
                                    "hour": 0,
                                    "minute": 0,
                                    "second": 0,
                                    "nano": 0,
                                    "chronology": {
                                        "calendarType": "iso8601",
                                        "id": "ISO"
                                    }
                                },
                                "endTime": {
                                    "dayOfYear": 1,
                                    "dayOfWeek": "SUNDAY",
                                    "dayOfMonth": 1,
                                    "monthValue": 1,
                                    "year": 2017,
                                    "month": "JANUARY",
                                    "hour": 1,
                                    "minute": 0,
                                    "second": 0,
                                    "nano": 0,
                                    "chronology": {
                                        "calendarType": "iso8601",
                                        "id": "ISO"
                                    }
                                }
                            },
                            "requiredSkill": {
                                "name": "speaking"
                            }
                        },
                        {
                            "timeslot": {
                                "startTime": {
                                    "dayOfYear": 1,
                                    "dayOfWeek": "SUNDAY",
                                    "dayOfMonth": 1,
                                    "monthValue": 1,
                                    "year": 2017,
                                    "month": "JANUARY",
                                    "hour": 0,
                                    "minute": 0,
                                    "second": 0,
                                    "nano": 0,
                                    "chronology": {
                                        "calendarType": "iso8601",
                                        "id": "ISO"
                                    }
                                },
                                "endTime": {
                                    "dayOfYear": 1,
                                    "dayOfWeek": "SUNDAY",
                                    "dayOfMonth": 1,
                                    "monthValue": 1,
                                    "year": 2017,
                                    "month": "JANUARY",
                                    "hour": 1,
                                    "minute": 0,
                                    "second": 0,
                                    "nano": 0,
                                    "chronology": {
                                        "calendarType": "iso8601",
                                        "id": "ISO"
                                    }
                                }
                            },
                            "requiredSkill": {
                                "name": "writing"
                            }
                        }
                    ],
                    "skillList": [
                        {
                            "name": "reading"
                        },
                        {
                            "name": "speaking"
                        },
                        {
                            "name": "writing"
                        }
                    ],
                    "timeslotList": [
                        {
                            "startTime": {
                                "dayOfYear": 1,
                                "dayOfWeek": "SUNDAY",
                                "dayOfMonth": 1,
                                "monthValue": 1,
                                "year": 2017,
                                "month": "JANUARY",
                                "hour": 0,
                                "minute": 0,
                                "second": 0,
                                "nano": 0,
                                "chronology": {
                                    "calendarType": "iso8601",
                                    "id": "ISO"
                                }
                            },
                            "endTime": {
                                "dayOfYear": 1,
                                "dayOfWeek": "SUNDAY",
                                "dayOfMonth": 1,
                                "monthValue": 1,
                                "year": 2017,
                                "month": "JANUARY",
                                "hour": 1,
                                "minute": 0,
                                "second": 0,
                                "nano": 0,
                                "chronology": {
                                    "calendarType": "iso8601",
                                    "id": "ISO"
                                }
                            }
                        }
                    ],
                    "dayOffRequestList": [],
                    "shiftAssignmentList": [
                        {
                            "shift": {
                                "timeslot": {
                                    "startTime": {
                                        "dayOfYear": 1,
                                        "dayOfWeek": "SUNDAY",
                                        "dayOfMonth": 1,
                                        "monthValue": 1,
                                        "year": 2017,
                                        "month": "JANUARY",
                                        "hour": 0,
                                        "minute": 0,
                                        "second": 0,
                                        "nano": 0,
                                        "chronology": {
                                            "calendarType": "iso8601",
                                            "id": "ISO"
                                        }
                                    },
                                    "endTime": {
                                        "dayOfYear": 1,
                                        "dayOfWeek": "SUNDAY",
                                        "dayOfMonth": 1,
                                        "monthValue": 1,
                                        "year": 2017,
                                        "month": "JANUARY",
                                        "hour": 1,
                                        "minute": 0,
                                        "second": 0,
                                        "nano": 0,
                                        "chronology": {
                                            "calendarType": "iso8601",
                                            "id": "ISO"
                                        }
                                    }
                                },
                                "requiredSkill": {
                                    "name": "reading"
                                }
                            },
                            "employee": {
                                "name": "John",
                                "skills": [
                                    {
                                        "name": "reading"
                                    }
                                ]
                            }
                        },
                        {
                            "shift": {
                                "timeslot": {
                                    "startTime": {
                                        "dayOfYear": 1,
                                        "dayOfWeek": "SUNDAY",
                                        "dayOfMonth": 1,
                                        "monthValue": 1,
                                        "year": 2017,
                                        "month": "JANUARY",
                                        "hour": 0,
                                        "minute": 0,
                                        "second": 0,
                                        "nano": 0,
                                        "chronology": {
                                            "calendarType": "iso8601",
                                            "id": "ISO"
                                        }
                                    },
                                    "endTime": {
                                        "dayOfYear": 1,
                                        "dayOfWeek": "SUNDAY",
                                        "dayOfMonth": 1,
                                        "monthValue": 1,
                                        "year": 2017,
                                        "month": "JANUARY",
                                        "hour": 1,
                                        "minute": 0,
                                        "second": 0,
                                        "nano": 0,
                                        "chronology": {
                                            "calendarType": "iso8601",
                                            "id": "ISO"
                                        }
                                    }
                                },
                                "requiredSkill": {
                                    "name": "speaking"
                                }
                            },
                            "employee": {
                                "name": "Petr",
                                "skills": [
                                    {
                                        "name": "speaking"
                                    }
                                ]
                            }
                        }
                    ],
                    "score": "0hard/-2soft"
                }
            }
        }