use of jodd.madvoc.config.ActionRuntime in project jodd by oblac.
the class ActionsManager method registerActionRuntime.
/**
* Registers manually created {@link ActionRuntime action runtime configurations}.
* Optionally, if action path with the same name already exist,
* exception will be thrown.
*/
public ActionRuntime registerActionRuntime(final ActionRuntime actionRuntime) {
final String actionPath = actionRuntime.getActionPath();
final String method = actionRuntime.getActionMethod();
log.debug("Madvoc action: " + ifNotNull(method, m -> m + " ") + actionRuntime.getActionPath() + " => " + actionRuntime.createActionString());
final RouteChunk routeChunk = routes.registerPath(method, actionPath);
if (routeChunk.value() != null) {
// existing chunk
if (detectDuplicatePathsEnabled) {
throw new MadvocException("Duplicate action path for [" + actionRuntime + "] occupied by: [" + routeChunk.value() + "]");
}
} else {
actionsCount++;
}
routeChunk.bind(actionRuntime);
// finally
runtimes.put(actionRuntime.createActionString(), actionRuntime);
// async check
if (actionRuntime.isAsync()) {
asyncMode = true;
}
return actionRuntime;
}
use of jodd.madvoc.config.ActionRuntime in project jodd by oblac.
the class ResultsManager method lookup.
/**
* Lookups for {@link jodd.madvoc.result.ActionResult action result handler}
* based on current {@link jodd.madvoc.ActionRequest action request} and action method
* result object.
*/
public ActionResult lookup(final ActionRequest actionRequest, final Object resultObject) {
ActionResult actionResultHandler = null;
// + read @RenderWith value on method
{
final ActionRuntime actionRuntime = actionRequest.getActionRuntime();
final Class<? extends ActionResult> actionResultClass = actionRuntime.getActionResult();
if (actionResultClass != null) {
actionResultHandler = lookupAndRegisterIfMissing(actionResultClass);
}
}
// + use @RenderWith value on resulting object if exist
if (actionResultHandler == null && resultObject != null) {
final RenderWith renderWith = resultObject.getClass().getAnnotation(RenderWith.class);
if (renderWith != null) {
actionResultHandler = lookupAndRegisterIfMissing(renderWith.value());
} else if (resultObject instanceof ActionResult) {
// special case - returned value is already the ActionResult
actionResultHandler = (ActionResult) resultObject;
}
}
// + use action configuration
if (actionResultHandler == null) {
final ActionRuntime actionRuntime = actionRequest.getActionRuntime();
final Class<? extends ActionResult> actionResultClass = actionRuntime.getDefaultActionResult();
if (actionResultClass != null) {
actionResultHandler = lookupAndRegisterIfMissing(actionResultClass);
}
}
if (actionResultHandler == null) {
throw new MadvocException("ActionResult not found for: " + resultObject);
}
// set action result object into action request!
actionRequest.bindActionResult(resultObject);
return actionResultHandler;
}
use of jodd.madvoc.config.ActionRuntime in project jodd by oblac.
the class ActionMethodParserTest method testClassesWithoutPackage.
@Test
void testClassesWithoutPackage() {
WebApp webapp = new WebApp();
webapp.start();
ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class);
RootPackages rootPackages = webapp.madvocContainer().lookupComponent(RootPackages.class);
rootPackages.addRootPackageOf(this.getClass());
ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst.Boo3Action#foo");
assertNotNull(cfg);
assertEquals(Boo3Action.class, cfg.getActionClass());
assertEquals("/bbb.foo", cfg.getActionPath());
cfg = parse(actionMethodParser, "fixtures.tst.Boo3Action#foo1");
assertEquals("/bbb.xxx", cfg.getActionPath());
cfg = parse(actionMethodParser, "fixtures.tst.Boo3Action#foo2");
assertEquals("/bbb.foo2.xxx", cfg.getActionPath());
cfg = parse(actionMethodParser, "fixtures.tst.Boo3Action#foo3");
assertEquals("/bbb", cfg.getActionPath());
}
use of jodd.madvoc.config.ActionRuntime in project jodd by oblac.
the class ActionMethodParserTest method testEndSlashClassName.
@Test
void testEndSlashClassName() {
WebApp webapp = new WebApp();
webapp.start();
ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class);
RootPackages rootPackages = webapp.madvocContainer().lookupComponent(RootPackages.class);
rootPackages.addRootPackageOf(this.getClass());
ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst2.ReAction#hello");
assertNotNull(cfg);
assertEquals(ReAction.class, cfg.getActionClass());
assertEquals("/re/hello", cfg.getActionPath());
cfg = parse(actionMethodParser, "fixtures.tst2.ReAction#macro");
assertNotNull(cfg);
assertEquals(ReAction.class, cfg.getActionClass());
assertEquals("/re/user/{id}/macro", cfg.getActionPath());
}
use of jodd.madvoc.config.ActionRuntime in project jodd by oblac.
the class ActionMethodParserTest method testClassesWithPackage.
@Test
void testClassesWithPackage() {
WebApp webapp = new WebApp();
webapp.start();
ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class);
RootPackages rootPackages = webapp.madvocContainer().lookupComponent(RootPackages.class);
rootPackages.addRootPackageOf(this.getClass());
ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst.Boo1Action#foo");
assertNotNull(cfg);
assertEquals(Boo1Action.class, cfg.getActionClass());
assertEquals("/fixtures/tst/boo1.foo", cfg.getActionPath());
cfg = parse(actionMethodParser, "fixtures.tst.Boo2Action#foo");
assertNotNull(cfg);
assertEquals(Boo2Action.class, cfg.getActionClass());
assertEquals("/fixtures/tst/bbb.foo", cfg.getActionPath());
cfg = parse(actionMethodParser, "fixtures.tst.Boo2Action#foo1");
assertEquals("/fixtures/tst/bbb.xxx", cfg.getActionPath());
cfg = parse(actionMethodParser, "fixtures.tst.Boo2Action#foo2");
assertEquals("/fixtures/tst/bbb.foo2.xxx", cfg.getActionPath());
cfg = parse(actionMethodParser, "fixtures.tst.Boo2Action#foo3");
assertEquals("/fixtures/tst/bbb", cfg.getActionPath());
}
Aggregations