473,734 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML-RPC "filter"

Dear all,

I'm writing an XML-RPC server which should be able to modify the
incoming request before dispatching it. In particular I wand to added
two fixed parameters to the method called: one is the client host
address, and the other is the user name provided as for Basic
Authentication (http://us**@www.bla-bla.com).

To do this, at the present I've overwritten the do_POST method of
SimpleXMLRPCReq uestHandler, including at a certain point this code:

.....
data = ''.join(L)

params, method = xmlrpclib.loads (data)
user = "unknown"
if self.headers.ha s_key('Authoriz ation'):
# handle Basic authentication
(enctype, encstr) = self.headers.ge t('Authorizatio n').split()
user, password = base64.standard _b64decode(encs tr).split(':')
params = list(params)
params.append(s elf.address_str ing())
params.append(u ser)
params = tuple(params)
data = xmlrpclib.dumps (params, methodname=meth od)

(I slightly modified it to make it more readable at mail level)

It works, but I don't really like it because it completely overwrites
the do_POST method that in the future Python releases is going to
change (I verified it). Do you know a better way to do this?

Thanks in advance.

Luigi
Sep 9 '08 #1
6 1605
Luigi wrote:
Dear all,

I'm writing an XML-RPC server which should be able to modify the
incoming request before dispatching it. In particular I wand to added
two fixed parameters to the method called: one is the client host
address, and the other is the user name provided as for Basic
Authentication (http://us**@www.bla-bla.com).

To do this, at the present I've overwritten the do_POST method of
SimpleXMLRPCReq uestHandler, including at a certain point this code:

....
data = ''.join(L)

params, method = xmlrpclib.loads (data)
user = "unknown"
if self.headers.ha s_key('Authoriz ation'):
# handle Basic authentication
(enctype, encstr) = self.headers.ge t('Authorizatio n').split()
user, password = base64.standard _b64decode(encs tr).split(':')
params = list(params)
params.append(s elf.address_str ing())
params.append(u ser)
params = tuple(params)
data = xmlrpclib.dumps (params, methodname=meth od)

(I slightly modified it to make it more readable at mail level)

It works, but I don't really like it because it completely overwrites
the do_POST method that in the future Python releases is going to
change (I verified it). Do you know a better way to do this?
I would go for a slightly different approach: make your server have a
dispatch-method that delegates the calls to the underlying actual
implementation. But *before* that happens, extract the information as
above, and either

- prepend it to the argument list

- stuff it into threadlocal variables, and only access these if needed in
your implementation.

Diez
Sep 9 '08 #2
On 9 Set, 17:55, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
I would go for a slightly different approach: make your server have a
dispatch-method that delegates the calls to the underlying actual
implementation. But *before* that happens, extract the information as
above, and either

*- prepend it to the argument list

*- stuff it into threadlocal variables, and only access these if neededin
your implementation.

Diez
Are you suggesting me to overwrite the _dispatch(self, method, params)
method of SimpleXMLRPCDis patcher? I thought to this possibility, but
it only accepts "method" and "params" as arguments, so, as far as I
know, I have no way to get the user and host address to append.

Perhaps I've misunderstood your suggestion... in that case can you
post a short example?

Thank you very much!

Luigi
Sep 10 '08 #3
On Sep 9, 8:53*am, Luigi <luigipai...@li bero.itwrote:
Dear all,

I'm writing an XML-RPC server which should be able to modify the
incoming request before dispatching it. In particular I wand to added
two fixed parameters to the method called: one is the client host
address, and the other is the user name provided as for Basic
Authentication (http://u...@www.bla-bla.com).

To do this, at the present I've overwritten the do_POST method of
SimpleXMLRPCReq uestHandler, including at a certain point this code:

....
data = ''.join(L)

params, method = xmlrpclib.loads (data)
user = "unknown"
if self.headers.ha s_key('Authoriz ation'):
* # handle Basic authentication
* (enctype, encstr) = *self.headers.g et('Authorizati on').split()
* user, password = base64.standard _b64decode(encs tr).split(':')
params = list(params)
params.append(s elf.address_str ing())
params.append(u ser)
params = tuple(params)
data = xmlrpclib.dumps (params, methodname=meth od)

(I slightly modified it to make it more readable at mail level)

It works, but I don't really like it because it completely overwrites
the do_POST method that in the future Python releases is going to
change (I verified it). Do you know a better way to do this?

Thanks in advance.

Luigi
I actually wrote a wsgi module for almost this -exact- use case
(having to prepend a user/password to the method calls). The simple
rpc server and dispatchers didn't give me enough control over the
behavior, so I had to reimplement all the logic surround the loads/
dumps calls, and eventually that just turned into the bulk of the
whole SimpleXMLRPCSer ver module. There's a lot of tight coupling in
the _dispatch method, so you'll have to override, monkey patch, or
reimplement it.
Sep 10 '08 #4
lu**********@gm ail.com schrieb:
On 9 Set, 17:55, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
>I would go for a slightly different approach: make your server have a
dispatch-method that delegates the calls to the underlying actual
implementation . But *before* that happens, extract the information as
above, and either

- prepend it to the argument list

- stuff it into threadlocal variables, and only access these if needed in
your implementation.

Diez

Are you suggesting me to overwrite the _dispatch(self, method, params)
method of SimpleXMLRPCDis patcher? I thought to this possibility, but
it only accepts "method" and "params" as arguments, so, as far as I
know, I have no way to get the user and host address to append.

Perhaps I've misunderstood your suggestion... in that case can you
post a short example?
Ah, darn. Yes, you are right of course, the information itself is not
available, as you don't have access to the request. I gotta ponder this
a bit more.

Diez
Sep 10 '08 #5
On Sep 10, 2:04*pm, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
luigi.pai...@gm ail.com schrieb:
On 9 Set, 17:55, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
I would go for a slightly different approach: make your server have a
dispatch-method that delegates the calls to the underlying actual
implementation. But *before* that happens, extract the information as
above, and either
*- prepend it to the argument list
*- stuff it into threadlocal variables, and only access these if needed in
your implementation.
Diez
Are you suggesting me to overwrite the _dispatch(self, method, params)
method of SimpleXMLRPCDis patcher? I thought to this possibility, but
it only accepts "method" and "params" as arguments, so, as far as I
know, I have no way to get the user and host address to append.
Perhaps I've misunderstood your suggestion... in that case can you
post a short example?

Ah, darn. Yes, you are right of course, the information itself is not
available, as you don't have access to the request. I gotta ponder this
a bit more.

Diez
Because he wants to insert parameters at the very start, he can
probably get away with modifying the xml directly. Just find the
position of the <params(i think thats the tag) and insert the xml
you need after it. Its pretty dirty, but would work. The wire format
isn't that complicated.
Sep 11 '08 #6
On 11 Set, 18:45, Richard Levasseur <richard...@gma il.comwrote:
Because he wants to insert parameters at the very start, he can
probably get away with modifying the xml directly. *Just find the
position of the <params(i think thats the tag) and insert the xml
you need after it. *Its pretty dirty, but would work. *The wire format
isn't that complicated.
I think this is exactly what I do... isn't it?
Sep 12 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1834
by: glin | last post by:
Hi I am trying to integrate the xmlrpc server into a class, does anyone know how to get it working? test.html: <html> <head> <title>XMLRPC Test</title> <script src="jsolait/init.js"></script> <script src="jsolait/lib/urllib.js"></script> <script src="jsolait/lib/xml.js"></script>
0
1736
by: Juan Carlos CORUÑA | last post by:
Hello all, I'm trying to create a COM Server with an embedded xmlrpc server. Here is way it must work: - The client application (programmed with a COM capable language) instantiates my COM server (programmed with python). - The COM server must have a connect interface in order to let the client application process the xmlrpc request. - After executing a "serveforever" method on the COM server it begins
6
5359
by: Michael Urman | last post by:
Hi. I'm a user of python for about 3 years now. I've written a client-server application that uses SimpleXMLRPCServer and xmlrpclib.ServerProxy to communicate. It's intended to be used by a single-person as a backend and GUI frontend. I've got it running great. Much stabler than my custom RPC I'd tried before. I've used the default support available by these classes. Thus it will run on a potentially public TCP/IP port. As the...
1
2797
by: Joxean Koret | last post by:
Hi to all! I'm having troubles to make my XMLRPC application working with non ASCII characters. Example: 1.- In one terminal run the following script: -----------XMLRPC Server-------------
1
3212
by: emielvl | last post by:
Hello, I'm developing a client/server architecture based on the XML-RPC implementation in php4. All works pretty well, except that in the response from the server there is no "Content-Length" in the header. Since the XML-RPC specification requires this header to be present in the server response, some libraries (notably: libxmlrpc++) choke on this. For clarity, here's a (simple) server (slightly altered from:...
4
8189
by: elyob | last post by:
Hi, I've got --with-xmlrpc option in my php.ini and can see on my phpinfo page. Now, how do I include this in some code? So far I've been downloading xmlrpc into a folder and just calling it from there, but if it's already installed what do I change to get this version working? Currently, I am calling ... require("../xmlrpc/lib/xmlrpc.inc"); I tried ... require("xmlrpc.inc"); ... but with no luck. Thanks
3
2841
by: Manuel | last post by:
Hello I need a xmlrpc lib for c++. I know two: xmlrpc++ and xmlrpc-c. But i don't know that it is best for me. I am developing an application in c++. I read that the xmlrpc-c lib is in C and wrap the functions to use in c++. Well, i think that it is more difficult to use than xmlrpc++ that it is made in c++. The trouble is that the xmlrpc++ is stopped from 2003 and i think that it has got a lot of bugs unresolved but it is more simple...
1
2383
by: fortepianissimo | last post by:
I have a simple xmlrpc server/client written in Python, and the client throws a list of lists to the server and gets back a list of lists. This runs without a problem. I then wrote a simple Java xmlrpc client and it calls the python server. But I can't figure out what type to cast the result (of type Object) to. The Java xmlrpc call is basically this: Object result = client.execute("MyFunction", params);
0
2751
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ext/xmlrpc/.libs/xmlrpc-epi-php.o(.text+0x359): In function `set_zval_xmlrpc_type': /php-5.2.5/ext/xmlrpc/xmlrpc-epi-php.c:1313: undefined reference to `XMLRPC_CreateValueDateTime_ISO8601'
4
3939
by: care02 | last post by:
I have implemented a simple Python XMLRPC server and need to call it from a C/C++ client. What is the simplest way to do this? I need to pass numerical arrays from C/C++ to Python. Yours, Carl
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.