Refactor response classes to use RequestContext instead of SessionId + request id #220

Merged
lars.winzer merged 5 commits from feat/34-make-response-use-requestcontext into main 2026-03-31 20:50:08 +02:00
Showing only changes of commit 34d782e252 - Show all commits
@@ -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."));
}