From 4da4a0daa1954f0e15fed210dd94167e39e78bd5 Mon Sep 17 00:00:00 2001 From: Jonathan Leonhardt Date: Mon, 13 May 2024 18:00:49 -0300 Subject: [PATCH] fix(audition/client): fix body request --- mvnw | 1 + .../br/com/potio/http_auditor/ClientFilter.java | 15 +++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/mvnw b/mvnw index 8d937f4..8ffaa9e 100755 --- a/mvnw +++ b/mvnw @@ -32,6 +32,7 @@ # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files # ---------------------------------------------------------------------------- +JAVA_HOME="/opt/jdk/jdk-17.0.5+8" if [ -z "$MAVEN_SKIP_RC" ] ; then diff --git a/src/main/java/br/com/potio/http_auditor/ClientFilter.java b/src/main/java/br/com/potio/http_auditor/ClientFilter.java index ff8301b..173c0f6 100644 --- a/src/main/java/br/com/potio/http_auditor/ClientFilter.java +++ b/src/main/java/br/com/potio/http_auditor/ClientFilter.java @@ -25,6 +25,8 @@ import br.com.potio.core.dto.RequestDTO; import br.com.potio.core.dto.ResponseDTO; +import jakarta.json.bind.Jsonb; +import jakarta.json.bind.JsonbBuilder; import jakarta.transaction.Transactional; import jakarta.transaction.Transactional.TxType; import jakarta.ws.rs.client.ClientRequestContext; @@ -76,17 +78,10 @@ private RequestDTO createRequest( ClientRequestContext context ) throws IOExcept Object entity = null; var hasEntity = context.hasEntity() && !( ( entity = context.getEntity() ) instanceof Form ); - if ( hasEntity && entity instanceof String) { - body = (String) entity; + if ( hasEntity ) { + Jsonb jsonb = JsonbBuilder.create(); + body = jsonb.toJson(entity); bodyTypeName = entity.getClass().getName(); - } else if ( hasEntity && entity instanceof InputStream ) { - try ( InputStream inputStream = ( InputStream ) entity; ){ - byte[] bytes = inputStream.readAllBytes(); - body = new String( bytes, StandardCharsets.UTF_8 ); - bodyTypeName = entity.getClass().getName(); - } catch ( IOException e ) { - ClientFilter.logger.log( Level.SEVERE, "Erro converting request body", e); - } } String requestDate = headers.get( "date" ).get( 0 ); var dateParser = new SimpleDateFormat( DATE_PATTERN, Locale.US );