Search in sources :

Example 1 with EzyBadRequestException

use of com.tvd12.ezyfox.core.exception.EzyBadRequestException in project ezyfox-server-example by tvd12.

the class BroacastMessageHandler method execute.

@Override
protected void execute() throws EzyBadRequestException {
    EzyApplication app = appContext.getApp();
    EzyAppUserManager userManager = app.getUserManager();
    responseFactory.newObjectResponse().command(BROADCAST_MESSAGE).param("message", message).users(userManager.getUserList()).execute();
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)

Example 2 with EzyBadRequestException

use of com.tvd12.ezyfox.core.exception.EzyBadRequestException in project ezyfox-server-example by tvd12.

the class UdpBroadcastMessageHandler method execute.

@Override
protected void execute() throws EzyBadRequestException {
    EzyApplication app = appContext.getApp();
    EzyAppUserManager userManager = app.getUserManager();
    responseFactory.newObjectResponse().udpTransport().command(UDP_BROADCAST_MESSAGE).param("message", message).users(userManager.getUserList()).execute();
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)

Example 3 with EzyBadRequestException

use of com.tvd12.ezyfox.core.exception.EzyBadRequestException in project ezyfox-server by youngmonkeys.

the class EzyUserRequestPrototypeController method handle.

public void handle(C context, E event) {
    EzyArray data = event.getData();
    String cmd = data.get(0, String.class);
    EzyPrototypeSupplier supplier = handlers.get(cmd);
    if (supplier == null) {
        logger.warn("has no handler with command: {} from session: {}", cmd, event.getSession().getName());
        return;
    }
    EzyHandler handler = (EzyHandler) supplier.supply(beanContext);
    if (handler instanceof EzyUserAware) {
        ((EzyUserAware) handler).setUser(event.getUser());
    }
    if (handler instanceof EzySessionAware) {
        ((EzySessionAware) handler).setSession(event.getSession());
    }
    if (handler instanceof EzyDataBinding) {
        EzyData params = data.get(1, EzyData.class, null);
        if (params != null) {
            unmarshaller.unwrap(params, handler);
        }
    }
    try {
        preHandle(context, event, cmd, handler);
        handler.handle();
        postHandle(context, event, cmd, handler);
    } catch (EzyBadRequestException e) {
        if (e.isSendToClient()) {
            EzyData errorData = newErrorData(e);
            responseError(context, event, errorData);
        }
        logger.debug("request cmd: {} by session: {} with data: {} error", cmd, event.getSession().getName(), data, e);
        postHandle(context, event, cmd, handler, e);
    } catch (Exception e) {
        postHandle(context, event, cmd, handler, e);
        throw e;
    }
}
Also used : EzyUserAware(com.tvd12.ezyfoxserver.entity.EzyUserAware) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyPrototypeSupplier(com.tvd12.ezyfox.bean.EzyPrototypeSupplier) EzyDataBinding(com.tvd12.ezyfox.binding.EzyDataBinding) EzyBadRequestException(com.tvd12.ezyfox.core.exception.EzyBadRequestException) EzyHandler(com.tvd12.ezyfox.function.EzyHandler) EzySessionAware(com.tvd12.ezyfoxserver.entity.EzySessionAware) EzyBadRequestException(com.tvd12.ezyfox.core.exception.EzyBadRequestException)

Example 4 with EzyBadRequestException

use of com.tvd12.ezyfox.core.exception.EzyBadRequestException in project ezyfox-server by youngmonkeys.

the class EzyUserRequestSingletonController method handle.

public void handle(C context, E event) {
    EzyArray data = event.getData();
    String cmd = data.get(0, String.class);
    EzyUserRequestHandler handler = requestHandlers.get(cmd);
    if (handler == null) {
        prototypeController.handle(context, event);
        return;
    }
    Object handlerData = data.get(1, EzyData.class, null);
    Class requestDataType = handler.getDataType();
    if (requestDataType != null) {
        handlerData = unmarshaller.unmarshal(handlerData, requestDataType);
    }
    try {
        preHandle(context, event, cmd, handlerData);
        handler.handle(context, event, handlerData);
        postHandle(context, event, cmd, handlerData);
    } catch (Exception e) {
        postHandle(context, event, cmd, handlerData, e);
        if (e instanceof EzyBadRequestException) {
            EzyBadRequestException ex = (EzyBadRequestException) e;
            if (ex.isSendToClient()) {
                EzyData errorData = newErrorData(ex);
                responseError(context, event, errorData);
            }
            logger.debug("request cmd: {} by session: {} with data: {} error", cmd, event.getSession().getName(), data, e);
        } else {
            EzyUncaughtExceptionHandler exceptionHandler = getExceptionHandler(e.getClass());
            if (exceptionHandler == null) {
                throw new EzyUserRequestException(cmd, handlerData, e);
            }
            try {
                exceptionHandler.handleException(context, event, cmd, handlerData, e);
            } catch (Exception ex) {
                throw new EzyUserRequestException(cmd, handlerData, ex);
            }
        }
    }
}
Also used : EzyUserRequestException(com.tvd12.ezyfoxserver.support.exception.EzyUserRequestException) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyUserRequestHandler(com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyUncaughtExceptionHandler(com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler) EzyBadRequestException(com.tvd12.ezyfox.core.exception.EzyBadRequestException) EzyUserRequestException(com.tvd12.ezyfoxserver.support.exception.EzyUserRequestException) EzyBadRequestException(com.tvd12.ezyfox.core.exception.EzyBadRequestException)

Aggregations

EzyBadRequestException (com.tvd12.ezyfox.core.exception.EzyBadRequestException)2 EzyArray (com.tvd12.ezyfox.entity.EzyArray)2 EzyData (com.tvd12.ezyfox.entity.EzyData)2 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)2 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)2 EzyPrototypeSupplier (com.tvd12.ezyfox.bean.EzyPrototypeSupplier)1 EzyDataBinding (com.tvd12.ezyfox.binding.EzyDataBinding)1 EzyHandler (com.tvd12.ezyfox.function.EzyHandler)1 EzySessionAware (com.tvd12.ezyfoxserver.entity.EzySessionAware)1 EzyUserAware (com.tvd12.ezyfoxserver.entity.EzyUserAware)1 EzyUserRequestException (com.tvd12.ezyfoxserver.support.exception.EzyUserRequestException)1 EzyUncaughtExceptionHandler (com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler)1 EzyUserRequestHandler (com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler)1