User offline. Last seen 27 weeks 21 hours ago. Offline
Joined: 01/11/2010

I try to use the Open Calais REST API with XQuery. I have had no problems with GET requests, but if the content gets biggish the URL would be too long. So I tried POST requests like the "Calais test page" does.
Unfortunately all I get from Calais is an <Error> with an <Exception> containing the stack trace of a NullPointerException. To reproduce this go to and copy&paste the following code which does the corresponding POST request:
import module namespace rest = "";

let $content := "Hello John Doe."
let $paramsXML := '<c:params xmlns:c="">
    <c:processingDirectives c:outputFormat="Text/Simple"/></c:params>'
let $p := <rest:payload content-type="multipart/form-data">
    <rest:part name="licenseID">6vktr24npxk3z828ys5bvmv6</rest:part>
    <rest:part name="content">{fn:encode-for-uri($content)}</rest:part>
    <rest:part name="paramsXML">{fn:encode-for-uri($paramsXML)}</rest:part>
let $response := rest:post("", $p)
return $response

I also tried to specify the content type as "application/x-www-form-urlencoded" and put the argument line as a whole in the payload. But this results in a 403 response code (which I find confusing as well).
Every comment is appreciated.

Trackback URL for this post:

Login or Register to post a comment.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
User offline. Last seen 3 years 42 weeks ago. Offline
Joined: 12/15/2008

I tried the demo page as you suggested above. You are missing the contentType parameter in parameter XML. So I copied the parameter XML from our example page at

I still got the null pointer exception. Following the stack seems like the server side code is not able to parse the parameters XML properly. I am not familiar with Zorba a lot, so not sure what the alternative can be here. But it has something to do with the way it passes the parameters XML to our server i.e. encoding, escaping, etc.


User offline. Last seen 27 weeks 21 hours ago. Offline
Joined: 01/11/2010

You're right, it seems that the post function already does the encoding of the parameters, so they're encoded twice. In my example code above, just remove the fn:encode-for-uri function calls and it works (even without the contentType parameter in paramsXML).

Thanks! :-)