Search in sources :

Example 61 with RequestContext

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Locale(java.util.Locale) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 62 with RequestContext

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) HashMap(java.util.HashMap) IURLManager(com.agiletec.aps.system.services.url.IURLManager) Page(com.agiletec.aps.system.services.page.Page) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 63 with RequestContext

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);
    }
}
Also used : IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) Template(freemarker.template.Template) HttpServletRequest(javax.servlet.http.HttpServletRequest) StringReader(java.io.StringReader) RequestContext(com.agiletec.aps.system.RequestContext) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer) Writer(java.io.Writer)

Example 64 with RequestContext

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;
}
Also used : ServletException(javax.servlet.ServletException) RequestContext(com.agiletec.aps.system.RequestContext)

Example 65 with RequestContext

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;
}
Also used : RequestContext(com.agiletec.aps.system.RequestContext)

Aggregations

RequestContext (com.agiletec.aps.system.RequestContext)89 ServletRequest (javax.servlet.ServletRequest)25 JspException (javax.servlet.jsp.JspException)22 IPage (com.agiletec.aps.system.services.page.IPage)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)12 Lang (com.agiletec.aps.system.services.lang.Lang)10 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 Widget (com.agiletec.aps.system.services.page.Widget)5 NavigatorTarget (com.agiletec.aps.system.services.page.widget.NavigatorTarget)5 IURLManager (com.agiletec.aps.system.services.url.IURLManager)5 ContentRenderizationInfo (com.agiletec.plugins.jacms.aps.system.services.dispenser.ContentRenderizationInfo)5 DataObjectRenderizationInfo (org.entando.entando.aps.system.services.dataobjectdispenser.DataObjectRenderizationInfo)5 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 ControllerManager (com.agiletec.aps.system.services.controller.ControllerManager)3 HeadInfoContainer (com.agiletec.aps.tags.util.HeadInfoContainer)3 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)3 IContentListWidgetHelper (com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListWidgetHelper)3 IContentViewerHelper (com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper)3