use of com.tvd12.ezyfox.binding.EzyDataBinding 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;
}
}
Aggregations