Call js webscript from Java webscript in Alfresco

不羁的心 提交于 2019-12-25 05:29:31

问题


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.


回答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.




回答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. :)



来源:https://stackoverflow.com/questions/10109901/call-js-webscript-from-java-webscript-in-alfresco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!