Can I split compressed files into json components in Camel via Spring DSL

345 views Asked by At

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": ""
            }
        }]
    }
}
]
1

There are 1 answers

5
Adam Hawkes On

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>