Skip to content

Commit

Permalink
Add logging and compacting on unexpected exception during filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Jun 5, 2019
1 parent fcbfa0b commit d20c68d
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

/**
*
* Thread-safe filter for JSON fields. Filters on property names,
* Thread-safe filter for JSON fields. Filters on property names.
* <br><br>
* Output is always compacted, even in case of invalid JSON,
* so this filter should not be used in conjunction with {@linkplain JsonCompactor}.
*
*/

@Slf4j
public class JacksonJsonFieldBodyFilter implements BodyFilter {

private final static StringReplaceJsonCompactor fallbackCompactor = new StringReplaceJsonCompactor();

private final String replacement;
private final Set<String> fields;
private final ObjectMapper objectMapper;
Expand Down Expand Up @@ -71,10 +79,9 @@ public String filter(final String body) {

return writer.toString();
} catch(Exception e) {
// ignore
log.trace("Unable to filter body, is it a JSON?. Keep as-is. `{}`", e.getMessage());
return fallbackCompactor.compact(body);
}
return body;
}

}

}

0 comments on commit d20c68d

Please sign in to comment.