Search in sources :

Example 36 with RequestContext

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

the class TestRequestValidator method testServiceFailure_1.

public void testServiceFailure_1() throws ApsSystemException {
    RequestContext reqCtx = this.getRequestContext();
    // Page does not exist
    ((MockHttpServletRequest) reqCtx.getRequest()).setServletPath("/it/notexists.wp");
    int status = _requestValidator.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(ControllerManager.REDIRECT, status);
    String redirectUrl = (String) reqCtx.getExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL);
    assertEquals("/Entando/it/notfound.page?redirectflag=1", redirectUrl);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RequestContext(com.agiletec.aps.system.RequestContext)

Example 37 with RequestContext

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

the class TestRequestValidator method testService.

public void testService() throws ApsSystemException {
    RequestContext reqCtx = this.getRequestContext();
    ((MockHttpServletRequest) reqCtx.getRequest()).setServletPath("/it/homepage.wp");
    int status = this._requestValidator.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(ControllerManager.CONTINUE, status);
    Lang lang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
    IPage page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
    assertNotNull(page);
    assertNotNull(lang);
    assertEquals("it", lang.getCode());
    assertEquals("homepage", page.getCode());
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext)

Example 38 with RequestContext

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

the class BaseTestCase method createRequestContext.

protected RequestContext createRequestContext(ApplicationContext applicationContext, ServletContext srvCtx) {
    RequestContext reqCtx = new RequestContext();
    srvCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setAttribute(RequestContext.REQCTX, reqCtx);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockHttpSession session = new MockHttpSession(srvCtx);
    request.setSession(session);
    reqCtx.setRequest(request);
    reqCtx.setResponse(response);
    ILangManager langManager = (ILangManager) this.getService(SystemConstants.LANGUAGE_MANAGER);
    Lang defaultLang = langManager.getDefaultLang();
    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG, defaultLang);
    return reqCtx;
}
Also used : ILangManager(com.agiletec.aps.system.services.lang.ILangManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpSession(org.springframework.mock.web.MockHttpSession) Lang(com.agiletec.aps.system.services.lang.Lang) RequestContext(com.agiletec.aps.system.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 39 with RequestContext

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

the class GuiFragmentTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        Object extractedValue = this.extractFragmentOutput(reqCtx);
        if (null == extractedValue) {
            _logger.info("The fragment '{}' is not available", this.getCode());
            extractedValue = "The fragment '" + this.getCode() + "' is not available";
        }
        if (this.getVar() != null) {
            this.pageContext.setAttribute(this.getVar(), extractedValue);
        } else {
            if (this.getEscapeXml()) {
                out(this.pageContext, this.getEscapeXml(), extractedValue);
            } else {
                this.pageContext.getOut().print(extractedValue);
            }
        }
    } catch (Throwable t) {
        _logger.error("error in doStartTag", t);
        throw new JspException("Error during tag initialization", t);
    }
    return super.doStartTag();
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) RequestContext(com.agiletec.aps.system.RequestContext)

Example 40 with RequestContext

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

the class RowContentListTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        this.extractExtraWidgetParameters(reqCtx);
        List<Properties> contents = this.getContents(reqCtx);
        this.pageContext.setAttribute(this.getListName(), contents);
    } catch (Throwable t) {
        _logger.error("error in end tag", t);
        throw new JspException("Error detected while finalising the tag", t);
    }
    this.release();
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) RequestContext(com.agiletec.aps.system.RequestContext) Properties(java.util.Properties)

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