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);
}
}
}
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());
}
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;
}
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);
}
Aggregations