use of com.agiletec.aps.system.RequestContext in project entando-core by entando.
the class I18nFrontEndInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
if (null != reqCtx) {
Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
Locale locale = new Locale(currentLang.getCode(), "");
invocation.getInvocationContext().setLocale(locale);
}
return invocation.invoke();
}
use of com.agiletec.aps.system.RequestContext in project entando-core by entando.
the class FrontServletActionRedirectResult method execute.
@Override
public void execute(ActionInvocation invocation) throws Exception {
try {
this._actionName = this.conditionalParse(this._actionName, invocation);
if (this._namespace == null) {
this._namespace = invocation.getProxy().getNamespace();
} else {
this._namespace = this.conditionalParse(this._namespace, invocation);
}
if (this._method == null) {
this._method = "";
} else {
this._method = this.conditionalParse(this._method, invocation);
}
String anchorDest = null;
Map<String, String> redirectParams = new HashMap<String, String>();
ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
if (resultConfig != null) {
this.extractResultParams(redirectParams, resultConfig, invocation);
anchorDest = this.extractAnchorDest(resultConfig, invocation);
}
HttpServletRequest request = ServletActionContext.getRequest();
RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
this.extractInternalServletParams(redirectParams, reqCtx);
IURLManager urlManager = (IURLManager) ApsWebApplicationUtils.getBean(SystemConstants.URL_MANAGER, request);
Page currentPage = (Page) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
String url = urlManager.createURL(currentPage, currentLang, redirectParams, false, request);
if (null != anchorDest) {
url += "#" + anchorDest;
}
this.setLocation(url);
} catch (Throwable t) {
_logger.error("error in execute", t);
}
super.execute(invocation);
}
use of com.agiletec.aps.system.RequestContext in project entando-core by entando.
the class GuiFragmentResult method doExecute.
/**
* Execute this result, using the specified fragment.
* @param code The code of the fragment
* @param invocation The invocation
*/
@Override
public void doExecute(String code, ActionInvocation invocation) throws Exception {
if (null == code) {
code = conditionalParse(this._code, invocation);
}
if (null == code) {
this.executeDispatcherResult(invocation);
return;
}
ActionContext ctx = invocation.getInvocationContext();
HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, req);
try {
GuiFragment guiFragment = guiFragmentManager.getGuiFragment(code);
String output = (null != guiFragment) ? guiFragment.getCurrentGui() : null;
if (StringUtils.isBlank(output)) {
_logger.info("The fragment '{}' is not available - Action '{}' - Namespace '{}'", code, invocation.getProxy().getActionName(), invocation.getProxy().getNamespace());
boolean execution = this.executeDispatcherResult(invocation);
if (!execution) {
output = "The fragment '" + code + "' is not available";
} else {
return;
}
}
RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
Writer writer = this.getWriter();
Template template = new Template(code, new StringReader(output), ebc.getConfiguration());
template.process(ebc.getTemplateModel(), writer);
} catch (Throwable t) {
_logger.error("Error processing GuiFragment result!", t);
throw new RuntimeException("Error processing GuiFragment result!", t);
}
}
use of com.agiletec.aps.system.RequestContext in project entando-core by entando.
the class ControllerServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
RequestContext reqCtx = this.initRequestContext(request, response);
int status = this.controlRequest(request, reqCtx);
if (status == ControllerManager.REDIRECT) {
_logger.debug("Redirection");
this.redirect(reqCtx, response);
} else if (status == ControllerManager.OUTPUT) {
_logger.debug("Output");
try {
this.initFreemarker(request, response, reqCtx);
this.executePage(request, reqCtx);
} catch (Throwable t) {
_logger.error("Error building response", t);
throw new ServletException("Error building response", t);
}
} else if (status == ControllerManager.ERROR) {
_logger.debug("Error");
this.outputError(reqCtx, response);
} else {
_logger.error("Error: final status = {} - request: {}", ControllerManager.getStatusDescription(status), request.getServletPath());
throw new ServletException("Service not available");
}
return;
}
use of com.agiletec.aps.system.RequestContext in project entando-core by entando.
the class ControllerServlet method initRequestContext.
protected RequestContext initRequestContext(HttpServletRequest request, HttpServletResponse response) {
RequestContext reqCtx = new RequestContext();
_logger.debug("Request:" + request.getServletPath());
request.setAttribute(RequestContext.REQCTX, reqCtx);
reqCtx.setRequest(request);
reqCtx.setResponse(response);
return reqCtx;
}
Aggregations