mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 15:10:23 +00:00
Filter beacon responses
This commit is contained in:
parent
0527dbee39
commit
ceee5d56b1
2 changed files with 36 additions and 7 deletions
|
@ -124,10 +124,9 @@ public class BeaconRequestHandler<T> implements HttpHandler {
|
|||
try {
|
||||
var emptyResponseClass = beaconInterface.getResponseClass().getDeclaredFields().length == 0;
|
||||
if (!emptyResponseClass && response != null) {
|
||||
TrackEvent.trace("Sending response:\n" + object);
|
||||
var tree = JacksonMapper.getDefault().valueToTree(response);
|
||||
TrackEvent.trace("Sending raw response:\n" + tree.toPrettyString());
|
||||
var bytes = tree.toPrettyString().getBytes(StandardCharsets.UTF_8);
|
||||
TrackEvent.trace("Sending response:\n" + response);
|
||||
TrackEvent.trace("Sending raw response:\n" + JacksonMapper.getCensored().valueToTree(response).toPrettyString());
|
||||
var bytes = JacksonMapper.getDefault().valueToTree(response).toPrettyString().getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, bytes.length);
|
||||
try (OutputStream os = exchange.getResponseBody()) {
|
||||
os.write(bytes);
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package io.xpipe.core.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
|
@ -88,4 +90,32 @@ public class JacksonMapper {
|
|||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public static ObjectMapper getCensored() {
|
||||
if (!JacksonMapper.isInit()) {
|
||||
return BASE;
|
||||
}
|
||||
|
||||
var c = INSTANCE.copy();
|
||||
c.registerModule(new SimpleModule() {
|
||||
@Override
|
||||
public void setupModule(SetupContext context) {
|
||||
addSerializer(SecretValue.class, new JsonSerializer<>() {
|
||||
@Override
|
||||
public void serialize(SecretValue value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeString("<secret>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeWithType(SecretValue value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws
|
||||
IOException {
|
||||
gen.writeString("<secret>");
|
||||
}
|
||||
});
|
||||
super.setupModule(context);
|
||||
}
|
||||
});
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue