Search in sources :

Example 66 with RequestContext

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

the class PreviewControllerServlet 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.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.REDIRECT) {
        // _logger.debug("Redirection");
        // this.redirect(reqCtx, response);
        // } else if (status == ControllerManager.ERROR) {
        // _logger.debug("Error");
        // this.outputError(reqCtx, response);
        // } else {
        _logger.error("Error: final status = {} - request: {} - path: {}", ControllerManager.getStatusDescription(status), request.getServletPath(), request.getPathInfo());
        throw new ServletException("Service not available");
    // }
    }
    return;
}
Also used : ServletException(javax.servlet.ServletException) RequestContext(com.agiletec.aps.system.RequestContext)

Example 67 with RequestContext

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

the class ContentPreviewTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        IContentViewerHelper helper = (IContentViewerHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_PREVIEW_VIEWER_HELPER, this.pageContext);
        String renderedContent = helper.getRenderedContent(null, null, reqCtx);
        this.pageContext.getOut().print(renderedContent);
    } catch (Throwable t) {
        _logger.error("error in doStartTag", t);
        throw new JspException("Error detected during tag initialisation", t);
    }
    return EVAL_PAGE;
}
Also used : ServletRequest(javax.servlet.ServletRequest) IContentViewerHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper) JspException(javax.servlet.jsp.JspException) RequestContext(com.agiletec.aps.system.RequestContext)

Example 68 with RequestContext

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

the class TestControllerManager method testService_3.

public void testService_3() throws ApsSystemException {
    RequestContext reqCtx = this.getRequestContext();
    ControllerManager controller = (ControllerManager) this.getService(SystemConstants.CONTROLLER_MANAGER);
    MockHttpServletRequest request = (MockHttpServletRequest) reqCtx.getRequest();
    request.setServletPath("/it/administrators_page.page");
    request.setRequestURI("/Entando/it/customers_page.page");
    int status = controller.service(reqCtx);
    assertEquals(ControllerManager.REDIRECT, status);
    String redirectUrl = (String) reqCtx.getExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL);
    assertTrue(redirectUrl.contains("/Entando/it/login.page?"));
    assertTrue(redirectUrl.contains("redirectflag=1"));
    assertTrue(redirectUrl.contains("returnUrl="));
    assertTrue(redirectUrl.contains("customers_page.page"));
    request.setParameter(RequestContext.PAR_REDIRECT_FLAG, "1");
    status = controller.service(reqCtx);
    assertEquals(ControllerManager.REDIRECT, status);
    redirectUrl = (String) reqCtx.getExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL);
    assertEquals("/Entando/it/errorpage.page", redirectUrl);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ControllerManager(com.agiletec.aps.system.services.controller.ControllerManager) RequestContext(com.agiletec.aps.system.RequestContext)

Example 69 with RequestContext

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

the class TestControllerManager method testService_2.

public void testService_2() throws ApsSystemException {
    RequestContext reqCtx = this.getRequestContext();
    ControllerManager controller = (ControllerManager) this.getService(SystemConstants.CONTROLLER_MANAGER);
    MockHttpServletRequest request = (MockHttpServletRequest) reqCtx.getRequest();
    request.setServletPath("/it/customers_page.page");
    int status = controller.service(reqCtx);
    assertEquals(ControllerManager.REDIRECT, status);
    request.setParameter("username", "admin");
    request.setParameter("password", "admin");
    request.setServletPath("/it/customers_page.page");
    status = controller.service(reqCtx);
    assertEquals(ControllerManager.OUTPUT, status);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ControllerManager(com.agiletec.aps.system.services.controller.ControllerManager) RequestContext(com.agiletec.aps.system.RequestContext)

Example 70 with RequestContext

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

the class TestControllerManager method testService_1.

public void testService_1() throws ApsSystemException {
    RequestContext reqCtx = this.getRequestContext();
    ControllerManager controller = (ControllerManager) this.getService(SystemConstants.CONTROLLER_MANAGER);
    MockHttpServletRequest request = (MockHttpServletRequest) reqCtx.getRequest();
    request.setServletPath("/it/homepage.page");
    int status = controller.service(reqCtx);
    assertEquals(ControllerManager.OUTPUT, status);
    request.setParameter("username", "admin");
    request.setParameter("password", "admin");
    status = controller.service(reqCtx);
    assertEquals(ControllerManager.OUTPUT, status);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ControllerManager(com.agiletec.aps.system.services.controller.ControllerManager) 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