Skip to content Skip to sidebar Skip to footer

Call Js Webscript From Java Webscript In Alfresco

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').exec

Solution 1:

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.


Solution 2:

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, override executeImpl and put your custom logic there.

Sure, you can still argue that having two controllers is bad style. :)


Post a Comment for "Call Js Webscript From Java Webscript In Alfresco"