Refactor: Use RequestContext in SessionReader when instantiating responses

This commit is contained in:
Lars Simon Winzer
2026-03-31 20:32:11 +02:00
parent 665e006b89
commit 34d782e252
@@ -46,11 +46,13 @@ public class SessionReader implements Runnable {
while (!Thread.currentThread().isInterrupted()) {
RawPacket rawPacket = null;
RawRequest rawRequest = null;
RequestContext requestContext = null;
try {
// Step 1: Read from transport
rawPacket = transport.read();
session.updateLastInboundActivity();
logger.debug("Recieved: {}", rawPacket);
requestContext = new RequestContext(session.getId(), rawPacket.requestId());
// Step 2: Syntax validation and conversion into transport object
rawRequest = ProtocolParser.parse(rawPacket.payload());
@@ -58,9 +60,7 @@ public class SessionReader implements Runnable {
PrimitiveRequest primitiveRequest =
new PrimitiveRequest(
new RequestContext(session.getId(), rawPacket.requestId()),
rawRequest.command(),
rawRequest.parameters());
requestContext, rawRequest.command(), rawRequest.parameters());
logger.debug("Converted to {}", primitiveRequest);
// Step 3: Parse into Request and execute Request
@@ -76,8 +76,7 @@ public class SessionReader implements Runnable {
sendErrorResponse(
new ErrorResponse(
session.getId(),
rawPacket.requestId(),
requestContext,
"PARSING_ERROR",
"Error occured during parsing. Likely due to malformed payload."));
@@ -85,8 +84,7 @@ public class SessionReader implements Runnable {
logger.error("Recieved unknown command '{}' from client", rawRequest.command(), e);
sendErrorResponse(
new ErrorResponse(
session.getId(),
rawPacket.requestId(),
requestContext,
"UNKNOWN_COMMAND",
"This command is unknown to the server."));
@@ -97,8 +95,7 @@ public class SessionReader implements Runnable {
logger.error("Unexpected RuntimeException occured", e);
sendErrorResponse(
new ErrorResponse(
session.getId(),
rawPacket.requestId(),
requestContext,
"INTERNAL_ERROR",
"Unexpected internal server error occured."));
}