Search in sources :

Example 16 with EzyData

use of com.tvd12.ezyfox.entity.EzyData in project ezyfox-server by youngmonkeys.

the class EzyPluginSendResponseImpl method execute.

@Override
public void execute(EzyData data, Collection<EzySession> recipients, boolean encrypted, EzyTransportType transportType) {
    EzyResponse response = newResponse(data);
    serverContext.send(response, recipients, encrypted, transportType);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse)

Example 17 with EzyData

use of com.tvd12.ezyfox.entity.EzyData in project ezyfox-server by youngmonkeys.

the class EzyAppSendResponseImpl method execute.

@Override
public void execute(EzyData data, EzySession recipient, boolean encrypted, EzyTransportType transportType) {
    EzyResponse response = newResponse(data);
    serverContext.send(response, recipient, encrypted, transportType);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse)

Example 18 with EzyData

use of com.tvd12.ezyfox.entity.EzyData in project ezyfox-server by youngmonkeys.

the class EzyAbstractResponse method execute.

@Override
public void execute() {
    recipients.removeAll(exclusiveRecipients);
    EzyData data = newResponseData();
    sendData(data, transportType);
    destroy();
}
Also used : EzyData(com.tvd12.ezyfox.entity.EzyData)

Example 19 with EzyData

use of com.tvd12.ezyfox.entity.EzyData 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 20 with EzyData

use of com.tvd12.ezyfox.entity.EzyData 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

EzyData (com.tvd12.ezyfox.entity.EzyData)12 BaseTest (com.tvd12.test.base.BaseTest)7 Test (org.testng.annotations.Test)7 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)4 EzyApp (com.tvd12.ezyfoxserver.client.entity.EzyApp)3 EzyData (com.tvd12.ezyfoxserver.client.entity.EzyData)3 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)3 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)3 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)3 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)3 EzyBadRequestException (com.tvd12.ezyfox.core.exception.EzyBadRequestException)2 EzyObject (com.tvd12.ezyfox.entity.EzyObject)2 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)2 EzyClient (com.tvd12.ezyfoxserver.client.EzyClient)2 EzyClients (com.tvd12.ezyfoxserver.client.EzyClients)2 EzyUTClient (com.tvd12.ezyfoxserver.client.EzyUTClient)2 EzyClientConfig (com.tvd12.ezyfoxserver.client.config.EzyClientConfig)2 EzyAppSetup (com.tvd12.ezyfoxserver.client.setup.EzyAppSetup)2 EzySetup (com.tvd12.ezyfoxserver.client.setup.EzySetup)2