Refactor response classes to use RequestContext instead of SessionId + request id #220
+3
-5
@@ -1,7 +1,7 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionId;
|
|
||||||
|
|
||||||
/** Response representing an error outcome for a client's request. */
|
/** Response representing an error outcome for a client's request. */
|
||||||
public class ErrorResponse extends Response {
|
public class ErrorResponse extends Response {
|
||||||
@@ -13,11 +13,9 @@ public class ErrorResponse extends Response {
|
|||||||
* @param errorCode a short error code identifying the failure
|
* @param errorCode a short error code identifying the failure
|
||||||
* @param errorMessage a human readable error message
|
* @param errorMessage a human readable error message
|
||||||
*/
|
*/
|
||||||
public ErrorResponse(
|
public ErrorResponse(RequestContext context, String errorCode, String errorMessage) {
|
||||||
SessionId sessionId, int requestId, String errorCode, String errorMessage) {
|
|
||||||
super(
|
super(
|
||||||
sessionId,
|
context,
|
||||||
requestId,
|
|
||||||
ResponseBody.builder().param("CODE", errorCode).param("MSG", errorMessage).build());
|
ResponseBody.builder().param("CODE", errorCode).param("MSG", errorMessage).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple success response with an empty body.
|
* A simple success response with an empty body.
|
||||||
@@ -15,7 +15,7 @@ public class OkResponse extends SuccessResponse {
|
|||||||
* @param sessionId the target session id
|
* @param sessionId the target session id
|
||||||
* @param requestId the originating request id
|
* @param requestId the originating request id
|
||||||
*/
|
*/
|
||||||
public OkResponse(SessionId sessionId, int requestId) {
|
public OkResponse(RequestContext context) {
|
||||||
super(sessionId, requestId, ResponseBody.builder().build());
|
super(context, ResponseBody.builder().build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -1,5 +1,6 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionId;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionId;
|
||||||
|
|
||||||
@@ -16,9 +17,9 @@ public abstract class Response {
|
|||||||
* @param requestId the request identifier this response corresponds to
|
* @param requestId the request identifier this response corresponds to
|
||||||
* @param body the structured response body
|
* @param body the structured response body
|
||||||
*/
|
*/
|
||||||
protected Response(SessionId sessionId, int requestId, ResponseBody body) {
|
protected Response(RequestContext context, ResponseBody body) {
|
||||||
this.sessionId = sessionId;
|
this.sessionId = context.sessionId();
|
||||||
this.requestId = requestId;
|
this.requestId = context.requestId();
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract {@link Response} specialization indicating a successful outcome.
|
* Abstract {@link Response} specialization indicating a successful outcome.
|
||||||
@@ -17,8 +17,8 @@ public abstract class SuccessResponse extends Response {
|
|||||||
* @param requestId the originating request id
|
* @param requestId the originating request id
|
||||||
* @param body the response body
|
* @param body the response body
|
||||||
*/
|
*/
|
||||||
protected SuccessResponse(SessionId sessionId, int requestId, ResponseBody body) {
|
protected SuccessResponse(RequestContext context, ResponseBody body) {
|
||||||
super(sessionId, requestId, body);
|
super(context, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user