public with sharing class PdfProxyPageController { public String result { get; set; } public void init() { // Initialize the page result = 'PDF Proxy Ready'; } @RemoteAction public static Map makeHttpCall(String endpoint, String dataJson) { try { System.debug('=== HTTP PROXY CALL ==='); System.debug('Endpoint: ' + endpoint); System.debug('Data JSON: ' + dataJson); // Parse the data Map data = new Map(); if (String.isNotBlank(dataJson)) { try { data = (Map) JSON.deserializeUntyped(dataJson); } catch (Exception e) { System.debug('Error parsing JSON: ' + e.getMessage()); } } // Make the HTTP callout Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(endpoint); request.setMethod('POST'); request.setHeader('Content-Type', 'application/json'); request.setBody(JSON.serialize(data)); request.setTimeout(120000); // 2 minutes HttpResponse response = http.send(request); System.debug('Response Status: ' + response.getStatusCode()); System.debug('Response Body: ' + response.getBody()); Map result = new Map(); if (response.getStatusCode() == 200) { try { Map responseData = (Map) JSON.deserializeUntyped(response.getBody()); result.put('success', true); result.put('data', responseData); } catch (Exception e) { result.put('success', true); result.put('data', response.getBody()); } } else { result.put('success', false); result.put('error', 'HTTP ' + response.getStatusCode() + ': ' + response.getBody()); } return result; } catch (Exception e) { System.debug('Error in HTTP proxy: ' + e.getMessage()); System.debug('Stack trace: ' + e.getStackTraceString()); Map errorResult = new Map(); errorResult.put('success', false); errorResult.put('error', 'Exception: ' + e.getMessage()); return errorResult; } } }