Search in sources :

Example 21 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class WidgetTag method doEndTag.

public int doEndTag() throws JspException {
    ServletRequest req = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
    IPage page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
    try {
        String[] showletOutput = (String[]) reqCtx.getExtraParam("ShowletOutput");
        if (_frame < 0 || _frame >= showletOutput.length) {
            _logger.error("Frame attribute {} exceeds the limit in the page {}", _frame, page.getCode());
            String msg = "Frame attribute =" + _frame + " exceeds the limit in the page " + page.getCode();
            throw new JspException(msg);
        // ApsSystemUtils.getLogger().error(msg);
        }
        String showlet = showletOutput[_frame];
        if (null == showlet)
            showlet = "";
        this.pageContext.getOut().print(showlet);
    } catch (Throwable t) {
        String msg = "Error detected in the inclusion of the output widget";
        _logger.error("Error detected in the inclusion of the output widget", t);
        // ApsSystemUtils.logThrowable(t, this, "doEndTag", msg);
        throw new JspException(msg, t);
    }
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) IPage(com.agiletec.aps.system.services.page.IPage) RequestContext(com.agiletec.aps.system.RequestContext)

Example 22 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class PagerTagHelper method getPagerId.

private String getPagerId(String pagerId, boolean pagerIdFromFrame, ServletRequest request) {
    String truePagerId = pagerId;
    if (null == truePagerId && pagerIdFromFrame) {
        RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
        if (reqCtx != null) {
            int currentFrame = this.getCurrentFrame(reqCtx);
            truePagerId = "frame" + currentFrame;
        }
    }
    return truePagerId;
}
Also used : RequestContext(com.agiletec.aps.system.RequestContext)

Example 23 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class Struts2ServletDispatcher method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    try {
        RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
        String currentFrameActionPath = request.getParameter(InternalServletTag.REQUEST_PARAM_FRAMEDEST);
        Integer currentFrame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME);
        Boolean staticAction = (Boolean) reqCtx.getExtraParam(InternalServletTag.EXTRAPAR_STATIC_ACTION);
        boolean executeCustomAction = (null == staticAction || !staticAction) && (null == currentFrameActionPath || Integer.parseInt(currentFrameActionPath) == currentFrame.intValue());
        prepare.createActionContext(request, response);
        prepare.assignDispatcherToThread();
        prepare.setEncodingAndLocale(request, response);
        request = prepare.wrapRequest(request);
        ActionMapper actionMapper = new ExtendedDefaultActionMapper();
        Dispatcher dispatcher = prepare.getDispatcher();
        String entandoActionName = EntandoActionUtils.extractEntandoActionName(request);
        ActionMapping mapping = actionMapper.getMapping(request, dispatcher.getConfigurationManager());
        if (mapping != null && null != entandoActionName && executeCustomAction) {
            mapping.setName(entandoActionName);
        }
        if (mapping == null) {
            boolean handled = execute.executeStaticResourceRequest(request, response);
            if (!handled) {
                throw new ServletException("Resource loading not supported, use the StrutsPrepareAndExecuteFilter instead.");
            }
        } else {
            execute.executeAction(request, response, mapping);
        }
    } finally {
        prepare.cleanupRequest(request);
    }
}
Also used : ServletException(javax.servlet.ServletException) ActionMapper(org.apache.struts2.dispatcher.mapper.ActionMapper) ExtendedDefaultActionMapper(org.entando.entando.aps.internalservlet.system.dispatcher.mapper.ExtendedDefaultActionMapper) ActionMapping(org.apache.struts2.dispatcher.mapper.ActionMapping) ExtendedDefaultActionMapper(org.entando.entando.aps.internalservlet.system.dispatcher.mapper.ExtendedDefaultActionMapper) RequestContext(com.agiletec.aps.system.RequestContext) Dispatcher(org.apache.struts2.dispatcher.Dispatcher)

Example 24 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class TestCacheInfoManager method testGetRenderedContent_1.

public void testGetRenderedContent_1() throws Throwable {
    RequestContext reqCtx = this.getRequestContext();
    String contentId = null;
    String langCode = "en";
    long modelId = -1;
    try {
        modelId = this.createMockContentModel();
        contentId = this.createMockContent();
        String renderInfoCacheKey = BaseContentDispenser.getRenderizationInfoCacheKey(contentId, modelId, langCode, reqCtx);
        assertNull(this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, renderInfoCacheKey));
        ContentRenderizationInfo outputInfo = this._contentDispenser.getRenderizationInfo(contentId, modelId, langCode, reqCtx);
        ContentRenderizationInfo cachedOutputInfo = (ContentRenderizationInfo) this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, renderInfoCacheKey);
        assertNotNull(cachedOutputInfo);
        assertEquals(outputInfo.hashCode(), cachedOutputInfo.hashCode());
        assertEquals(outputInfo.getContentId(), cachedOutputInfo.getContentId());
        assertEquals(outputInfo.getModelId(), cachedOutputInfo.getModelId());
        assertEquals(outputInfo.getCachedRenderedContent(), cachedOutputInfo.getCachedRenderedContent());
    } catch (Throwable t) {
        throw t;
    } finally {
        this.deleteMockContentObject(contentId, modelId);
    }
}
Also used : ContentRenderizationInfo(com.agiletec.plugins.jacms.aps.system.services.dispenser.ContentRenderizationInfo) RequestContext(com.agiletec.aps.system.RequestContext)

Example 25 with RequestContext

use of com.agiletec.aps.system.RequestContext in project entando-core by entando.

the class TestCacheInfoManager method testGetRenderedContentsGroup.

protected void testGetRenderedContentsGroup(String contentId, long modelId, String cacheGroupId) throws Throwable {
    RequestContext reqCtx = this.getRequestContext();
    String langCode = "en";
    try {
        String groupsCsv = BaseContentDispenser.getRenderizationInfoCacheGroupsCsv(contentId, modelId);
        String renderInfoCacheKey = BaseContentDispenser.getRenderizationInfoCacheKey(contentId, modelId, langCode, reqCtx);
        assertNull(this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, renderInfoCacheKey));
        ContentRenderizationInfo outputInfo = this._contentDispenser.getRenderizationInfo(contentId, modelId, langCode, reqCtx);
        assertNotNull(outputInfo);
        assertNotNull(this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, renderInfoCacheKey));
        // -----------
        assertTrue(groupsCsv.indexOf(cacheGroupId) > -1);
        this._cacheInfoManager.flushGroup(ICacheInfoManager.DEFAULT_CACHE_NAME, cacheGroupId);
        assertNull(this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, renderInfoCacheKey));
        outputInfo = this._contentDispenser.getRenderizationInfo(contentId, modelId, langCode, reqCtx);
        assertNotNull(outputInfo);
        assertNotNull(this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, renderInfoCacheKey));
        // -----------
        outputInfo = this._contentDispenser.getRenderizationInfo(contentId, modelId, langCode, reqCtx);
        assertNotNull(outputInfo);
        assertNotNull(this._cacheInfoManager.getFromCache(ICacheInfoManager.DEFAULT_CACHE_NAME, renderInfoCacheKey));
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ContentRenderizationInfo(com.agiletec.plugins.jacms.aps.system.services.dispenser.ContentRenderizationInfo) 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