use of act.handler.event.ReflectedHandlerInvokerInvoke in project actframework by actframework.
the class ReflectedHandlerInvoker method handle.
public Result handle(final ActionContext context) {
if (disabled) {
return ActNotFound.get();
}
if (null != throttleFilter) {
Result throttleResult = throttleFilter.handle(context);
if (null != throttleResult) {
return throttleResult;
}
}
Result result = pluginBeforeHandler.apply(context);
if (null != result) {
return result;
}
context.setReflectedHandlerInvoker(this);
app.eventBus().emit(new ReflectedHandlerInvokerInvoke(this, context));
if (isLargeResponse) {
context.setLargeResponse();
}
if (null != filters) {
context.fastjsonFilters(filters);
}
if (null != features) {
context.fastjsonFeatures(features);
}
if (null != dateFormatPattern) {
context.dateFormatPattern(dateFormatPattern);
}
if (byPassImplicityTemplateVariable && context.state().isHandling()) {
context.byPassImplicitVariable();
}
context.templateChangeListener(templateChangeListener);
if (noTemplateCache) {
context.disableTemplateCaching();
}
context.currentMethod(method);
String urlContext = this.controller.urlContext();
if (S.notBlank(urlContext)) {
context.urlContext(urlContext);
}
String templateContext = this.controller.templateContext();
if (null != templateContext) {
context.templateContext(templateContext);
}
preventDoubleSubmission(context);
processForceResponse(context);
if (forceDataBinding || context.state().isHandling()) {
ensureJsonDTOGenerated(context);
}
final Object controller = controllerInstance(context);
/*
* We will send back response immediately when param validation
* failed in either of the following cases:
* 1) this is an ajax call
* 2) the accept content type is **NOT** html
*/
boolean failOnViolation = context.isAjax() || context.accept() != H.Format.HTML;
final Object[] params = params(controller, context);
if (failOnViolation && context.hasViolation()) {
String msg = context.violationMessage(";");
return ActBadRequest.create(msg);
}
if (async) {
JobManager jobManager = context.app().jobManager();
String jobId = jobManager.prepare(new TrackableWorker() {
@Override
protected void run(ProgressGauge progressGauge) {
try {
invoke(handler, context, controller, params);
} catch (Exception e) {
logger.warn(e, "Error executing async handler: " + handler);
}
}
});
context.setJobId(jobId);
WebSocketConnectionManager wscm = app.getInstance(WebSocketConnectionManager.class);
wscm.subscribe(context.session(), SimpleProgressGauge.wsJobProgressTag(jobId));
jobManager.now(jobId);
return new RenderJSON(C.Map("jobId", jobId));
}
try {
return pluginAfterHandler.apply(invoke(handler, context, controller, params), context);
} finally {
if (hasOutputVar) {
fillOutputVariables(controller, params, context);
}
}
}
Aggregations