I have a problem. I need execute js webscript from Java webscript. I know, how do it:
req.getRuntime().getContainer().getRegistry().getWebScript("com/home/testJs/testJs.get").execute(req, res)
, but how to construct the new WebScriptRequest object? I need do it for rewrite request path. It's a really problem for me. Thank you.
Of course skuro is correct saying it is a bad idea going through the HTTP layer twice.
But in fact, executing both, a script controller and a java method is supported by Alfresco right out of the box - without ugly hacks, and without passing the entire HTTP layer twice.
You may do this:
Put your script code in the corresponding .js file.
Make sure your Java class is a subclass of
DeclarativeWebScript
, overrideexecuteImpl
and put your custom logic there.Sure, you can still argue that having two controllers is bad style. :)
In general, you should use WebScriptRequestURLImpl. Without any other detail, it's hard go any deeper.
That said, it's in general a bad idea to go through yet another HTTP call to yourself to fix your problem, it's basically an indication of poor modularization or lack of code reuse.
I'd rather move the piece of code that's common in both the JS and Java web scripts flows to be an Action, which you could invoke from both places without having to repackage the input parameters, or worse send them via HTTP.