Web service : save response as PDF file

In the <KatalonStudioInstallationDirectory>/Contents/Eclipse/configuration/resources/source directory, you can find the source codes of Katalon Studio. In the com.kms.katalon.core/com.kms.katalon.core-sources.ja of v9.0.0, I could find the source of com.kms.katalon.core.testobject.ResponseObject class. Here I quote the source of getResponseBodyContent() method, as follows:

    /**
     * Get the response body content as a String
     * 
     * @return the response body content as a String
     * @throws Exception if errors happened
     */
    // TODO: Detect the source to see if it is JSON, XML, HTML or plain text
    public String getResponseBodyContent() throws Exception {
        if (responseText != null) {
            if (contentType != null && contentType.startsWith("application/xml")) {
                Matcher SOAPEnvMatcher = SOAPPatternEnvelope.matcher(responseText);
                Matcher SOAPBodyMatcher = SOAPPatternBody.matcher(responseText);
                if (SOAPEnvMatcher.find() && SOAPBodyMatcher.find()) {
                    // SOAP xml
                    DocumentBuilder db = DocumentBuilderProvider.newBuilderInstance();
                    Document doc = db.parse(new InputSource(new StringReader(responseText)));
                    XPath xPath = XPathFactory.newInstance().newXPath();
                    NodeList nodes = (NodeList) xPath.evaluate("/*/*/*", doc, XPathConstants.NODESET);
                    if (nodes.getLength() > 0) {
                        // Body root node always at the last
                        Node lastNode = nodes.item(nodes.getLength() - 1);
                        return nodeToString(lastNode);
                    }
                    return "";
                } else { 
                    // REST xml
                    return responseText;
                }
            } else if (contentType != null && contentType.startsWith("application/json")) {
                return responseText;
            }
            // plain text/html
            else {
                return responseText;
            }
        }
        return "";
    }

You can easily see that this method is written with an assumption that the response body is a java.lang.String type such as JSON, XML, HTML and text/plain.

Does it support PDF? No, it doesn’t. A PDF file is not a string at all. As far as I read the source code, the ReponseObject class is not designed to process any binary files (such as PDF, MS-excel, zip, PNG, JPEG).

If a binary content is provided in the response body, how does the ResponseObject class behave? Does it throw any error saying “I don’t understand this type: application/pdf ? — No. It gives you no warning. It just gives you a strange result. This careless implementation made @Frederic_Canovas1 confused.