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);
}
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);
}
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();
}
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;
}
}
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);
}
}
}
}
Aggregations