-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolving the issue of no data reporting in the BOE environment due t…
…o the inability to find message serialization and deserialization classes
- Loading branch information
1 parent
7e0de6d
commit 62b9920
Showing
5 changed files
with
82 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/MessageDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.security.smith.client; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.netty.handler.codec.ReplayingDecoder; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.buffer.ByteBuf; | ||
import java.util.List; | ||
import java.io.IOException; | ||
|
||
public class MessageDecoder extends ReplayingDecoder<Void> { | ||
@Override | ||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws IOException { | ||
long payloadSize = in.readUnsignedInt(); | ||
|
||
if (payloadSize > Message.MAX_PAYLOAD_SIZE) | ||
return; | ||
|
||
byte[] buffer = new byte[(int) payloadSize]; | ||
in.readBytes(buffer); | ||
|
||
Message message = new ObjectMapper().readValue(buffer, Message.class); | ||
|
||
if (message != null) | ||
out.add(message); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/MessageDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.security.smith.client; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.io.IOException; | ||
|
||
public class MessageDeserializer extends StdDeserializer<Message> { | ||
protected MessageDeserializer() { | ||
super(Message.class); | ||
} | ||
|
||
protected MessageDeserializer(Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public Message deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
JsonNode node = p.getCodec().readTree(p); | ||
|
||
Message message = new Message(); | ||
|
||
message.setOperate(node.get("message_type").asInt()); | ||
message.setData(node.get("data")); | ||
|
||
return message; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
rasp/jvm/JVMProbe/src/main/java/com/security/smith/client/MessageEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.security.smith.client; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.netty.handler.codec.MessageToByteEncoder; | ||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import java.nio.ByteBuffer; | ||
|
||
public class MessageEncoder extends MessageToByteEncoder<Object> { | ||
@Override | ||
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws JsonProcessingException { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
byte[] payload = objectMapper.writeValueAsBytes(msg); | ||
int payloadSize = payload.length; | ||
|
||
ByteBuffer buffer = ByteBuffer.allocate(payloadSize + Message.PROTOCOL_HEADER_SIZE); | ||
|
||
buffer.putInt(payloadSize); | ||
buffer.put(payload); | ||
|
||
buffer.flip(); | ||
|
||
out.writeBytes(buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters