On Mon, Jan 2, 2012 at 5:26 PM, Bruno Gruel <[email protected]> wrote:
> On Mon, 02 Jan 2012 18:15:59 +0100, Bruno Gruel wrote:
>> On Mon, 2 Jan 2012 11:03:46 -0600, Jeffrey Van Voorst wrote:
>>>>From the mongrel2 website: mongrel2 supports "HTTP 1.1 and 1.0,
>>>> Flash
>>> JSON Sockets, Flash XML Sockets".
>>>
>>> Read the mongrel2 documentation.
>>> Read the mongrel2 documentation.
>>> Read the mongrel2 chapter 5 to determine which communication
>>> patterns
>>> you want.
>>>
>>> It is my opinion that if your end goal is a pyjamas application that
>>> you use XMLHTTPRequest as browsers can use SSL for XHR. In other
>>> words, get jsonrpclib working with mongrel2 and your server portion
>>> of
>>> the application. Then do the small amount of code needed to connect
>>> your pyjamas app to your server vi jsonrpc over XHR.
>>>
>>> --Jeff
>
> Hello,
>
>
> First, thank's to try help me.
>
> I read your previous reply. What i want to do ?
> In my webapp (network probe or thinkclint mabager) i use this kind off
> class to retreive some data from the server (mysql query, snmp query
> etc..). And my goal is to do the same things with mongrel2.
>
> class AuthServicePython(JSONProxy):
> def __init__(self):
> JSONProxy.__init__(self, "services/toto.py", ["auth"])
>
> OK i will re-read and re-read the mongrel2 doc and read the mongrel2
> chapter 5.
sod the documentation, go for the source code :) (sorry, jeffrey,
that's my way hehe)
rright.
examples/python/mongrel2/request.py looks like what you need (for the
first part).
class Request(object):
def __init__(self, sender, conn_id, path, headers, body):
self.sender = sender
self.path = path
self.conn_id = conn_id
self.headers = headers
self.body = body
if self.headers['METHOD'] == 'JSON':
self.data = json.loads(body)
else:
self.data = {}
ok so there you go, a request object once created will have self.body
as the data: that's what you pass in to the jsonrpc.py code, as line
no 1.
yep, as you can see in handler.py, a request object is returned from
the function "recv". you do NOT want the "recv_json" function.
then, you want the reply_http function, with the body as the
response... from the jsonrpc.py code, and you're done!
now, exactly how you glue those together is unclear - mongrel2 is
looking pretty obscure, even to me! :)
hmmmm...
http://sheddingbikes.com/posts/1279007133.html
ok, that looks obvios.
What It Looks Like
Take a look at your most basic HTTP handler:
from mongrel2 import handler
import json
sender_id = "82209006-86FF-4982-B5EA-D1E29E55D481"
conn = handler.Connection(sender_id, "tcp://127.0.0.1:9997",
"tcp://127.0.0.1:9996")
while True:
print "WAITING FOR REQUEST"
req = conn.recv()
response = "<pre>\nSENDER: %r\nIDENT:%r\nPATH:
%r\nHEADERS:%r\nBODY:%r</pre>" % (
req.sender, req.conn_id, req.path,
json.dumps(req.headers), req.body)
print response
conn.reply_http(req, response)
so, um... that would be "from pyjs.blah import jsonrpc"
then... response = self.process(conn.recv())
err... that's it :) actually, one line modification, not even 2 or 3.
ok i'll knock something together, i'm curious to see what happens.
l.