cancel
Showing results for 
Search instead for 
Did you mean: 

Webscript not running with post.json.js

rcrittendon
Champ in-the-making
Champ in-the-making
I am running a small example in Alfresco 3.2.  The issue I am running into is that I cannot call the script if the javascript file ends in post.json.js, but can if it ends in post.js

If I call http://localhost:8080/alfresco/service/hmm/testIssue?alf_method=post with the javascript file ending in post.json.js I get the following sort of error.
'Expression results is undefined on line 2, column 18 in testIssue\/test-issue.post.json.ftl.'

Is there something I should add to get that.  It looked like it should be possible when reading http://wiki.alfresco.com/wiki/Web_Scripts#Request_Processing.

test-issue.post.desc.xml
<webscript>
  <shortname>Test Webscript</shortname>
  <description>Test webscript for result</description>
  <url>/hmm/testIssue</url>
  <format default="json"/>
  <authentication>user</authentication>
</webscript>

test-issue.post.js (what I wanted as test-issue.post.json.js)

function main(){
   model.results = "hello";
}
main();

test-issue.post.json.ftl

{
    "results":"${results}"
             
}
4 REPLIES 4

mikeh
Star Contributor
Star Contributor
When your client POSTs to the webscript, make sure the Content-Type header is set to "application/json" and the body contains a valid JSON string.

Thanks,
Mike

rcrittendon
Champ in-the-making
Champ in-the-making
Hi Mike,

It looks like "application/json" is being returned.

The following is my TamperData information on that request.
Note: This is when I use the file test-issue.post.js.  It does not work for test-issue.post.json.js.

18:25:02.439[22ms][total 22ms] Status: 200[OK]
GET http://localhost:8080/alfresco/service/hmm/testIssue?alf_method=post Load Flags[VALIDATE_ALWAYS LOAD_DOCUMENT_URI  LOAD_INITIAL_DOCUMENT_URI  ] Content Size[41] Mime Type[application/json]
   Request Headers:
      Host[localhost:8080]
      User-Agent[Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6]
      Accept[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]
      Accept-Language[en-us,en;q=0.5]
      Accept-Encoding[gzip,deflate]
      Accept-Charset[ISO-8859-1,utf-8;q=0.7,*;q=0.7]
      Keep-Alive[115]
      Connection[keep-alive]
      Authorization[Basic YWRtaW46YWRtaW4=]
      Cache-Control[max-age=0]
   Response Headers:
      Server[Apache-Coyote/1.1]
      Cache-Control[no-cache]
      Pragma[no-cache]
      Content-Type[application/json;charset=UTF-8]
      Content-Length[41]
      Date[Fri, 19 Mar 2010 22:25:02 GMT]

rcrittendon
Champ in-the-making
Champ in-the-making
Hi,

I was wondering if anyone else has been able to reproduce the issue in this thread.

I could replicate it on two instances of Alfresco 3.2, on different machines.

alch3mi5t
Champ in-the-making
Champ in-the-making

Quite old, but since I came across this post through a google search it might still be relevant to somebody:

You need to paste this into your json.ftl file:

<#escape x as jsonUtils.encodeJSONString(x)>
{ "results": "${results}" }
</#escape>