我需要根据某种模式验证对骆驼休息服务的传入请求。例如。
根据要求,如下所示
{
"routeId" : "fileBatchRoute",
"action" : "start",
"sourceLocation" : "sourceDirectory",
"destinationLocation" : "destinationDirectory"
}
上述请求应根据以下条件进行验证
1. 必须包含action元素,格式如上。
2. RouteId 应存在。
您可以使用json 验证器 https://github.com/apache/camel/blob/master/components/camel-json-validator/src/main/docs/json-validator-component.adoc成分。
借助架构生成工具可以帮助您JSONschema.net https://www.jsonschema.net/.
根据您的要求(需要routeId,需要操作,并且是“开始”、“停止”、“暂停”、“恢复”之一),架构可能类似于:
路线架构.json:
{
"definitions": {},
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"routeId",
"action"
],
"properties": {
"routeId": {
"type": "string"
},
"action": {
"type": "string",
"enum": [
"start",
"stop",
"suspend",
"resume"
]
},
"sourceLocation": {
"type": "string"
},
"destinationLocation": {
"type": "string"
}
}
}
路线定义:
.to("json-validator:routeSchema.json")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)