cancel
Showing results for 
Search instead for 
Did you mean: 

How to get content coming back from a repository javaback webscript in share JS?

vince20151
Champ in-the-making
Champ in-the-making
I'm working on a very simple exercise to create a Java webscript in Alfresco. It extends DeclarativeWebScript and returns a simple string. I can call this webscript on the URL and it works.
On the share side, I have a JS file that calls the web script via remote.connect.
This is where I am stuck. How do I get the content from the remote call and put it in the model. It seems to fail at the eval statement and my free marker renders this string org.mozilla.javascript.Undefined@12fa845 instead of the string returned from remote.
Any advice is appreciated.

Here is the JS on the share side
function main() {
  var connector = remote.connect("alfresco");
  var result = connector.get("/alfresco/service/aa/simpleremote");
 
  if (result.status == status.STATUS_OK)
  {
    data = eval("(" + result.response + ")");
  }
  model.html = result["html"];
}
main();


Here is the Java code on the repository side
public class SimpleWebScriptModel extends DeclarativeWebScript {
   protected Map<String, Object> executeImpl(WebScriptRequest req,
          Status status, Cache cache)   {
      Map<String, Object> model = new HashMap<String, Object>();
      String myString = "Hello World";
      model.put("html", myString);
      return model;
   }
}
2 REPLIES 2

vince20151
Champ in-the-making
Champ in-the-making
Found out that the response code from remote call is 404 404 Description:    Requested resource is not available. So that's why the tag shows as undefined.
What makes the URL not found when calling inside share versus explicit in the browser? I had the authentication for the remote script as user and changed to to guest and it still couldn't find.

Just realized that the URL should not include /alfresco/service part as it is implied. After I removed this, it is working now.
A good learning experience and somehow the thought process becomes a little clearer once you post your question. It helps sometimes to talk out loud I guess.