Friends,

I have been trying to use REST on pyjamas 0.7 and 0.8a without success.
The following pyjamas code always get empty responses, despite calls from
curl and web browsers get the right responses.

To have the simplest test server I used restlite (
http://code.google.com/p/restlite/ ):

=> svn checkout http://restlite.googlecode.com/svn/trunk/ restlite-read-only
=> cd restlite-read-only
=> python example.py

The server is now running and the server log will be shown in this terminal
window.

Opening another terminal to use curl, we can see the right responses:

=> curl -H "Accept: application/json" http://localhost:8000

We get a 404 not found and a help text.

=> curl -H "Accept: application/json" http://localhost:8000/files

we get a 202 Accept code and a list of files.

So I've tried the following pyjamas code:

# This code is derived from
http://groups.google.com/group/pyjamas-dev/browse_thread/thread/f8494b11267092d0/f7f5ed7a81c86c8e?lnk=gst&q=rest#f7f5ed7a81c86c8e
from pyjamas import Window
from pyjamas.HTTPRequest import HTTPRequest
from pyjamas.JSONParser import JSONParser
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.Label import Label

class RESTClient(VerticalPanel):
    def __init__(self):
        VerticalPanel.__init__(self)
        self.label = Label()
        self.add(self.label)
        self.log("REST Client")
        HTTPRequest().asyncGet(url = "http://localhost:8000/files
",handler=self,returnxml=False)

    def onCompletion(self, text):
        self.log("onCompletion text='" + str(text) + "'")
        try:
            ar = JSONParser().decode(text)
        except:
            Window.alert("JSONParser decode Error")
        self.log(" Decoded text:'" + str(ar) + "'")

    def onError(self, text, code):
        self.label.setText(text)

    def onTimeout(self, text):
        self.label.setText(text)

    def log(self, txt):
        self.label.setText(self.label.getText() + txt + " | ")

if __name__ == '__main__':
    RootPanel().add(RESTClient())

The result is:
        REST Client | onCompletion text='' | Decoded text:'False' |

The text that comes in onCompletion is empty. What am I doing wrong?

Thanks,
Marcio

Reply via email to