Search in sources :

Example 1 with BaseHandler

use of com.gianlu.pyxreborn.server.Handlers.BaseHandler in project PretendYoureXyzzyReborn by devgianlu.

the class Server method onMessage.

/**
 * Picks the right {@link BaseHandler} to perform the requested {@link Operations}.
 */
@Override
@Nullable
protected JsonObject onMessage(WebSocket conn, User user, JsonObject request, JsonObject response) throws GeneralException {
    Operations op = Operations.parse(request.get(Fields.OPERATION.toString()).getAsString());
    if (op == null)
        throw new GeneralException(ErrorCodes.UNKNOWN_OPERATION);
    BaseHandler handler;
    try {
        handler = Handlers.LIST.get(op).newInstance();
    } catch (InstantiationException | IllegalAccessException ex) {
        throw new GeneralException(ErrorCodes.SERVER_ERROR, ex);
    }
    return handler.handleRequest(this, request, response);
}
Also used : GeneralException(com.gianlu.pyxreborn.Exceptions.GeneralException) BaseHandler(com.gianlu.pyxreborn.server.Handlers.BaseHandler) Operations(com.gianlu.pyxreborn.Operations) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GeneralException (com.gianlu.pyxreborn.Exceptions.GeneralException)1 Operations (com.gianlu.pyxreborn.Operations)1 BaseHandler (com.gianlu.pyxreborn.server.Handlers.BaseHandler)1 Nullable (org.jetbrains.annotations.Nullable)1