Skip to content

Commit

Permalink
fix(audition/client): fix body request
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanleonhardt committed May 13, 2024
1 parent bf56e82 commit 4da4a0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
1 change: 1 addition & 0 deletions mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 5 additions & 10 deletions src/main/java/br/com/potio/http_auditor/ClientFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 4da4a0d

Please sign in to comment.