AnsweredAssumed Answered

Calling an external web service from an Alfresco Web Script

Question asked by nmcminn on Aug 3, 2009
Latest reply on Oct 12, 2010 by dc_noze
Greetings all,

I am currently working on a project that will be made MUCH easier if I can figure out a way to call a REST web service from a web script in Alfresco.  It is my understanding that Alfresco web scripts are run in Rhino.  Rhino supports a few built in functions, such as readUrl, that would be ideal for my purposes.  I'm a bit new to running JavaScript in the Rhino environment, so I may be missing something obvious.

When I run my script via the Rhino console, it works as expected.  However, when I try to execute the same script in the Alfresco environment, I get the following:

org.mozilla.javascript.EcmaError - ReferenceError: "readUrl" is not defined. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts/blah/blah/blah#linenumber)

With this failing, I went for the next obvious line of attack: using Rhino to load the package and using the Java URL object to hit my service.  This too was a no-go, as the importPackage provided by Rhino led to the same ReferenceError shown above.  A little digging in the forums turned up this thread:

The thread referenced above clearly shows why I couldn't load any Java packages/classes into my web scripts, this functionality is disabled for (very valid) security purposes.  However, the original poster's question, how to hit an external web service from a web script, was never really addressed.

So, my question:  What is the best way to hit a simple external RESTful web service from an Alfresco web script?  I only need support for GET operations, nothing fancy.