Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message Collector - body length limit #190

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class MessageCollector extends EventNotifierSupport {
private final String flowId;
private final String flowVersion;

private final String MSG_COLLECTOR_LIMIT_BODY_LENGTH = "MSG_COLLECTOR_LIMIT_BODY_LENGTH";
private final int MSG_COLLECTOR_DEFAULT_LIMIT_BODY_LENGTH = 250000;


public MessageCollector(String collectorId, String flowId, String flowVersion, ArrayList<String> events, ArrayList<Filter> filters, ArrayList<org.assimbly.dil.event.domain.Store> stores) {
this.collectorId = collectorId;
Expand Down Expand Up @@ -119,11 +122,12 @@ public String getBody(Message message) {
try {

byte[] body = message.getBody(byte[].class);
int limitBodyLength = getLimitBodyLength();

if (body == null || body.length == 0) {
return "<empty>";
}else if (body.length > 250000) {
return new String(Arrays.copyOfRange(body, 0, 250000), StandardCharsets.UTF_8);
}else if (body.length > limitBodyLength) {
return new String(Arrays.copyOfRange(body, 0, limitBodyLength), StandardCharsets.UTF_8);
}else{
return new String (body, StandardCharsets.UTF_8);
}
Expand All @@ -139,4 +143,13 @@ public String getBody(Message message) {

}

private int getLimitBodyLength() {
try {
String bodyLength = System.getenv(MSG_COLLECTOR_LIMIT_BODY_LENGTH);
return Integer.parseInt(bodyLength);
} catch (Exception e) {
return MSG_COLLECTOR_DEFAULT_LIMIT_BODY_LENGTH;
}
}

}