frankframework / frankframework

The Frank!Framework is an easy-to-use, stateless integration framework which allows (transactional) messages to be modified and exchanged between different systems.
https://frankframework.org
Apache License 2.0
130 stars 78 forks source link

Proposals for simplifying error handling with HttpSender #4500

Open mhdirkse opened 1 year ago

mhdirkse commented 1 year ago

Describe the issue I have a HttpSender and I want to handle errors indicated by a negative HTTP response code. The HttpSender provides a forward for every possible HTTP code, but implementing all these forwards introduces a lot of boilerplate code. I also looked at the forwards provided by the SenderPipe, but I did not see a forward that would be triggered by a 4xx or 5xx response code. I tried to give my SenderPipe only a "success" forward and putting a pipe below that for the error handling. This did not work because the success forward was also followed for a 5xx response code.

After discussing with Jaco de Groot I propose that the following features are added:

With these changes, you could give the SenderPipe two forwards "2xx" and "notFound" where the "notFound" forward should be the value of attribute notFoundForwardName.

Reporter Martijn Dirkse

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Screenshots If applicable, add screenshots to help explain your problem.

Configuration

Please provide the configuration of the Pipe or Receiver with the problem.

Input

Please provide an example of the input message. 
Alternatively, provide a Ladybug report.

Environment

Please go to the console of your Frank, click on 'Information' and copy-paste the results here. 

Additional Environment

Additional Context The context of this issue is the ZaakBrug project. I have a HttpSender that issues requests to OpenZaak. I want to add simple error handling: a single flow for any error response from OpenZaak.

nielsm5 commented 1 year ago

Perhaps it would help if you would show us how you configured your HttpSender. Each status code can be used as a forward, success (200/201/202/204/206) it is also possible to treat follow redirects (301/302/307) as success. Other status codes will use the statuscode as the name of the foward (if this forward exists).

mhdirkse commented 1 year ago

This is how I am trying to get along:

                <Json2XmlInputValidator name="ValidatePost"
                    schema="CreeerZaak_LK01/xsd/ZgwZaak.xsd"
                    root="ZgwZaak"
                    outputFormat="JSON"
                    deepSearch="true"
                    throwException="true"
                />

                <HttpSender name="PostZgwZaakSender"
                    methodType="POST"
                    headersParams="Authorization,Accept-Crs,Content-Crs,Accept"
                    url="${zgw.baseurl}${zgw.endpoint.zaak}"
                    timeout="${creeerZaak.timeout}"
                    maxExecuteRetries="5"
                    contentType="application/json">
                    <Param name="Accept-Crs" value="EPSG:4326" />
                    <Param name="Accept" value="application/json" />
                    <Param name="Content-Crs" value="EPSG:4326" />
                    <Param name="Authorization" value="Bearer ${JwtToken}" />
                </HttpSender>

                <Forward name="success" path="JsonToXml" />
            </SenderPipe>

            <EchoPipe name="FailPostZgwZaakSender">
                <Forward name="success" path="EXCEPTION"/>
            </EchoPipe>

            <JsonPipe name="JsonToXml"
                storeResultInSessionKey="PostZgwZaakResult">
                <Forward name="success" path="UnwrapOpenZaakApiEnvelopeToSingle" />
            </JsonPipe>

I hoped that the success forward would only be followed for 2xx response codes. In any other case I expected a default behavior of taking the next pipe, which is the <EchoPipe> in this example.

mhdirkse commented 1 year ago

I have F!F version 7.9-20230214.195451.

mhdirkse commented 1 year ago

The following code does what I want:

            <SenderPipe name="PostZgwZaak">

                <Json2XmlInputValidator name="ValidatePost"
                    schema="CreeerZaak_LK01/xsd/ZgwZaak.xsd"
                    root="ZgwZaak"
                    outputFormat="JSON"
                    deepSearch="true"
                    throwException="true"
                />

                <HttpSender name="PostZgwZaakSender"
                    methodType="POST"
                    headersParams="Authorization,Accept-Crs,Content-Crs,Accept"
                    url="${zgw.baseurl}${zgw.endpoint.zaak}"
                    timeout="${creeerZaak.timeout}"
                    maxExecuteRetries="5"
                    contentType="application/json">
                    <Param name="Accept-Crs" value="EPSG:4326" />
                    <Param name="Accept" value="application/json" />
                    <Param name="Content-Crs" value="EPSG:4326" />
                    <Param name="Authorization" value="Bearer ${JwtToken}" />
                </HttpSender>

                <Forward name="success" path="JsonToXml" />
                <Forward name="exception" path="FailPostZgwZaakSender" />
            </SenderPipe>

            <EchoPipe name="FailPostZgwZaakSender">
                <Forward name="success" path="EXCEPTION"/>
            </EchoPipe>

            <JsonPipe name="JsonToXml"
                storeResultInSessionKey="PostZgwZaakResult">
                <Forward name="success" path="UnwrapOpenZaakApiEnvelopeToSingle" />
            </JsonPipe>

@nielsm5, I understand your remark that any 2xx HTTP code results in forward "success" while any other code results in forward "exception" provided that this forward is in the SenderPipe. The explanation of forward "exception" is very confusing to me. It says: "an exception was caught when processing the message". This suggests a Java exception. @nielsm5, you indicated that the "exception" forward is followed if any (very) unhappy situation is encountered, the definition of "unhappy" depending on the type of pipe. I would document this differently.

nielsm5 commented 1 year ago

Just to clarify, the name is meant to represent 'anomaly / irregularity and deviation', the opposite of success. You are assuming it has something to do with a Java Exception. While this forward will also be used in such a scenario, but it is not limited to just Java Exceptions.