Skip to content

Commit

Permalink
[PAGOPA-2353] fix: trying to catch macro-exception on bugged logging
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-deri committed Nov 13, 2024
1 parent 36c7715 commit 703b591
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import java.io.IOException;
import java.io.StringReader;
Expand Down Expand Up @@ -144,21 +142,19 @@ public void receiptOk(@RequestBody ReceiptRequest request) throws IOException {
}

private String getReceiptRequestInfoToLog(String xml) {
String args = "n/a";
String args = "";
try {
if (StringUtils.isNotEmpty(xml)) {
// fix for sonar issue XML external entity in user-controlled data
saxParserFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
saxParserFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
saxParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

saxParserFactory.newSAXParser().parse(new InputSource(new StringReader(xml)), receiptRequestHandler);

PaSendRTV2Request result = receiptRequestHandler.getPaSendRTV2Request();
args = "noticeNumber=" + result.getNoticeNumber() + ", fiscalCode=" + result.getFiscalCode() + ", creditorReferenceId=" + result.getCreditorReferenceId();
}
} catch (SAXException | IOException | ParserConfigurationException e) {
return args;
} catch (Exception e) {
args = "n/a";
}
return args;
}
Expand Down

0 comments on commit 703b591

Please sign in to comment.