Search in sources :

Example 1 with ActionRequest

use of jodd.madvoc.ActionRequest in project jodd by oblac.

the class RequestScopeInjector method outjectMoveSource.

/**
	 * Outjects all request data from move result source, if exist.
	 */
protected void outjectMoveSource(ActionRequest actionRequest) {
    HttpServletRequest servletRequest = actionRequest.getHttpServletRequest();
    String moveId = servletRequest.getParameter(attributeMoveId);
    if (moveId != null) {
        HttpSession session = servletRequest.getSession();
        ActionRequest sourceRequest = (ActionRequest) session.getAttribute(moveId);
        session.removeAttribute(moveId);
        if (sourceRequest != null) {
            outjectAfterMove(sourceRequest);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionRequest(jodd.madvoc.ActionRequest) HttpSession(javax.servlet.http.HttpSession)

Example 2 with ActionRequest

use of jodd.madvoc.ActionRequest in project jodd by oblac.

the class ServletDispatcherResultTest method testServletDispatcherLookup.

@Test
public void testServletDispatcherLookup() throws Exception {
    WebApplication webapp = new WebApplication(true);
    webapp.registerMadvocComponents();
    final List<String> targets = new ArrayList<>();
    ServletDispatcherResult sdr = new ServletDispatcherResult() {

        @Override
        protected boolean targetExists(ActionRequest actionRequest, String target) {
            targets.add(target);
            return false;
        }
    };
    ResultMapper resultMapper = webapp.getComponent(ResultMapper.class);
    BeanUtil.declared.setProperty(sdr, "resultMapper", resultMapper);
    ActionRequest actionRequest = createActionRequest("/hello.world.html");
    sdr.render(actionRequest, "ok");
    assertEquals("[" + "/hello.world.html.ok.jspf, " + "/hello.world.html.ok.jsp, " + "/hello.world.html.jspf, " + "/hello.world.html.jsp, " + "/hello.world.ok.jspf, " + "/hello.world.ok.jsp, " + "/hello.world.jspf, " + "/hello.world.jsp, " + "/hello.ok.jspf, " + "/hello.ok.jsp, " + "/hello.jspf, " + "/hello.jsp, " + "/ok.jspf, " + "/ok.jsp" + "]", targets.toString());
    // folder
    targets.clear();
    actionRequest = createActionRequest("/pak/hello.world.html");
    sdr.render(actionRequest, "ok");
    assertEquals("[" + "/pak/hello.world.html.ok.jspf, " + "/pak/hello.world.html.ok.jsp, " + "/pak/hello.world.html.jspf, " + "/pak/hello.world.html.jsp, " + "/pak/hello.world.ok.jspf, " + "/pak/hello.world.ok.jsp, " + "/pak/hello.world.jspf, " + "/pak/hello.world.jsp, " + "/pak/hello.ok.jspf, " + "/pak/hello.ok.jsp, " + "/pak/hello.jspf, " + "/pak/hello.jsp, " + "/pak/ok.jspf, " + "/pak/ok.jsp" + "]", targets.toString());
    // null result
    targets.clear();
    actionRequest = createActionRequest("/hello.world.html");
    sdr.render(actionRequest, null);
    assertEquals("[" + "/hello.world.html.jspf, " + "/hello.world.html.jsp, " + "/hello.world.jspf, " + "/hello.world.jsp, " + "/hello.jspf, " + "/hello.jsp" + "]", targets.toString());
}
Also used : ActionRequest(jodd.madvoc.ActionRequest) ResultMapper(jodd.madvoc.component.ResultMapper) ArrayList(java.util.ArrayList) WebApplication(jodd.madvoc.WebApplication) Test(org.junit.Test)

Example 3 with ActionRequest

use of jodd.madvoc.ActionRequest in project jodd by oblac.

the class MadvocController method invoke.

// ---------------------------------------------------------------- invoke
/**
	 * Invokes action registered to provided action path, Provides action chaining, by invoking the next action request.
	 * Returns <code>null</code> if action path is consumed and has been invoked by this controller; otherwise
	 * the action path string is returned (it might be different than original one, provided in arguments).
	 * On first invoke, initializes the action configuration before further proceeding.
	 */
public String invoke(String actionPath, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception {
    ActionRequest actionRequest = null;
    boolean characterEncodingSet = false;
    while (actionPath != null) {
        if (log.isDebugEnabled()) {
            log.debug("Action path: " + actionPath);
        }
        // build action path
        String httpMethod = servletRequest.getMethod().toUpperCase();
        actionPath = actionPathRewriter.rewrite(servletRequest, actionPath, httpMethod);
        // resolve action configuration
        ActionConfig actionConfig = actionsManager.lookup(actionPath, httpMethod);
        if (actionConfig == null) {
            return actionPath;
        }
        if (log.isDebugEnabled()) {
            log.debug("Invoking action path '" + actionPath + "' using " + actionConfig.actionClass.getSimpleName());
        }
        // set character encoding
        if (!characterEncodingSet && madvocConfig.isApplyCharacterEncoding()) {
            String encoding = madvocConfig.getEncoding();
            if (encoding != null) {
                servletRequest.setCharacterEncoding(encoding);
                servletResponse.setCharacterEncoding(encoding);
            }
            characterEncodingSet = true;
        }
        // create action object
        Object action = createAction(actionConfig.actionClass);
        // create action request
        ActionRequest previousRequest = actionRequest;
        actionRequest = createActionRequest(actionPath, actionConfig, action, servletRequest, servletResponse);
        actionRequest.setPreviousActionRequest(previousRequest);
        // invoke and render
        if (actionConfig.isAsync()) {
            AsyncContext asyncContext = servletRequest.startAsync();
            executor.execute(new ActionRequestInvoker(asyncContext, actionRequest));
        } else {
            actionRequest.invoke();
        }
        actionPath = actionRequest.getNextActionPath();
    }
    return null;
}
Also used : ActionConfig(jodd.madvoc.ActionConfig) ActionRequest(jodd.madvoc.ActionRequest) AsyncContext(javax.servlet.AsyncContext)

Example 4 with ActionRequest

use of jodd.madvoc.ActionRequest in project jodd by oblac.

the class ServletDispatcherResultTest method createActionRequest.

protected ActionRequest createActionRequest(String actionPath) {
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    HttpServletResponse servletResponse = mock(HttpServletResponse.class);
    HttpSession httpSession = mock(HttpSession.class);
    ServletContext servletContext = mock(ServletContext.class);
    when(servletRequest.getSession()).thenReturn(httpSession);
    when(httpSession.getServletContext()).thenReturn(servletContext);
    MadvocController madvocController = new MadvocController();
    Object action = new Object();
    ActionConfig actionConfig = new ActionConfig(Action.class, ReflectUtil.findMethod(Action.class, "view"), null, null, new ActionDef(actionPath, "GET"), null, false, null, null);
    return new ActionRequest(madvocController, actionConfig.getActionPath(), actionConfig, action, servletRequest, servletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionConfig(jodd.madvoc.ActionConfig) MadvocController(jodd.madvoc.component.MadvocController) ActionRequest(jodd.madvoc.ActionRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) ActionDef(jodd.madvoc.ActionDef)

Aggregations

ActionRequest (jodd.madvoc.ActionRequest)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2 ActionConfig (jodd.madvoc.ActionConfig)2 ArrayList (java.util.ArrayList)1 AsyncContext (javax.servlet.AsyncContext)1 ServletContext (javax.servlet.ServletContext)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ActionDef (jodd.madvoc.ActionDef)1 WebApplication (jodd.madvoc.WebApplication)1 MadvocController (jodd.madvoc.component.MadvocController)1 ResultMapper (jodd.madvoc.component.ResultMapper)1 Test (org.junit.Test)1