How to invoke a Java class from WebScripts
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2009 07:57 AM
Hi All,
I have a business requirement where I need to call a Java Class from a Webscript.
Please can anyone help me how I can call a Java class from webscripts or link which can help me to call the Java class from webscripts.
Thanks & Regards,
Anwar
I have a business requirement where I need to call a Java Class from a Webscript.
Please can anyone help me how I can call a Java class from webscripts or link which can help me to call the Java class from webscripts.
Thanks & Regards,
Anwar
Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2009 08:20 AM
Look at script-services-context.xml which is where you define which classes are available to the script API.
Basically what you do is give your class a name which is then available in the scripting environment.
Basically what you do is give your class a name which is then available in the scripting environment.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2009 08:31 AM
Hi Morgers,
Thanks for the quick reply.
I have gone through the 'script-services-context.xml' but was not able to exactly pickup exactly how it can be done.
If possible can you please provide me the sample code which will adress my issue.
Thanks & Regards,
Anwar
Thanks for the quick reply.
I have gone through the 'script-services-context.xml' but was not able to exactly pickup exactly how it can be done.
If possible can you please provide me the sample code which will adress my issue.
Thanks & Regards,
Anwar

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2009 11:29 PM
Your java class has to be in the classpath. I put mine in WEB-INF/classes/org/alfresco/sample, with the appropriate package name(org.alfresco.sample). You need a compiled .class in there, not a .java.
Then in the script-services-context.xml file, you add in a new bean of your new class, and call it what you want:
Depending what your java class will do, you might also want to inject some properties, such as:
In your web script, you'll be able to call customSearch.blah(…), much the same as you call logger.log(….).
Then in the script-services-context.xml file, you add in a new bean of your new class, and call it what you want:
<bean id="searchCustomScript" parent="baseJavaScriptExtension" class="org.alfresco.sample.CustomSearch"> <property name="extensionName"> <value>customSearch</value> </property> </bean>
Depending what your java class will do, you might also want to inject some properties, such as:
<property name="serviceRegistry"> <ref bean="ServiceRegistry"/> </property> <property name="storeUrl"> <value>${spaces.store}</value> </property>
In your web script, you'll be able to call customSearch.blah(…), much the same as you call logger.log(….).
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2009 02:58 AM
Hei Anwar, a big point for Tara please
(besides - I never checked, is this mentioned in the Wiki already, Tara, or can you add it ?)
Norgan

(besides - I never checked, is this mentioned in the Wiki already, Tara, or can you add it ?)
Norgan

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2009 01:05 PM
With Cocoon which used, and still uses, a js rhino implementation (the same as Alfresco I think), it was possible to call java class directly from js code, with a special syntax like noted in this html page:
* http://cocoon.apache.org/2.1/userdocs/flow/java.html
Could it be possible to use such a mechanism?
JC
* http://cocoon.apache.org/2.1/userdocs/flow/java.html
Could it be possible to use such a mechanism?
JC
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2010 11:41 AM
With Cocoon which used, and still uses, a js rhino implementation (the same as Alfresco I think), it was possible to call java class directly from js code..JSScriptProcessor disables this behavior :
… // remove security issue related objects - this ensures the script may not access // unsecure java.* libraries or import any other classes for direct access - only // the configured root host objects will be available to the script writer this.secureScope.delete("Packages"); this.secureScope.delete("getClass"); this.secureScope.delete("java");…
bad luck JCK.Tara, do you have some code example?
(org.alfresco.sample.CustomSearch)
I'm fighting with spring-surf M3, the parent="baseJavaScriptExtension" has been changed by "baseScriptExtension" in spring-surf-script-services-context.xml
but I can't find any implementation example.
The only way I found is override "webscripts.abstractcontainer" bean, but i prefer extend than override.
Any suggestions?
Thanks.
