Run Nevow and XMLRPC on a single port?

Hello, Is it possible to run a nevow site and and serve XMLRPC (or SOAP) requests on a single port? I've tried to make it work some time ago, but to no avail. Anyone? - Remi -

Remi Cool wrote:
Is it possible to run a nevow site and and serve XMLRPC (or SOAP) requests on a single port? I've tried to make it work some time ago, but to no avail.
I've attached an example extracted (with names changed to protect the guilty) from my app's tac file, which gives one possible approach ... in my case I've only set up xmlrpc and a static web site, but I think adding a Nevow service would not be much different in principle. Gracefully handling a web client wandering into the xmlrpc area or vice versa is left as an exercise to the reader, but I don't expect it would be all that difficult. There may be a more elegant way to do this -- commentary from the twisted gurus is welcome (as always :). Steve

Stephen Waterbury wrote:
Remi Cool wrote:
Is it possible to run a nevow site and and serve XMLRPC (or SOAP) requests on a single port? I've tried to make it work some time ago, but to no avail.
I've attached an example extracted (with names changed to protect the guilty) from my app's tac file, which gives one possible approach ...
Hmm ... now that I've experimented with NevowSite, I see that my post was useless (I also notice your post of the same question back in May apparently went unanswered). Apologies for the wasted bandwidth. I'm sure it's possible to do but probably won't be pretty and is best avoided if possible -- separate ports, better! Steve

Remi Cool wrote:
Hello,
Is it possible to run a nevow site and and serve XMLRPC (or SOAP) requests on a single port? I've tried to make it work some time ago, but to no avail.
I believe you can do this: class Xrpc(xmlrpc.XMLRPC): def xmlrpc_echo(self, arg): return arg xrpc = Xrpc() page = NevowRootPage() page.putChild('RPC2', xrpc)

On 12/14/06, Phil Mayers <p.mayers@imperial.ac.uk> wrote:
Remi Cool wrote:
Hello,
Is it possible to run a nevow site and and serve XMLRPC (or SOAP) requests on a single port? I've tried to make it work some time ago, but to no avail.
I believe you can do this:
class Xrpc(xmlrpc.XMLRPC): def xmlrpc_echo(self, arg): return arg
xrpc = Xrpc() page = NevowRootPage() page.putChild('RPC2', xrpc)
just make sure xmlrpc resource isn't behind nevow.guard cu, Maio

Marian Schubert wrote:
I believe you can do this:
class Xrpc(xmlrpc.XMLRPC): def xmlrpc_echo(self, arg): return arg
xrpc = Xrpc() page = NevowRootPage() page.putChild('RPC2', xrpc)
just make sure xmlrpc resource isn't behind nevow.guard
It's a shame you can't persuade guard by URL arguments to not try an HTTP redirect to HTML login, but issue an HTTP auth challenge. Bizarrely nevow guard will accept http auth credentials if they're given, but I don't know of a single HTTP client that will submit them without getting the 401 first.

Phil Mayers wrote:
Marian Schubert wrote:
I believe you can do this:
class Xrpc(xmlrpc.XMLRPC): def xmlrpc_echo(self, arg): return arg
xrpc = Xrpc() page = NevowRootPage() page.putChild('RPC2', xrpc)
just make sure xmlrpc resource isn't behind nevow.guard
It's a shame you can't persuade guard by URL arguments to not try an HTTP redirect to HTML login, but issue an HTTP auth challenge.
Bizarrely nevow guard will accept http auth credentials if they're given, but I don't know of a single HTTP client that will submit them without getting the 401 first.
_______________________________________________
You can solve this by modifying locateChild in your root resource and returning a 401 when needed. if not loggedin: if childSegments[0] == "RPC2": return AuthReq(), () return login.LoginPage(), () class AuthReq: """A simple 401 (Auth required) page. """ __implements__ = inevow.IResource, notAuth = "<html><head><title>Authentication required</title><head><body>This resource is protected.</body></html>" original = None def locateChild(self, ctx, segments): return None, () def renderHTTP(self, ctx): request = inevow.IRequest(ctx) request.setResponseCode(401) request.setHeader('WWW-Authenticate', 'Basic realm="rpc@yourhost.com"') return self.notAuth def __nonzero__(self): return False Hope this helps. /Simon

On Dec 14, 2006, at 3:45 AM, Phil Mayers wrote:
Marian Schubert wrote:
I believe you can do this:
class Xrpc(xmlrpc.XMLRPC): def xmlrpc_echo(self, arg): return arg
xrpc = Xrpc() page = NevowRootPage() page.putChild('RPC2', xrpc) just make sure xmlrpc resource isn't behind nevow.guard
It's a shame you can't persuade guard by URL arguments to not try an HTTP redirect to HTML login, but issue an HTTP auth challenge.
Bizarrely nevow guard will accept http auth credentials if they're given, but I don't know of a single HTTP client that will submit them without getting the 401 first.
Most programatic clients can be told to submit basic auth credentials without a 401, but digest and negotiate are much harder. It doesn't matter though, because nevow.guard only supports basic auth afaik. I seem to recall that xmlrpclib supports http://user:pass@host/ syntax. twisted.web.xmlrpc.Proxy also supports this, as well as explicit keyword arguments for user and password. - David Reid http://dreid.org/

Phil Mayers wrote:
Remi Cool wrote:
Hello,
Is it possible to run a nevow site and and serve XMLRPC (or SOAP) requests on a single port? I've tried to make it work some time ago, but to no avail.
I believe you can do this:
class Xrpc(xmlrpc.XMLRPC): def xmlrpc_echo(self, arg): return arg
xrpc = Xrpc() page = NevowRootPage() page.putChild('RPC2', xrpc)
That's what I had in my suggestion. It does give you an xml-rpc service, sure, but the problem is that NevowSite tries to render every request it gets, so you'll need to specify a renderer for the xml-rpc resources that will pass them through unaltered. But, as I mentioned, you probably also want to do some checking to prevent browsers from getting xml-rpc gibberish and xml-rpc clients from getting rendered xhtml ... possibly by giving them different auth realms. Steve

Phil Mayers wrote:
Remi Cool wrote:
Hello,
Is it possible to run a nevow site and and serve XMLRPC (or SOAP) requests on a single port? I've tried to make it work some time ago, but to no avail.
I believe you can do this:
class Xrpc(xmlrpc.XMLRPC): def xmlrpc_echo(self, arg): return arg
xrpc = Xrpc() page = NevowRootPage() page.putChild('RPC2', xrpc)
Thanks for all the reactions, I will put the suggested solution to the test. Any info on guard is also very useful :) I only have to deal with a browser based upon gecko (xulrunner application) ... so it's not for general internet use. It is important that the overhead is kept to a minimum though. Remi
participants (7)
-
David Reid
-
Marian Schubert
-
Phil Mayers
-
Remi Cool
-
Simon Hedberg
-
Stephen Waterbury
-
Stephen Waterbury