10 12 25
Переименовал классы в один стиль
This commit is contained in:
parent
7072882b0b
commit
7f91c60d26
@ -5,10 +5,10 @@ import server.logic.ws_protocol.JSON.entyties.Auth.Net_AuthChallenge_Request;
|
|||||||
import server.logic.ws_protocol.JSON.entyties.Auth.Net_CreateAuthSession_Request;
|
import server.logic.ws_protocol.JSON.entyties.Auth.Net_CreateAuthSession_Request;
|
||||||
import server.logic.ws_protocol.JSON.entyties.Auth.Net_RefreshSession_Request;
|
import server.logic.ws_protocol.JSON.entyties.Auth.Net_RefreshSession_Request;
|
||||||
import server.logic.ws_protocol.JSON.handlers.*;
|
import server.logic.ws_protocol.JSON.handlers.*;
|
||||||
import server.logic.ws_protocol.JSON.entyties.tempToTest.NetAddUserRequest;
|
import server.logic.ws_protocol.JSON.entyties.tempToTest.Net_AddUser_Request;
|
||||||
import server.logic.ws_protocol.JSON.handlers.auth.Net_CreateAuthSession__Handler;
|
import server.logic.ws_protocol.JSON.handlers.auth.Net_CreateAuthSession__Handler;
|
||||||
import server.logic.ws_protocol.JSON.handlers.auth.Net_RefreshSession_Handler;
|
import server.logic.ws_protocol.JSON.handlers.auth.Net_RefreshSession_Handler;
|
||||||
import server.logic.ws_protocol.JSON.handlers.tempToTest.NetAddUserHandler;
|
import server.logic.ws_protocol.JSON.handlers.tempToTest.Net_AddUser_Handler;
|
||||||
import server.logic.ws_protocol.JSON.handlers.auth.Net_AuthChallenge_Handler;
|
import server.logic.ws_protocol.JSON.handlers.auth.Net_AuthChallenge_Handler;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -26,15 +26,15 @@ public final class JsonHandlerRegistry {
|
|||||||
|
|
||||||
private static final Map<String, JsonMessageHandler> HANDLERS = Map.of(
|
private static final Map<String, JsonMessageHandler> HANDLERS = Map.of(
|
||||||
"RefreshSession", new Net_RefreshSession_Handler(),
|
"RefreshSession", new Net_RefreshSession_Handler(),
|
||||||
"AddUser", new NetAddUserHandler(),
|
"AddUser", new Net_AddUser_Handler(),
|
||||||
"AuthChallenge", new Net_AuthChallenge_Handler(),
|
"AuthChallenge", new Net_AuthChallenge_Handler(),
|
||||||
"CreateAuthSession", new Net_CreateAuthSession__Handler()
|
"CreateAuthSession", new Net_CreateAuthSession__Handler()
|
||||||
// сюда потом добавишь другие операции
|
// сюда потом добавишь другие операции
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final Map<String, Class<? extends NetRequest>> REQUEST_TYPES = Map.of(
|
private static final Map<String, Class<? extends Net_Request>> REQUEST_TYPES = Map.of(
|
||||||
"RefreshSession", Net_RefreshSession_Request.class,
|
"RefreshSession", Net_RefreshSession_Request.class,
|
||||||
"AddUser", NetAddUserRequest.class,
|
"AddUser", Net_AddUser_Request.class,
|
||||||
"AuthChallenge", Net_AuthChallenge_Request.class,
|
"AuthChallenge", Net_AuthChallenge_Request.class,
|
||||||
"CreateAuthSession", Net_CreateAuthSession_Request.class
|
"CreateAuthSession", Net_CreateAuthSession_Request.class
|
||||||
);
|
);
|
||||||
@ -47,7 +47,7 @@ public final class JsonHandlerRegistry {
|
|||||||
return HANDLERS;
|
return HANDLERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Class<? extends NetRequest>> getRequestTypes() {
|
public static Map<String, Class<? extends Net_Request>> getRequestTypes() {
|
||||||
return REQUEST_TYPES;
|
return REQUEST_TYPES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetExceptionResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Exception_Response;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
||||||
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
||||||
import server.logic.ws_protocol.WireCodes;
|
import server.logic.ws_protocol.WireCodes;
|
||||||
@ -40,7 +40,7 @@ public final class JsonInboundProcessor {
|
|||||||
private static final Map<String, JsonMessageHandler> JSON_HANDLERS =
|
private static final Map<String, JsonMessageHandler> JSON_HANDLERS =
|
||||||
JsonHandlerRegistry.getHandlers();
|
JsonHandlerRegistry.getHandlers();
|
||||||
|
|
||||||
private static final Map<String, Class<? extends NetRequest>> JSON_REQUEST_TYPES =
|
private static final Map<String, Class<? extends Net_Request>> JSON_REQUEST_TYPES =
|
||||||
JsonHandlerRegistry.getRequestTypes();
|
JsonHandlerRegistry.getRequestTypes();
|
||||||
|
|
||||||
private JsonInboundProcessor() {
|
private JsonInboundProcessor() {
|
||||||
@ -53,7 +53,7 @@ public final class JsonInboundProcessor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (json == null || json.isBlank()) {
|
if (json == null || json.isBlank()) {
|
||||||
NetExceptionResponse err = NetExceptionResponseFactory.error(
|
Net_Exception_Response err = NetExceptionResponseFactory.error(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
WireCodes.Status.BAD_REQUEST,
|
WireCodes.Status.BAD_REQUEST,
|
||||||
@ -71,7 +71,7 @@ public final class JsonInboundProcessor {
|
|||||||
requestId = getTextOrNull(root, "requestId");
|
requestId = getTextOrNull(root, "requestId");
|
||||||
|
|
||||||
if (op == null || op.isEmpty()) {
|
if (op == null || op.isEmpty()) {
|
||||||
NetExceptionResponse err = NetExceptionResponseFactory.error(
|
Net_Exception_Response err = NetExceptionResponseFactory.error(
|
||||||
null,
|
null,
|
||||||
requestId,
|
requestId,
|
||||||
WireCodes.Status.BAD_REQUEST,
|
WireCodes.Status.BAD_REQUEST,
|
||||||
@ -82,10 +82,10 @@ public final class JsonInboundProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonMessageHandler handler = JSON_HANDLERS.get(op);
|
JsonMessageHandler handler = JSON_HANDLERS.get(op);
|
||||||
Class<? extends NetRequest> reqClass = JSON_REQUEST_TYPES.get(op);
|
Class<? extends Net_Request> reqClass = JSON_REQUEST_TYPES.get(op);
|
||||||
|
|
||||||
if (handler == null || reqClass == null) {
|
if (handler == null || reqClass == null) {
|
||||||
NetExceptionResponse err = NetExceptionResponseFactory.error(
|
Net_Exception_Response err = NetExceptionResponseFactory.error(
|
||||||
op,
|
op,
|
||||||
requestId,
|
requestId,
|
||||||
WireCodes.Status.BAD_REQUEST,
|
WireCodes.Status.BAD_REQUEST,
|
||||||
@ -98,7 +98,7 @@ public final class JsonInboundProcessor {
|
|||||||
// 3. Берём payload
|
// 3. Берём payload
|
||||||
JsonNode payloadNode = root.get("payload");
|
JsonNode payloadNode = root.get("payload");
|
||||||
if (payloadNode == null || payloadNode.isNull()) {
|
if (payloadNode == null || payloadNode.isNull()) {
|
||||||
NetExceptionResponse err = NetExceptionResponseFactory.error(
|
Net_Exception_Response err = NetExceptionResponseFactory.error(
|
||||||
op,
|
op,
|
||||||
requestId,
|
requestId,
|
||||||
WireCodes.Status.BAD_REQUEST,
|
WireCodes.Status.BAD_REQUEST,
|
||||||
@ -108,7 +108,7 @@ public final class JsonInboundProcessor {
|
|||||||
return writeResponse(err);
|
return writeResponse(err);
|
||||||
}
|
}
|
||||||
if (!payloadNode.isObject()) {
|
if (!payloadNode.isObject()) {
|
||||||
NetExceptionResponse err = NetExceptionResponseFactory.error(
|
Net_Exception_Response err = NetExceptionResponseFactory.error(
|
||||||
op,
|
op,
|
||||||
requestId,
|
requestId,
|
||||||
WireCodes.Status.BAD_REQUEST,
|
WireCodes.Status.BAD_REQUEST,
|
||||||
@ -134,16 +134,16 @@ public final class JsonInboundProcessor {
|
|||||||
merged.setAll((ObjectNode) payloadNode);
|
merged.setAll((ObjectNode) payloadNode);
|
||||||
|
|
||||||
// 4. Маппим в конкретный класс NetRequest
|
// 4. Маппим в конкретный класс NetRequest
|
||||||
NetRequest request = JSON_MAPPER.treeToValue(merged, reqClass);
|
Net_Request request = JSON_MAPPER.treeToValue(merged, reqClass);
|
||||||
|
|
||||||
NetResponse response;
|
Net_Response response;
|
||||||
|
|
||||||
// 5. Вызываем хэндлер
|
// 5. Вызываем хэндлер
|
||||||
try {
|
try {
|
||||||
response = handler.handle(request, ctx);
|
response = handler.handle(request, ctx);
|
||||||
} catch (Exception handlerError) {
|
} catch (Exception handlerError) {
|
||||||
log.error("💥 Ошибка внутри хэндлера '{}'", op, handlerError);
|
log.error("💥 Ошибка внутри хэндлера '{}'", op, handlerError);
|
||||||
NetExceptionResponse err = NetExceptionResponseFactory.error(
|
Net_Exception_Response err = NetExceptionResponseFactory.error(
|
||||||
op,
|
op,
|
||||||
requestId,
|
requestId,
|
||||||
WireCodes.Status.INTERNAL_ERROR,
|
WireCodes.Status.INTERNAL_ERROR,
|
||||||
@ -162,7 +162,7 @@ public final class JsonInboundProcessor {
|
|||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Ошибка при обработке JSON-сообщения", e);
|
log.error("Ошибка при обработке JSON-сообщения", e);
|
||||||
NetExceptionResponse err = NetExceptionResponseFactory.error(
|
Net_Exception_Response err = NetExceptionResponseFactory.error(
|
||||||
op != null ? op : "Unknown",
|
op != null ? op : "Unknown",
|
||||||
requestId,
|
requestId,
|
||||||
WireCodes.Status.INTERNAL_ERROR,
|
WireCodes.Status.INTERNAL_ERROR,
|
||||||
@ -189,7 +189,7 @@ public final class JsonInboundProcessor {
|
|||||||
* "payload": { ... }
|
* "payload": { ... }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
private static String writeResponse(NetResponse response) {
|
private static String writeResponse(Net_Response response) {
|
||||||
try {
|
try {
|
||||||
// Конвертируем полный объект ответа в ObjectNode
|
// Конвертируем полный объект ответа в ObjectNode
|
||||||
ObjectNode full = JSON_MAPPER.convertValue(response, ObjectNode.class);
|
ObjectNode full = JSON_MAPPER.convertValue(response, ObjectNode.class);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package server.logic.ws_protocol.JSON.entyties.Auth;
|
package server.logic.ws_protocol.JSON.entyties.Auth;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Шаг 1 авторизации: запрос выдачи временного пароля сессии (sessionPwd).
|
* Шаг 1 авторизации: запрос выдачи временного пароля сессии (sessionPwd).
|
||||||
@ -27,7 +27,7 @@ import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public class Net_AuthChallenge_Request extends NetRequest {
|
public class Net_AuthChallenge_Request extends Net_Request {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Логин пользователя, для которого запускается авторизация.
|
* Логин пользователя, для которого запускается авторизация.
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package server.logic.ws_protocol.JSON.entyties.Auth;
|
package server.logic.ws_protocol.JSON.entyties.Auth;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ответ на AuthChallenge.
|
* Ответ на AuthChallenge.
|
||||||
@ -19,7 +19,7 @@ import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public class Net_AuthChallenge_Response extends NetResponse {
|
public class Net_AuthChallenge_Response extends Net_Response {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Одноразовый nonce для авторификации.
|
* Одноразовый nonce для авторификации.
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package server.logic.ws_protocol.JSON.entyties.Auth;
|
package server.logic.ws_protocol.JSON.entyties.Auth;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Шаг 2 авторизации: подтверждение владения ключом и установка сессии.
|
* Шаг 2 авторизации: подтверждение владения ключом и установка сессии.
|
||||||
@ -28,7 +28,7 @@ import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public class Net_CreateAuthSession_Request extends NetRequest {
|
public class Net_CreateAuthSession_Request extends Net_Request {
|
||||||
|
|
||||||
/** Клиентский пароль для хранения данных (base64 от 32 байт). */
|
/** Клиентский пароль для хранения данных (base64 от 32 байт). */
|
||||||
private String storagePwd;
|
private String storagePwd;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package server.logic.ws_protocol.JSON.entyties.Auth;
|
package server.logic.ws_protocol.JSON.entyties.Auth;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ответ на CreateAuthSession.
|
* Ответ на CreateAuthSession.
|
||||||
@ -19,7 +19,7 @@ import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public class Net_CreateAuthSession_Response extends NetResponse {
|
public class Net_CreateAuthSession_Response extends Net_Response {
|
||||||
|
|
||||||
/** Идентификатор сессии, base64 от 32 байт. */
|
/** Идентификатор сессии, base64 от 32 байт. */
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package server.logic.ws_protocol.JSON.entyties.Auth;
|
package server.logic.ws_protocol.JSON.entyties.Auth;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Запрос RefreshSession.
|
* Запрос RefreshSession.
|
||||||
@ -15,7 +15,7 @@ import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
|||||||
* "clientInfo": "до 50 символов, краткая строка об устройстве"
|
* "clientInfo": "до 50 символов, краткая строка об устройстве"
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public class Net_RefreshSession_Request extends NetRequest {
|
public class Net_RefreshSession_Request extends Net_Request {
|
||||||
|
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
private String sessionPwd;
|
private String sessionPwd;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package server.logic.ws_protocol.JSON.entyties.Auth;
|
package server.logic.ws_protocol.JSON.entyties.Auth;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Успешный ответ на RefreshSession.
|
* Успешный ответ на RefreshSession.
|
||||||
@ -18,7 +18,7 @@ import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public class Net_RefreshSession_Response extends NetResponse {
|
public class Net_RefreshSession_Response extends Net_Response {
|
||||||
|
|
||||||
/** Пароль хранилища, сохранённый в сессии (storagePwd). */
|
/** Пароль хранилища, сохранённый в сессии (storagePwd). */
|
||||||
private String storagePwd;
|
private String storagePwd;
|
||||||
|
|||||||
@ -33,8 +33,7 @@ Net_RefreshSession_Request — обновление / продление
|
|||||||
|
|
||||||
план что сделать
|
план что сделать
|
||||||
|
|
||||||
Додумать названия что бы было общее новое приветствие ( и поле назвать число для проверки а не пароль )
|
получить список сесссий
|
||||||
или от него или новая сессия (и плюс в ней новый пароль передавать)
|
и удалить сессию
|
||||||
или получить список сесссий
|
|
||||||
или удалить сессию
|
при новом подключении или при активной сесии
|
||||||
И добавить хранимую инфу по сессии
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ package server.logic.ws_protocol.JSON.entyties;
|
|||||||
* "payload": { ... }
|
* "payload": { ... }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public abstract class NetEvent {
|
public abstract class Net_Event {
|
||||||
|
|
||||||
/** Имя операции / события (op). */
|
/** Имя операции / события (op). */
|
||||||
private String op;
|
private String op;
|
||||||
@ -9,7 +9,7 @@ package server.logic.ws_protocol.JSON.entyties;
|
|||||||
* "message": "..."
|
* "message": "..."
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public class NetExceptionResponse extends NetResponse {
|
public class Net_Exception_Response extends Net_Response {
|
||||||
|
|
||||||
private String code;
|
private String code;
|
||||||
private String message;
|
private String message;
|
||||||
@ -12,7 +12,7 @@ package server.logic.ws_protocol.JSON.entyties;
|
|||||||
* "payload": { ... }
|
* "payload": { ... }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public abstract class NetRequest extends NetEvent {
|
public abstract class Net_Request extends Net_Event {
|
||||||
|
|
||||||
/** Идентификатор запроса, чтобы связать запрос и ответ. */
|
/** Идентификатор запроса, чтобы связать запрос и ответ. */
|
||||||
private String requestId;
|
private String requestId;
|
||||||
@ -13,7 +13,7 @@ package server.logic.ws_protocol.JSON.entyties;
|
|||||||
* "payload": { ... } // и для успеха, и для ошибки
|
* "payload": { ... } // и для успеха, и для ошибки
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public abstract class NetResponse extends NetRequest {
|
public abstract class Net_Response extends Net_Request {
|
||||||
|
|
||||||
/** Статус результата (200 — успех, любое другое значение — ошибка). */
|
/** Статус результата (200 — успех, любое другое значение — ошибка). */
|
||||||
private int status;
|
private int status;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package server.logic.ws_protocol.JSON.entyties.tempToTest;
|
package server.logic.ws_protocol.JSON.entyties.tempToTest;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Запрос AddUser — временная/тестовая регистрация локального пользователя.
|
* Запрос AddUser — временная/тестовая регистрация локального пользователя.
|
||||||
@ -22,7 +22,7 @@ import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
|||||||
*
|
*
|
||||||
* Все поля лежат внутри payload.
|
* Все поля лежат внутри payload.
|
||||||
*/
|
*/
|
||||||
public class NetAddUserRequest extends NetRequest {
|
public class Net_AddUser_Request extends Net_Request {
|
||||||
|
|
||||||
private String login;
|
private String login;
|
||||||
private long loginId;
|
private long loginId;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
package server.logic.ws_protocol.JSON.entyties.tempToTest;
|
package server.logic.ws_protocol.JSON.entyties.tempToTest;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Успешный ответ на AddUser.
|
* Успешный ответ на AddUser.
|
||||||
@ -15,6 +15,6 @@ import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
|||||||
* "payload": { }
|
* "payload": { }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public class NetAddUserResponse extends NetResponse {
|
public class Net_AddUser_Response extends Net_Response {
|
||||||
// При необходимости сюда можно добавить, например, флаг created/updated и т.п.
|
// При необходимости сюда можно добавить, например, флаг created/updated и т.п.
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server.logic.ws_protocol.JSON.handlers;
|
package server.logic.ws_protocol.JSON.handlers;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
import server.logic.ws_protocol.JSON.ConnectionContext;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Общий интерфейс для всех JSON-хэндлеров.
|
* Общий интерфейс для всех JSON-хэндлеров.
|
||||||
@ -15,5 +15,5 @@ public interface JsonMessageHandler {
|
|||||||
* @param request распарсенный запрос
|
* @param request распарсенный запрос
|
||||||
* @param ctx контекст текущего WebSocket-соединения
|
* @param ctx контекст текущего WebSocket-соединения
|
||||||
*/
|
*/
|
||||||
NetResponse handle(NetRequest request, ConnectionContext ctx) throws Exception;
|
Net_Response handle(Net_Request request, ConnectionContext ctx) throws Exception;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class Net_AuthChallenge_Handler implements JsonMessageHandler {
|
|||||||
private static final SecureRandom RANDOM = new SecureRandom();
|
private static final SecureRandom RANDOM = new SecureRandom();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetResponse handle(NetRequest baseReq, ConnectionContext ctx) throws Exception {
|
public Net_Response handle(Net_Request baseReq, ConnectionContext ctx) throws Exception {
|
||||||
|
|
||||||
Net_AuthChallenge_Request req = (Net_AuthChallenge_Request) baseReq;
|
Net_AuthChallenge_Request req = (Net_AuthChallenge_Request) baseReq;
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import server.logic.ws_protocol.JSON.ActiveConnectionsRegistry;
|
import server.logic.ws_protocol.JSON.ActiveConnectionsRegistry;
|
||||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
import server.logic.ws_protocol.JSON.ConnectionContext;
|
||||||
import server.logic.ws_protocol.JSON.entyties.Auth.Net_CreateAuthSession_Response;
|
import server.logic.ws_protocol.JSON.entyties.Auth.Net_CreateAuthSession_Response;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
import server.logic.ws_protocol.JSON.entyties.Auth.Net_CreateAuthSession_Request;
|
import server.logic.ws_protocol.JSON.entyties.Auth.Net_CreateAuthSession_Request;
|
||||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
||||||
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
||||||
@ -53,7 +53,7 @@ public class Net_CreateAuthSession__Handler implements JsonMessageHandler {
|
|||||||
private static final long ALLOWED_SKEW_MS = 30_000L;
|
private static final long ALLOWED_SKEW_MS = 30_000L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetResponse handle(NetRequest baseReq, ConnectionContext ctx) throws Exception {
|
public Net_Response handle(Net_Request baseReq, ConnectionContext ctx) throws Exception {
|
||||||
Net_CreateAuthSession_Request req = (Net_CreateAuthSession_Request) baseReq;
|
Net_CreateAuthSession_Request req = (Net_CreateAuthSession_Request) baseReq;
|
||||||
|
|
||||||
// --- базовые проверки контекста ---
|
// --- базовые проверки контекста ---
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import server.logic.ws_protocol.JSON.ActiveConnectionsRegistry;
|
|||||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
import server.logic.ws_protocol.JSON.ConnectionContext;
|
||||||
import server.logic.ws_protocol.JSON.entyties.Auth.Net_RefreshSession_Request;
|
import server.logic.ws_protocol.JSON.entyties.Auth.Net_RefreshSession_Request;
|
||||||
import server.logic.ws_protocol.JSON.entyties.Auth.Net_RefreshSession_Response;
|
import server.logic.ws_protocol.JSON.entyties.Auth.Net_RefreshSession_Response;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
||||||
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
||||||
import server.logic.ws_protocol.WireCodes;
|
import server.logic.ws_protocol.WireCodes;
|
||||||
@ -37,7 +37,7 @@ public class Net_RefreshSession_Handler implements JsonMessageHandler {
|
|||||||
private static final int CLIENT_INFO_MAX_LEN = 50;
|
private static final int CLIENT_INFO_MAX_LEN = 50;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetResponse handle(NetRequest request, ConnectionContext ctx) throws Exception {
|
public Net_Response handle(Net_Request request, ConnectionContext ctx) throws Exception {
|
||||||
Net_RefreshSession_Request req = (Net_RefreshSession_Request) request;
|
Net_RefreshSession_Request req = (Net_RefreshSession_Request) request;
|
||||||
|
|
||||||
String sessionId = req.getSessionId();
|
String sessionId = req.getSessionId();
|
||||||
|
|||||||
@ -3,10 +3,10 @@ package server.logic.ws_protocol.JSON.handlers.tempToTest;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
import server.logic.ws_protocol.JSON.ConnectionContext;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||||
import server.logic.ws_protocol.JSON.entyties.tempToTest.NetAddUserRequest;
|
import server.logic.ws_protocol.JSON.entyties.tempToTest.Net_AddUser_Request;
|
||||||
import server.logic.ws_protocol.JSON.entyties.tempToTest.NetAddUserResponse;
|
import server.logic.ws_protocol.JSON.entyties.tempToTest.Net_AddUser_Response;
|
||||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
||||||
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
||||||
import server.logic.ws_protocol.WireCodes;
|
import server.logic.ws_protocol.WireCodes;
|
||||||
@ -36,13 +36,13 @@ import java.sql.SQLException;
|
|||||||
* - пользователь сохраняется в таблицу solana_users;
|
* - пользователь сохраняется в таблицу solana_users;
|
||||||
* - возвращается status=200 и пустой payload.
|
* - возвращается status=200 и пустой payload.
|
||||||
*/
|
*/
|
||||||
public class NetAddUserHandler implements JsonMessageHandler {
|
public class Net_AddUser_Handler implements JsonMessageHandler {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(NetAddUserHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(Net_AddUser_Handler.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetResponse handle(NetRequest baseRequest, ConnectionContext ctx) throws Exception {
|
public Net_Response handle(Net_Request baseRequest, ConnectionContext ctx) throws Exception {
|
||||||
NetAddUserRequest req = (NetAddUserRequest) baseRequest;
|
Net_AddUser_Request req = (Net_AddUser_Request) baseRequest;
|
||||||
|
|
||||||
// Одна общая проверка всех ключевых полей
|
// Одна общая проверка всех ключевых полей
|
||||||
if (req.getLogin() == null || req.getLogin().isBlank()
|
if (req.getLogin() == null || req.getLogin().isBlank()
|
||||||
@ -72,7 +72,7 @@ public class NetAddUserHandler implements JsonMessageHandler {
|
|||||||
|
|
||||||
dao.insert(user);
|
dao.insert(user);
|
||||||
|
|
||||||
NetAddUserResponse resp = new NetAddUserResponse();
|
Net_AddUser_Response resp = new Net_AddUser_Response();
|
||||||
resp.setOp(req.getOp());
|
resp.setOp(req.getOp());
|
||||||
resp.setRequestId(req.getRequestId());
|
resp.setRequestId(req.getRequestId());
|
||||||
resp.setStatus(WireCodes.Status.OK);
|
resp.setStatus(WireCodes.Status.OK);
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package server.logic.ws_protocol.JSON.utils;
|
package server.logic.ws_protocol.JSON.utils;
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetExceptionResponse;
|
import server.logic.ws_protocol.JSON.entyties.Net_Exception_Response;
|
||||||
import server.logic.ws_protocol.JSON.entyties.NetRequest;
|
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Фабрика ошибок для JSON-протокола.
|
* Фабрика ошибок для JSON-протокола.
|
||||||
@ -13,12 +13,12 @@ public final class NetExceptionResponseFactory {
|
|||||||
// запрет на создание объектов
|
// запрет на создание объектов
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NetExceptionResponse error(NetRequest req,
|
public static Net_Exception_Response error(Net_Request req,
|
||||||
int status,
|
int status,
|
||||||
String code,
|
String code,
|
||||||
String message) {
|
String message) {
|
||||||
|
|
||||||
NetExceptionResponse resp = new NetExceptionResponse();
|
Net_Exception_Response resp = new Net_Exception_Response();
|
||||||
resp.setOp(req.getOp());
|
resp.setOp(req.getOp());
|
||||||
resp.setRequestId(req.getRequestId());
|
resp.setRequestId(req.getRequestId());
|
||||||
resp.setStatus(status);
|
resp.setStatus(status);
|
||||||
@ -31,13 +31,13 @@ public final class NetExceptionResponseFactory {
|
|||||||
* Вариант для случаев, когда NetRequest ещё не распарсен,
|
* Вариант для случаев, когда NetRequest ещё не распарсен,
|
||||||
* но мы уже знаем op и requestId (или они null).
|
* но мы уже знаем op и requestId (или они null).
|
||||||
*/
|
*/
|
||||||
public static NetExceptionResponse error(String op,
|
public static Net_Exception_Response error(String op,
|
||||||
String requestId,
|
String requestId,
|
||||||
int status,
|
int status,
|
||||||
String code,
|
String code,
|
||||||
String message) {
|
String message) {
|
||||||
|
|
||||||
NetExceptionResponse resp = new NetExceptionResponse();
|
Net_Exception_Response resp = new Net_Exception_Response();
|
||||||
resp.setOp(op);
|
resp.setOp(op);
|
||||||
resp.setRequestId(requestId);
|
resp.setRequestId(requestId);
|
||||||
resp.setStatus(status);
|
resp.setStatus(status);
|
||||||
|
|||||||
@ -46,8 +46,8 @@ public class Test_AddUser_and_Authorification {
|
|||||||
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
|
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
// Тестовые данные пользователя
|
// Тестовые данные пользователя
|
||||||
private static final String TEST_LOGIN = "anya2";
|
private static final String TEST_LOGIN = "anya24";
|
||||||
private static final long TEST_LOGIN_ID = 100120L;
|
private static final long TEST_LOGIN_ID = 1030120L;
|
||||||
private static final long TEST_BCH_ID = 4222L;
|
private static final long TEST_BCH_ID = 4222L;
|
||||||
private static final int TEST_BCH_LIMIT = 1_000_000;
|
private static final int TEST_BCH_LIMIT = 1_000_000;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user