2525import java .io .IOException ;
2626import java .io .OutputStream ;
2727import java .net .URI ;
28- // import java.nio.charset.StandardCharsets; // Commented out as not needed when debug logging is disabled
2928import java .util .List ;
3029import java .util .Map ;
3130
@@ -137,11 +136,9 @@ public ClientHttpResponse execute() throws IOException {
137136 // This is crucial for @JsonTypeInfo annotated classes like Execution
138137 ByteArrayEntity requestEntity = new ByteArrayEntity (bytes );
139138
140- // ВАЖНО: НЕ устанавливаем Content-Type на entity!
141- // Это предотвращает дублирование заголовков и конфликты с GoodData API
142- // Content-Type будет управляться только через HTTP заголовки в addHeaders()
139+
143140 if (logger .isDebugEnabled ()) {
144- // Проверяем какой Content-Type мы получим от заголовков
141+ // Check if Content-Type is already set in headers
145142 boolean hasContentType = false ;
146143 for (org .apache .http .Header header : httpRequest .getAllHeaders ()) {
147144 if ("Content-Type" .equalsIgnoreCase (header .getName ())) {
@@ -159,38 +156,6 @@ public ClientHttpResponse execute() throws IOException {
159156
160157 entityRequest .setEntity (requestEntity );
161158
162- // DEBUG: Enhanced logging for request debugging including @JsonTypeInfo issues
163- // if (bytes.length > 0 && logger.isDebugEnabled()) {
164- // logger.debug("Request Body Length: {} bytes", bytes.length);
165- //
166- // // Get final Content-Type from entity for logging
167- // org.apache.http.Header finalContentType = entityRequest.getEntity().getContentType();
168- // String contentType = finalContentType != null ? finalContentType.getValue() : "none";
169- // logger.debug("Final entity Content-Type: {}", contentType);
170-
171- // // Only log text-based requests to avoid binary data issues
172- // if (contentType.contains("application/json") || contentType.contains("text/")) {
173- // try {
174- // // Use charset from Content-Type if available, otherwise UTF-8
175- // java.nio.charset.Charset charset = StandardCharsets.UTF_8;
176- // if (contentType.contains("charset=")) {
177- // String charsetName = contentType.substring(contentType.indexOf("charset=") + 8);
178- // charsetName = charsetName.split(";")[0].trim();
179- // charset = java.nio.charset.Charset.forName(charsetName);
180- // }
181- //
182- // String requestBody = new String(bytes, charset);
183- // // Log @JsonTypeInfo requests that might cause "malformed syntax" errors
184- // if (requestBody.contains("\"execution\"") || requestBody.contains("\"report_req\"")) {
185- // logger.debug("@JsonTypeInfo request ({}): {}", contentType, requestBody);
186- // }
187- // } catch (Exception e) {
188- // logger.debug("Could not decode request body for logging: {}", e.getMessage());
189- // }
190- // } else if (contentType.contains("multipart/form-data")) {
191- // logger.debug("Multipart form data request with Content-Type: {}", contentType);
192- // }
193- // }
194159 }
195160 }
196161
@@ -232,18 +197,18 @@ public ClientHttpResponse execute() throws IOException {
232197 * Follows HttpClient4ClientHttpRequest.executeInternal implementation pattern.
233198 */
234199 private void addHeaders (HttpRequest httpRequest ) {
235- // КРИТИЧНО для GoodData API: устанавливаем заголовки в фиксированном порядке
236- // для стабильной чексуммы. Порядок : Accept, X-GDC-Version, Content-Type, остальные
200+ // CRITICAL for GoodData API: set headers in fixed order
201+ // for stable checksum. Order : Accept, X-GDC-Version, Content-Type, others
237202
238- // Сначала очищаем потенциально проблемные заголовки
203+ // First clear potentially problematic headers
239204 if (httpRequest instanceof HttpUriRequest ) {
240205 HttpUriRequest uriRequest = (HttpUriRequest ) httpRequest ;
241206 uriRequest .removeHeaders ("Accept" );
242207 uriRequest .removeHeaders ("X-GDC-Version" );
243208 uriRequest .removeHeaders ("Content-Type" );
244209 }
245210
246- // 1. Accept заголовок (первый для стабильности чексуммы )
211+ // 1. Accept header (first for checksum stability )
247212 if (headers .containsKey ("Accept" )) {
248213 String acceptValue = String .join (", " , headers .get ("Accept" ));
249214 httpRequest .setHeader ("Accept" , acceptValue );
@@ -252,7 +217,7 @@ private void addHeaders(HttpRequest httpRequest) {
252217 // }
253218 }
254219
255- // 2. X-GDC-Version заголовок (второй для стабильности )
220+ // 2. X-GDC-Version header (second for stability )
256221 if (headers .containsKey ("X-GDC-Version" )) {
257222 String versionValue = String .join (", " , headers .get ("X-GDC-Version" ));
258223 httpRequest .setHeader ("X-GDC-Version" , versionValue );
@@ -261,12 +226,12 @@ private void addHeaders(HttpRequest httpRequest) {
261226 // }
262227 }
263228
264- // 3. Content-Type - управляется только через заголовки (без entity Content-Type)
229+ // 3. Content-Type - managed only through headers (without entity Content-Type)
265230 String finalContentType = null ;
266231 if (headers .containsKey ("Content-Type" )) {
267- // Используем Spring заголовок Content-Type
232+ // Use Spring Content-Type header
268233 String contentTypeValue = String .join (", " , headers .get ("Content-Type" ));
269- // Добавляем charset=UTF-8 для JSON если его нет
234+ // Add charset=UTF-8 for JSON if not present
270235 if (contentTypeValue .contains ("application/json" ) && !contentTypeValue .contains ("charset=" )) {
271236 finalContentType = contentTypeValue + "; charset=UTF-8" ;
272237 // if (logger.isDebugEnabled()) {
@@ -279,7 +244,7 @@ private void addHeaders(HttpRequest httpRequest) {
279244 // }
280245 }
281246 } else if (httpRequest instanceof HttpEntityEnclosingRequest ) {
282- // Устанавливаем дефолтный Content-Type для JSON запросов с телом
247+ // Set default Content-Type for JSON requests with body
283248 finalContentType = "application/json; charset=UTF-8" ;
284249 // if (logger.isDebugEnabled()) {
285250 // logger.debug("Default Content-Type for JSON requests: {}", finalContentType);
@@ -293,7 +258,7 @@ private void addHeaders(HttpRequest httpRequest) {
293258 // }
294259 }
295260
296- // 4. Все остальные заголовки (в алфавитном порядке для стабильности )
261+ // 4. All other headers (in alphabetical order for stability )
297262 headers .entrySet ().stream ()
298263 .filter (entry -> {
299264 String headerName = entry .getKey ();
@@ -303,7 +268,7 @@ private void addHeaders(HttpRequest httpRequest) {
303268 !"Accept" .equalsIgnoreCase (headerName ) &&
304269 !"X-GDC-Version" .equalsIgnoreCase (headerName );
305270 })
306- .sorted (Map .Entry .comparingByKey ()) // Алфавитный порядок для стабильности
271+ .sorted (Map .Entry .comparingByKey ()) // Alphabetical order for stability
307272 .forEach (entry -> {
308273 String headerName = entry .getKey ();
309274 List <String > headerValues = entry .getValue ();
0 commit comments