Gets the XML representation of the given API response. An XML element named with name of the endpoint and with child elements as given by ApiResponse#toXML(Document, Element). @param endpointName the name of the API endpoint, must not be null. @param response the API res
(String endpointName, ApiResponse response)
| 831 | * @throws ApiException if an error occurred while converting the response. |
| 832 | */ |
| 833 | static String responseToXml(String endpointName, ApiResponse response) throws ApiException { |
| 834 | try { |
| 835 | DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); |
| 836 | DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); |
| 837 | |
| 838 | Document doc = docBuilder.newDocument(); |
| 839 | Element rootElement = doc.createElement(endpointName); |
| 840 | doc.appendChild(rootElement); |
| 841 | response.toXML(doc, rootElement); |
| 842 | |
| 843 | TransformerFactory transformerFactory = TransformerFactory.newInstance(); |
| 844 | Transformer transformer = transformerFactory.newTransformer(); |
| 845 | DOMSource source = new DOMSource(doc); |
| 846 | |
| 847 | StringWriter sw = new StringWriter(); |
| 848 | StreamResult result = new StreamResult(sw); |
| 849 | transformer.transform(source, result); |
| 850 | |
| 851 | return sw.toString(); |
| 852 | |
| 853 | } catch (Exception e) { |
| 854 | LOGGER.error("Failed to convert API response to XML: {}", e.getMessage(), e); |
| 855 | throw new ApiException(ApiException.Type.INTERNAL_ERROR, e); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | private static JSONObject getParams(HttpRequestHeader requestHeader) throws ApiException { |
| 860 | return getParams(requestHeader.getURI().getEscapedQuery()); |