@@ -271,7 +271,7 @@ public byte[] getReceiptPngById(String id,int charsCount, int paperWidth)
271271 parameters .add ("width=" +charsCount );
272272 if (paperWidth >= MIN_WIDTH_PNG_RECEIPT && MAX_WIDTH_PNG_RECEIPT <= 80 )
273273 parameters .add ("paper_width=" + paperWidth );
274- return getForBytes (URI .create (apiPrefix + RECEIPTS_PATH + "/" + id + "/png" + parameters ));
274+ return getForBytes (URI .create (apiPrefix + RECEIPTS_PATH + "/" + id + "/png" + parameters ));
275275 }
276276
277277 public byte [] getReceiptPdfById (String id )
@@ -299,13 +299,13 @@ private <T> T postForObject(Class<T> returnType, Object postData, Function<HttpR
299299 try
300300 {
301301 HttpRequest .BodyPublisher publisher = postData != null
302- ? HttpRequest .BodyPublishers .ofString (mapper .writeValueAsString (postData ))
303- : HttpRequest .BodyPublishers .noBody ();
302+ ? HttpRequest .BodyPublishers .ofString (mapper .writeValueAsString (postData ))
303+ : HttpRequest .BodyPublishers .noBody ();
304304 HttpRequest .Builder request = HttpRequest .newBuilder ()
305- .POST (publisher )
306- .uri (uri )
307- .header ("Content-Type" , "application/json" )
308- .header ("Authorization" , "Bearer " + token );
305+ .POST (publisher )
306+ .uri (uri )
307+ .header ("Content-Type" , "application/json" )
308+ .header ("Authorization" , "Bearer " + token );
309309 if (httpRequestCustomBuilder != null )
310310 {
311311 request = httpRequestCustomBuilder .apply (request );
@@ -320,17 +320,17 @@ else if (response.statusCode() == 422)
320320 // Validation error
321321 HTTPValidationError error = mapper .readValue (response .body (), HTTPValidationError .class );
322322 throw CheckboxApiCallException .builder ()
323- .httpCode (response .statusCode ())
324- .validationError (error )
325- .build ();
323+ .httpCode (response .statusCode ())
324+ .validationError (error )
325+ .build ();
326326 }
327327 else
328328 {
329329 ErrorDetails error = mapper .readValue (response .body (), ErrorDetails .class );
330330 throw CheckboxApiCallException .builder ()
331- .httpCode (response .statusCode ())
332- .error (error )
333- .build ();
331+ .httpCode (response .statusCode ())
332+ .error (error )
333+ .build ();
334334 }
335335 }
336336 catch (InterruptedException |IOException e )
@@ -348,7 +348,7 @@ private <T> T getForObject(Class<T> returnType, URI uri)
348348 {
349349 return mapper .readValue (response .body (), returnType );
350350 }
351- catch (JsonProcessingException e )
351+ catch (Exception e )
352352 {
353353 e .printStackTrace ();
354354 log .error ("API call error" , e );
@@ -365,7 +365,7 @@ private <T> T getForObject(Class<T> returnType, URI uri, Function<HttpRequest.Bu
365365 {
366366 return mapper .readValue (response .body (), returnType );
367367 }
368- catch (JsonProcessingException e )
368+ catch (Exception e )
369369 {
370370 e .printStackTrace ();
371371 log .error ("API call error" , e );
@@ -382,7 +382,7 @@ private <T> T getForObject(TypeReference<T> returnType, URI uri)
382382 {
383383 return mapper .readValue (response .body (), returnType );
384384 }
385- catch (JsonProcessingException e )
385+ catch (Exception e )
386386 {
387387 log .error ("API call error" , e );
388388 throw CheckboxApiCallException .builder ().build ();
@@ -392,52 +392,19 @@ private <T> T getForObject(TypeReference<T> returnType, URI uri)
392392
393393 private String getForString (URI uri )
394394 {
395- return getForObjectImpl (HttpResponse :: body , uri );
395+ return getForObjectImpl (httpResponse -> new String ( httpResponse . body (), StandardCharsets . UTF_8 ) , uri );
396396 }
397397 private byte [] getForBytes (URI uri )
398398 {
399- return getForBytesImpl (httpResponse -> httpResponse .body (), uri ,null );
399+ return getForObjectImpl (httpResponse -> httpResponse .body (), uri ,null );
400400 }
401401
402- private <T > T getForObjectImpl (Function <HttpResponse <String >, T > responseFunction , URI uri )
402+ private <T > T getForObjectImpl (Function <HttpResponse <byte [] >, T > responseFunction , URI uri )
403403 {
404404 return getForObjectImpl (responseFunction , uri , null );
405405 }
406406
407- private <T > T getForObjectImpl (Function <HttpResponse <String >, T > responseFunction , URI uri , Function <HttpRequest .Builder ,HttpRequest .Builder > httpRequestCustomBuilder )
408- {
409- try
410- {
411- HttpRequest .Builder request = HttpRequest .newBuilder ()
412- .GET ()
413- .uri (uri )
414- .header ("Authorization" , "Bearer " + token );
415- if (httpRequestCustomBuilder != null )
416- {
417- request = httpRequestCustomBuilder .apply (request );
418- }
419- HttpResponse <String > response = httpClient .send (request .build (), HttpResponse .BodyHandlers .ofString ());
420- if (response .statusCode () == HttpURLConnection .HTTP_OK )
421- {
422- return responseFunction .apply (response );
423- }
424- else
425- {
426- ErrorDetails error = mapper .readValue (response .body (), ErrorDetails .class );
427- throw CheckboxApiCallException .builder ()
428- .httpCode (response .statusCode ())
429- .error (error )
430- .build ();
431- }
432- }
433- catch (InterruptedException |IOException e )
434- {
435- log .error ("API call error" , e );
436- throw CheckboxApiCallException .builder ().build ();
437- }
438- }
439-
440- private <T > T getForBytesImpl (Function <HttpResponse <byte []>, T > responseFunction , URI uri , Function <HttpRequest .Builder ,HttpRequest .Builder > httpRequestCustomBuilder )
407+ private <T > T getForObjectImpl (Function <HttpResponse <byte []>, T > responseFunction , URI uri , Function <HttpRequest .Builder ,HttpRequest .Builder > httpRequestCustomBuilder )
441408 {
442409 try
443410 {
0 commit comments