Catching Errors in Route Definition

13 views
Skip to first unread message

cobo lus

unread,
Apr 7, 2021, 7:32:15 AM4/7/21
to ipf-user
Hi !

I want to use the xds-iti43 component so that I can retrieve documents.
My issue is that I don't know how to handle exceptions if they occure inside my code or the xds-iti43 component.
Fe. if I give create a RetrieveDocumentSet response with Status SUCCESS and a document that points to a datahandler which uses a filedatasource and the file doesn't exist I get a FileNotFoundException but the calling application will get the SUCCESS response as the FNFE is not somehow catched somewhere and doesn't stop the route.

here the sample route I try to create:

((TryDefinition)from("xds-iti43:iti43")
.doTry()
.log("Got Retrieve Document Transaction: ${bodyAs(org.openehealth.ipf.commons.ihe.xds.core.requests.RetrieveDocumentSet)}")
.process(XdsCamelValidators.iti43RequestValidator())
.convertBodyTo(RetrieveDocumentSet.class)
.bean(MyBean.class,"retrieve")
.process(XdsCamelValidators.iti43ResponseValidator()))
.doCatch(Exception.class)
.bean( MyBean .class,"errorResponse")
.endDoTry();

anyone knows what I might be doing wrong ?

Quentin Ligier

unread,
Apr 13, 2021, 2:56:21 PM4/13/21
to ipf-user
Hi,

When configuring my route builder, I use the following pattern in the configure() method:
onException(InternalException.class)
    .log("ITI-43 route: caught InternalException: ${exception.message}")
    .handled(true)
    .maximumRedeliveries(2)
    .delay(500)
    .bean(Iti43ResponseConverter.class)
    .stop();

onException(Exception.class)
    .log("ITI-43 route: caught Exception: ${exception.message}")
    .handled(true)
    .bean(Iti43ResponseConverter.class)
    .stop();

from("xds-iti43:xds/iti43")
    .routeId("xds-iti43-consumer")
    .bean(Iti43QueryValidator.class)
    .bean(Iti43QueryConverter.class)
    .bean(RetrieveDocumentsProcessor.class)
    .bean(Iti43ResponseConverter.class)
    .process(iti43ResponseValidator());

I declare exception handling before the actual route. It works well for me, you could try it.

Kind regards,
Quentin
Reply all
Reply to author
Forward
0 new messages