我可以通过 Spring DSL 将压缩文件拆分为 Camel 中的 json 组件吗 [英] Can I split compressed files into json components in Camel via Spring DSL

查看:13
本文介绍了我可以通过 Spring DSL 将压缩文件拆分为 Camel 中的 json 组件吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,我需要获取一个包含与此示例非常相似的 json 的 gzipped 文件,将其解压缩(我知道如何执行此操作),将每个 json 对象作为字符串并将其从它所在的位置推送到 AMQ弹出一个网络服务.我对一个对象的所有这些都很好,但我将收到一个代表数组的文件.如果这是一个字符串数组或 xml,我会看到 Camel 如何处理它,但我看不到拆分 json 的方法.此外,这将需要流式传输,因为这些文件可能非常大.编辑以尝试使请求更清晰,并提供示例 json.

<预><代码> [{rickenbackerRepair":{estimateId":22788411},修理店": {检查站点":{检验日期": ""},维修设施":{"companyIdCode": "",公司名": "",城市": "","州省": "",邮编/邮政编码": "",国家": ""},维修信息":{"guitarDateInShop": "","guitarTimeInShop": "","授权备忘录": "","guitarTargetCompletionDate": "","guitarTargetCompletionTime": "","吉他完成日期": "","吉他完成时间": ""},locationOfguitar":{城市": "","州省": "",邮编/邮政编码": "",国家": ""}},仪器标识符":{吉他": {索赔相关":{"primaryPointOfImpact": "","secondaryPointOfImpact": ""},鉴别": {"databaseguitarCode": "","制造州省": "",序列号": "","吉他条件": "",生产日期": "",年": "",模型": "","吉他类型": "",身材": "","trimCode": "","trimColor": "",选项列表":"}}},林":[{内部控制": {线指示器":"},部分": {描述": {"partType": "","descriptionJudgmentFlag": "","oemPartNumber": "","priceIncludedIndicator": "","alternatePartIndicator": "","taxableFlag": "","databasePartPrice": "","actualPartPrice": "","priceJudgmentFlag": "","certifiedFlag": "",数量": ""},非OEM供应商":{"companyIdCode": "","nonOemPartNumber": "","nonOemSupplierUserOverride": "","nonOemSupplierMemo": ""},调整": {百分": "",数量": ""}},劳工": {描述": {类型": "","actualHours": "","hoursJudgmentFlag": "","typeJudgmentFlag": ""},miscSublet":{数量": "","subletFlag": ""}}}],stl":{小计":[{"总类型": "","totalTypeCode": "",小计详细信息":{"taxableAmount": ""}}]}},{rickenbackerRepair":{estimateId":22788412},修理店": {检查站点":{检验日期": ""},维修设施":{"companyIdCode": "",公司名": "",城市": "","州省": "",邮编/邮政编码": "",国家": ""},维修信息":{"guitarDateInShop": "","guitarTimeInShop": "","授权备忘录": "","guitarTargetCompletionDate": "","guitarTargetCompletionTime": "","吉他完成日期": "","吉他完成时间": ""},locationOfguitar":{城市": "","州省": "",邮编/邮政编码": "",国家": ""}},仪器标识符":{吉他": {索赔相关":{"primaryPointOfImpact": "","secondaryPointOfImpact": ""},鉴别": {"databaseguitarCode": "","制造州省": "",序列号": "","吉他条件": "",生产日期": "",年": "",模型": "","吉他类型": "",身材": "","trimCode": "","trimColor": "",选项列表":"}}},林":[{内部控制": {线指示器":"},部分": {描述": {"partType": "","descriptionJudgmentFlag": "","oemPartNumber": "","priceIncludedIndicator": "","alternatePartIndicator": "","taxableFlag": "","databasePartPrice": "","actualPartPrice": "","priceJudgmentFlag": "","certifiedFlag": "",数量": ""},非OEM供应商":{"companyIdCode": "","nonOemPartNumber": "","nonOemSupplierUserOverride": "","nonOemSupplierMemo": ""},调整": {百分": "",数量": ""}},劳工": {描述": {类型": "","actualHours": "","hoursJudgmentFlag": "","typeJudgmentFlag": ""},miscSublet":{数量": "","subletFlag": ""}}}],stl":{小计":[{"总类型": "","totalTypeCode": "",小计详细信息":{"taxableAmount": ""}}]}}]

解决方案

您应该能够使用 jsonpath 表达式来拆分传入的消息(文件)并单独处理每个元素.

<from uri="file://path"/><拆分><jsonpath>$.</jsonpath><to uri="direct:doSomething"></拆分></路线>

In a nutshell, I need to take a gzipped file containing json very similar to this example, unzip it (I know how to do that), get each json object as a string and push it to AMQ from where it will be popped to a webservice. I'm fine with all of this with one object, but I will be receiving a file that represents an array. If this were an array of strings or xml, I see how Camel processes it, but I don't see a way to split json. Also, this will require streaming as these files can be very large. Edited to try to make request clearer, and provide a sample json.

 [
{
    "rickenbackerRepair": {
        "estimateId": 22788411
    },
    "repairShop": {
        "inspectionSite": {
            "inspectionDate": ""
        },
        "repairFacility": {
            "companyIdCode": "",
            "companyName": "",
            "city": "",
            "stateProvince": "",
            "zipPostalCode": "",
            "country": ""
        },
        "repairInformation": {
            "guitarDateInShop": "",
            "guitarTimeInShop": "",
            "authorizationMemo": "",
            "guitarTargetCompletionDate": "",
            "guitarTargetCompletionTime": "",
            "guitarCompletionDate": "",
            "guitarCompletionTime": ""
        },
        "locationOfguitar": {
            "city": "",
            "stateProvince": "",
            "zipPostalCode": "",
            "country": ""
        }
    },  
    "instrumentIdentifier": {
        "guitar": {
            "claimRelated": {
                "primaryPointOfImpact": "",
                "secondaryPointOfImpact": ""
            },
            "identification": {
                "databaseguitarCode": "",
                "manufacturingStateProvince": "",
                "serialNumber": "",
                "guitarCondition": "",
                "productionDate": "",
                "year": "",
                "model": "",
                "guitarType": "",
                "bodyStyle": "",
                "trimCode": "",
                "trimColor": "",
                "optionsList": ""
            }
        }
    },
    "lin": [{
        "internalControl": {
            "lineIndicator": ""
        },
        "part": {
            "description": {
                "partType": "",
                "descriptionJudgmentFlag": "",
                "oemPartNumber": "",
                "priceIncludedIndicator": "",
                "alternatePartIndicator": "",
                "taxableFlag": "",
                "databasePartPrice": "",
                "actualPartPrice": "",
                "priceJudgmentFlag": "",
                "certifiedFlag": "",
                "quantity": ""
            },
            "nonOemSupplier": {
                "companyIdCode": "",
                "nonOemPartNumber": "",
                "nonOemSupplierUserOverride": "",
                "nonOemSupplierMemo": ""
            },
            "adjustment": {
                "percent": "",
                "amount": ""
            }
        },
        "labor": {
            "description": {
                "type": "",
                "actualHours": "",
                "hoursJudgmentFlag": "",
                "typeJudgmentFlag": ""
            },
            "miscSublet": {
                "amount": "",
                "subletFlag": ""
            }
        }
    }],

    "stl": {
        "subtotal": [{
            "totalType": "",
            "totalTypeCode": "",
            "subtotalDetail": {
                "taxableAmount": ""
            }
        }]
    }
},
{
    "rickenbackerRepair": {
        "estimateId": 22788412
    },
    "repairShop": {
        "inspectionSite": {
            "inspectionDate": ""
        },
        "repairFacility": {
            "companyIdCode": "",
            "companyName": "",
            "city": "",
            "stateProvince": "",
            "zipPostalCode": "",
            "country": ""
        },
        "repairInformation": {
            "guitarDateInShop": "",
            "guitarTimeInShop": "",
            "authorizationMemo": "",
            "guitarTargetCompletionDate": "",
            "guitarTargetCompletionTime": "",
            "guitarCompletionDate": "",
            "guitarCompletionTime": ""
        },
        "locationOfguitar": {
            "city": "",
            "stateProvince": "",
            "zipPostalCode": "",
            "country": ""
        }
    },  
    "instrumentIdentifier": {
        "guitar": {
            "claimRelated": {
                "primaryPointOfImpact": "",
                "secondaryPointOfImpact": ""
            },
            "identification": {
                "databaseguitarCode": "",
                "manufacturingStateProvince": "",
                "serialNumber": "",
                "guitarCondition": "",
                "productionDate": "",
                "year": "",
                "model": "",
                "guitarType": "",
                "bodyStyle": "",
                "trimCode": "",
                "trimColor": "",
                "optionsList": ""
            }
        }
    },
    "lin": [{
        "internalControl": {
            "lineIndicator": ""
        },
        "part": {
            "description": {
                "partType": "",
                "descriptionJudgmentFlag": "",
                "oemPartNumber": "",
                "priceIncludedIndicator": "",
                "alternatePartIndicator": "",
                "taxableFlag": "",
                "databasePartPrice": "",
                "actualPartPrice": "",
                "priceJudgmentFlag": "",
                "certifiedFlag": "",
                "quantity": ""
            },
            "nonOemSupplier": {
                "companyIdCode": "",
                "nonOemPartNumber": "",
                "nonOemSupplierUserOverride": "",
                "nonOemSupplierMemo": ""
            },
            "adjustment": {
                "percent": "",
                "amount": ""
            }
        },
        "labor": {
            "description": {
                "type": "",
                "actualHours": "",
                "hoursJudgmentFlag": "",
                "typeJudgmentFlag": ""
            },
            "miscSublet": {
                "amount": "",
                "subletFlag": ""
            }
        }
    }],

    "stl": {
        "subtotal": [{
            "totalType": "",
            "totalTypeCode": "",
            "subtotalDetail": {
                "taxableAmount": ""
            }
        }]
    }
}
]

解决方案

You should be able to use a jsonpath expression to split the incoming message (file) and process each element individually.

<route>
  <from uri="file://path" />
  <split>
    <jsonpath>$.</jsonpath>
    <to uri="direct:doSomething">
  </split>
</route>

这篇关于我可以通过 Spring DSL 将压缩文件拆分为 Camel 中的 json 组件吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆