hessianpy-general Mailing List for HessianPy
Brought to you by:
batyi
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: Petr G. <pet...@gm...> - 2006-04-09 16:11:06
|
From: "Bernd Stolle" To: ba...@us... Date: Sat, 11 Mar 2006 05:27:50 -0800 Subject: Extensions to HessianPy Message body follows: Hi, I'm very interested in your project HessianPy. I intend to use it in a project I'm currently working on. However, for that project I need support for https and BasicAuthentication. So I made a few modifications to the client and introduced an abstraction layer for a few transports (currently only http and https). I would like to ask if you are interested in integrating these changes. Let me know, and I'll send you the source. Greetings, Bernd ---------- Forwarded message ---------- From: Petr Gladkikh To: Bernd Stolle <th...@us...> Date: Mon, 13 Mar 2006 11:53:16 +0600 Subject: Re: Extensions to HessianPy Hello. Bernd Stolle wrote: > I would like to ask if you are interested in integrating > these changes. Let me know, and I'll send you the source. > Of course it would be interesting. I thought about adding HTTPS and authentication but stopped with it for now as my project (at my job) needs many other things to do before I need this protocol. It would be nice if you send me a patch against latest revision from Sourceforge's CVS repository. If that's too inconvenient to you just sources suffice. -- Petr ---------- Forwarded message ---------- From: Bernd Stolle To: Petr Gladkikh Date: Mon, 13 Mar 2006 19:11:10 +0100 Subject: Re: Extensions to HessianPy Petr Gladkikh wrote: > Hello. > > Bernd Stolle wrote: >> I would like to ask if you are interested in integrating >> these changes. Let me know, and I'll send you the source. >> > Of course it would be interesting. I thought about adding HTTPS and > authentication but stopped with it for now as my project (at my job) > needs many other things to do before I need this protocol. > > It would be nice if you send me a patch against latest revision from > Sourceforge's CVS repository. If that's too inconvenient to you just > sources suffice. > > -- > Petr > Since the CVS checkout failed and the diff against the latest release did not work properly, I'm sending you the source files. advclient.py - the modified client, uses the transports transports.py - HTTP and HTTPS transports with BasicAuthentication I originally based the HTTPS version on tlslite, but I think httplib.HTTPSConnection is a better approach to this. Greetings, Bernd -- "Poor man... he was like an employee to me." -- The police commisioner on "Sledge Hammer" laments the death of his bodyguard # # Hessian protocol implementation # This file contains pluggable transport mechanisms. # # Protocol specification can be found here: # http://www.caucho.com/resin-3.0/protocols/hessian-1.0-spec.xtp # # Copyright 2006 Bernd Stolle (thebee at sourceforge net) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """ Transports for Hessian. Content: * HessianTransport - abstract base class * HTTPTransport - talk hessian over simple unencrypted HTTP, support for BasicAuthentication """ import base64 import httplib from StringIO import StringIO __version__ = "0.5.0" __revision__ = "$Rev$" AUTH_BASIC = "basic" def getTransportForProtocol (protocol): """ returns the appropriate transport for a protocol identifier """ return { "http": HTTPTransport, "https": HTTPSTransport, }[protocol] class TransportError(Exception): """ Generic Exception for Transports """ pass class HessianTransport: """ Base class for all transports use can use to talk to a Hessian. """ def __init__(self, host = "", port = 0, path = ""): # initialization goes here self._host = host self._port = port self._path = path def authenticate(self, credentials): """ Invoke the authentication mechanism of the transport layer if supported. """ pass def request(self, outstream): """ Transport a request to the Hessian """ pass class HTTPTransport(HessianTransport): """ Transport the Hessian protocol via plain old unsecure HTTP """ def __init__(self, host = "localhost", port = 0, path = "/", use_ssl = False): if port == 0: port = { True: httplib.HTTPS_PORT, False: httplib.HTTP_PORT, }[use_ssl] HessianTransport.__init__(self, host, port, path) self._connection = { True: httplib.HTTPSConnection, False: httplib.HTTPConnection, }[use_ssl](self._host, self._port) self._headers = {"Host" : self._host, "User-Agent" : "HessianPy/%s" % __version__} def authenticate(self, credentials): """ Authenticate to the server using BasicAuthentication. Actully just stores the values, since real authentication is performed on every single request. @param credentials tuple consisting of username and password @returns True, since there is no way of telling, whether the credentials are correct """ # store username and password for later use self._headers["Authorization"] = "Basic %s" % base64.encodestring( "%s:%s" % (credentials["username"], credentials["password"])).rstrip() return True def request(self, outstream): """ Send the request via HTTP """ # pass it to the server self._connection.request("POST", self._path, outstream.getvalue(), self._headers) response = self._connection.getresponse() if not response.status == httplib.OK: # tbd: analyze error code and take appropriate actions raise Exception("HTTP Error %d: %s" % (response.status, response.reason)) result = StringIO(response.read()) response.close() return result class HTTPSTransport(HTTPTransport): """ Transport the Hessian protocol via SSL encrypted HTTP """ def __init__(self, host = "localhost", port = 0, path = "/"): HTTPTransport.__init__(self, host, port, path, True) # # Hessian protocol implementation # This file contains an advanced client proxy code. # It uses a pluggable transport mechanism. # # Protocol specification can be found here: # http://www.caucho.com/resin-3.0/protocols/hessian-1.0-spec.xtp # # Copyright 2005, 2006 Petr Gladkikh (batyi at sourceforge net) # Copyright 2006 Bernd Stolle (thebee at sourceforge net) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import hessian import transports import urlparse from StringIO import StringIO __version__ = "0.5.0" def split_host_and_port(host_and_port): result = host_and_port.split(":", 1) if len(result) == 2: return (result[0], result[1]) else: # use default port here until someone comes up with a better idea return (result[0], "80") class Method: "Encapsulates the method to be called" def __init__(self, invoker, method): self.invoker = invoker self.method = method def __call__(self, *args): return self.invoker(self.method, args) class HessianProxy: """ A Hessian Proxy Class Supports all mechanisms defined in transports.py """ typename = "advclient.HessianProxy" def __init__(self, url, authdata = {"type": transports.AUTH_BASIC, "username": "", "password": ""}): url_tuple = urlparse.urlparse(url) protocol = url_tuple[0] host_with_port = url_tuple[1] path = "%s?%s" % (url_tuple[2], url_tuple[4]) host, port = split_host_and_port(host_with_port) self._authdata = authdata transport_class = transports.getTransportForProtocol(protocol) self._transport = transport_class(host, port, path) self._transport.authenticate(authdata) def __invoke(self, method, params): request = StringIO() hessian.writeObject(hessian.WriteContext(request), (method, [], params), hessian.Call()) response = self._transport.request(request) ctx = hessian.ParseContext(response) (headers, status, value) = hessian.Reply().read(ctx, ctx.read(1)) if not status: # value is a Hessian error description raise Exception(value) return value def __getattr__(self, name): # encapsulate the method call return Method(self.__invoke, name) @staticmethod def deref(object): "Replace hessian.RemoteReference with live proxies" if hasattr(object, "typename"): if object.typename == "hessian.RemoteReference": return HessianProxy(object.url, object._authdata) else: return object @staticmethod def drain(object): "Replace Hessian proxies with hessian.RemoteReference" if hasattr(object, "typename") and object.typename == "advclient.HessianProxy": return hessian.RemoteReference(object.url) else: return object ---------- Forwarded message ---------- From: Petr Gladkikh To: Bernd Stolle Date: Mon, 20 Mar 2006 12:22:02 +0600 Subject: Re: Extensions to HessianPy Hello. I have replaced original client.py with your version and fixed it so existing tests pass. It is already in CVS. I am thinking about having some at least dumb tests for new functionality before releasing it. Do you have any ideas on that? BTW I think it would be useful sending this conversation to mailing list (although I haven't used it yet) because it is archived and probably would be useful for someone who wants to find additional information. -- Petr ---------- Forwarded message ---------- From: Bernd Stolle To: Petr Gladkikh Date: Sat, 01 Apr 2006 14:39:33 +0200 Subject: Re: Extensions to HessianPy Petr Gladkikh wrote: > Hello. > > I have replaced original client.py with your version and fixed it so > existing tests pass. It is already in CVS. I am thinking about having > some at least dumb tests for new functionality before releasing it. Do > you have any ideas on that? Well, the only test i have made so far, is to try and connect to the luntbuild[1] remote interface and this worked. If i find some time in the next days, i'll might be able to extend the transport idea to the server too. > > BTW I think it would be useful sending this conversation to mailing list > (although I haven't used it yet) because it is archived and probably > would be useful for someone who wants to find additional information. Sure, makes sense. But you'll have to create a mailinglist for that project first ;-) Greetings, Bernd [1] http://luntbuild.javaforge.com/remote-api/samples/index.html -- Men take only their needs into consideration -- never their abilities. -- Napoleon Bonaparte |