@@ -74,7 +74,7 @@ public static String post(String url, String body, String bearerToken) throws Ex
7474
7575 public static String execute (Request request , HttpMethod method ) throws Exception {
7676 final String url = request .url ().toString ();
77- final String requestBody = extractRequestBody (request );
77+ final String requestBodyForLog = extractRequestBodyForLog (request );
7878 final String authHeader = extractAuthHeader (request );
7979 final Headers headers = request .headers ();
8080
@@ -85,17 +85,21 @@ public static String execute(Request request, HttpMethod method) throws Exceptio
8585 " Headers: %s" ,
8686 method , url ,
8787 authHeader ,
88- requestBody ,
88+ requestBodyForLog ,
8989 headers .toString ()
9090 ));
9191
9292 try (Response response = RAW_CLIENT .newCall (request ).execute ()) {
9393 final ResponseBody body = response .body ();
94- final String responseBody = extractResponseBody (body );
94+ // Read the FULL response body - don't truncate the actual data!
95+ final String fullResponseBody = (body != null ) ? body .string () : "" ;
9596 final int statusCode = response .code ();
9697 final String statusMessage = response .message ();
9798 final Headers responseHeaders = response .headers ();
9899
100+ // Only truncate for logging display
101+ final String responseBodyForLog = truncateForLog (fullResponseBody , 1000 );
102+
99103 LOGGER .info (() -> String .format (
100104 "[HTTP RESPONSE] %s %s%n" +
101105 " Status: %d %s%n" +
@@ -104,33 +108,40 @@ public static String execute(Request request, HttpMethod method) throws Exceptio
104108 method , url ,
105109 statusCode , statusMessage ,
106110 responseHeaders .toString (),
107- responseBody
111+ responseBodyForLog
108112 ));
109113
110114 if (!response .isSuccessful ()) {
111115 LOGGER .error (() -> String .format (
112116 "[HTTP ERROR] Request failed: %s %s - Status: %d %s - Response: %s" ,
113- method , url , statusCode , statusMessage , responseBody
117+ method , url , statusCode , statusMessage , responseBodyForLog
114118 ));
115- throw new HttpException (method , url , statusCode , statusMessage , responseBody );
119+ throw new HttpException (method , url , statusCode , statusMessage , fullResponseBody );
116120 }
117- return responseBody ;
121+ // Return the FULL response body, not truncated
122+ return fullResponseBody ;
123+ }
124+ }
125+
126+ private static String truncateForLog (String text , int maxLength ) {
127+ if (text == null || text .isEmpty ()) {
128+ return "[empty]" ;
129+ }
130+ if (text .length () > maxLength ) {
131+ return text .substring (0 , maxLength ) + "... [truncated, total length=" + text .length () + "]" ;
118132 }
133+ return text ;
119134 }
120135
121- private static String extractRequestBody (Request request ) {
136+ private static String extractRequestBodyForLog (Request request ) {
122137 if (request .body () == null ) {
123138 return "[empty]" ;
124139 }
125140 try {
126141 okio .Buffer buffer = new okio .Buffer ();
127142 request .body ().writeTo (buffer );
128143 String body = buffer .readUtf8 ();
129- // Truncate very long bodies for readability
130- if (body .length () > 500 ) {
131- return body .substring (0 , 500 ) + "... [truncated, length=" + body .length () + "]" ;
132- }
133- return body ;
144+ return truncateForLog (body , 500 );
134145 } catch (Exception e ) {
135146 return "[unable to read request body: " + e .getMessage () + "]" ;
136147 }
@@ -151,22 +162,6 @@ private static String extractAuthHeader(Request request) {
151162 }
152163 return "[none]" ;
153164 }
154-
155- private static String extractResponseBody (ResponseBody body ) {
156- if (body == null ) {
157- return "[empty]" ;
158- }
159- try {
160- String bodyString = body .string ();
161- // Truncate very long responses
162- if (bodyString .length () > 1000 ) {
163- return bodyString .substring (0 , 1000 ) + "... [truncated, length=" + bodyString .length () + "]" ;
164- }
165- return bodyString ;
166- } catch (Exception e ) {
167- return "[unable to read response body: " + e .getMessage () + "]" ;
168- }
169- }
170165
171166 private static Request buildRequest (HttpMethod method , String url , String body , String bearerToken ) {
172167 return buildRequest (method , url , body , bearerToken , null );
0 commit comments