Re: [Zope] Re: Sending XML straight down to a zope
Jonathan wrote: As an alternative strategy, how about: i) set up a url just for this problem user ii) us apache rewrite to redirect to a non-zope cgi script iii) use the cgi script to 'fix' the xml iv) do a redirect with the fixed xml to a 'zope' url Being all Nu Skool about this, I wonder if there's a wsgi thingy that could help here? Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] Re: Sending XML straight down to a zope
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dieter Maurer wrote: > Chris Withers wrote at 2006-10-12 08:35 +0100: >> Peter Bengtsson wrote: >>> xml_content = open('validxmlfile.xml').read() >>> http = httplib.HTTP("localhost", 8080) >>> http.putrequest("POST", "/uploadExpenseXML") >> That's not really a valid transaction... > > Why not? > > > The real problem is that Zope wrongfully assumes that each > "POST" with content type "text/xml" is an XML-RPC request. > > That's wrong at least since XML is more widely used on the browser > side (e.g. XForms). I think XForms uses PUT to save the model back to the server, rather than POST. WRT my proposed earlier solution: Adding a custom server type does not necessarily require deploying a hacked version of ZPublisher: it is possible to register new server types in Zope2 products (e.g., the original ClockServer product). Tres. - -- === Tres Seaver +1 202-558-7113 [EMAIL PROTECTED] Palladion Software "Excellence by Design"http://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFLqzA+gerLs4ltQ4RAs5QAJ9O4YHNOS9jAqIgD7Mv+4tdRbj35ACdE2Zk f6XAABi4VRlZWq4OSDCCuoo= =NxlO -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Re: Sending XML straight down to a zope
- Original Message - From: "Jonathan" <[EMAIL PROTECTED]> To: "Peter Bengtsson" <[EMAIL PROTECTED]> Cc: Sent: Thursday, October 12, 2006 1:21 PM Subject: Re: [Zope] Re: Sending XML straight down to a zope - Original Message - From: "Peter Bengtsson" <[EMAIL PROTECTED]> To: "Tres Seaver" <[EMAIL PROTECTED]> Cc: Sent: Thursday, October 12, 2006 1:09 PM Subject: Re: [Zope] Re: Sending XML straight down to a zope Tres Seaver wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Peter Bengtsson wrote: I'm trying to send an XML straight into Zope without specifying it as a parameter and with a Content-Length. It seems that Zope's mapply function or whatever it's called digests the raw http body and tries to turn it into parameters? Here's the code on the Zope server (uploadExpenseXML()): def uploadExpenseXML(self): return str(self.REQUEST.form.keys()) Here's the dummy code that sends the XML into my Zope: xml_content = open('validxmlfile.xml').read() http = httplib.HTTP("localhost", 8080) http.putrequest("POST", "/uploadExpenseXML") http.putheader("User-Agent", "Simple") http.putheader("Host", "localhost") http.putheader("Content-Length", "%d" % len(xml_content)) http.endheaders() http.send(xml_content) reply, message, headers = http.getreply() print http.getfile().read() The result I get is: ['\n Obviously, one solution would be to ask the XML sending company to not post it like this but instead post it by parameter which I know will work. But, what if I can't change their minds? PS. When faced with the same problem a long time ago I ended up writing a mod_python app running one a different port that converted the http post from mod_python into a parameter based http post. I don't want to have to do that again. Stock Zope can only handle POST request with XML payloads if they conform to the XMLRPC spec: they must have the 'Content-type' header of 'text/xml', and the document must be encoded as an xmlrpc request. If you can get the vendor to use a PUT request instead of a POST, you could process the result inside a custom object'c 'PUT' method. Otherwise, you are going to need to create a custom derivative of ZPublisher.HTTPRequest, and override its 'processInputs' to handle the vendor's non-standard dump. You could make that server listen on a different port, for instance (I'm guessing you can tell them what URL to POST to, right?) Cool. Thanks for the suggestion. I've tried to make them change the way they post it to me and if that's not possible I'll consider your advice about either PUT or digging into ZPublisher which I was hoping not to have to do. As an alternative strategy, how about: i) set up a url just for this problem user ii) us apache rewrite to redirect to a non-zope cgi script iii) use the cgi script to 'fix' the xml iv) do a redirect with the fixed xml to a 'zope' url Sorry, 'redirect' is the wrong terminology, you would have to do an RPC call or use something like wget, urllib, etc to feed the new xml data to your zope app, and then return the response (or a response) to the originator. Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Re: Sending XML straight down to a zope
- Original Message - From: "Peter Bengtsson" <[EMAIL PROTECTED]> To: "Tres Seaver" <[EMAIL PROTECTED]> Cc: Sent: Thursday, October 12, 2006 1:09 PM Subject: Re: [Zope] Re: Sending XML straight down to a zope Tres Seaver wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Peter Bengtsson wrote: I'm trying to send an XML straight into Zope without specifying it as a parameter and with a Content-Length. It seems that Zope's mapply function or whatever it's called digests the raw http body and tries to turn it into parameters? Here's the code on the Zope server (uploadExpenseXML()): def uploadExpenseXML(self): return str(self.REQUEST.form.keys()) Here's the dummy code that sends the XML into my Zope: xml_content = open('validxmlfile.xml').read() http = httplib.HTTP("localhost", 8080) http.putrequest("POST", "/uploadExpenseXML") http.putheader("User-Agent", "Simple") http.putheader("Host", "localhost") http.putheader("Content-Length", "%d" % len(xml_content)) http.endheaders() http.send(xml_content) reply, message, headers = http.getreply() print http.getfile().read() The result I get is: ['\n Obviously, one solution would be to ask the XML sending company to not post it like this but instead post it by parameter which I know will work. But, what if I can't change their minds? PS. When faced with the same problem a long time ago I ended up writing a mod_python app running one a different port that converted the http post from mod_python into a parameter based http post. I don't want to have to do that again. Stock Zope can only handle POST request with XML payloads if they conform to the XMLRPC spec: they must have the 'Content-type' header of 'text/xml', and the document must be encoded as an xmlrpc request. If you can get the vendor to use a PUT request instead of a POST, you could process the result inside a custom object'c 'PUT' method. Otherwise, you are going to need to create a custom derivative of ZPublisher.HTTPRequest, and override its 'processInputs' to handle the vendor's non-standard dump. You could make that server listen on a different port, for instance (I'm guessing you can tell them what URL to POST to, right?) Cool. Thanks for the suggestion. I've tried to make them change the way they post it to me and if that's not possible I'll consider your advice about either PUT or digging into ZPublisher which I was hoping not to have to do. As an alternative strategy, how about: i) set up a url just for this problem user ii) us apache rewrite to redirect to a non-zope cgi script iii) use the cgi script to 'fix' the xml iv) do a redirect with the fixed xml to a 'zope' url This would allow you to run a standard zope installation (running a hacked installation is a maintenance nightmare), and if the problem user ever gets their act together, you just change the apache rewrite rule so that they are delivered straight to your zope application. Just a thought... Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Re: Sending XML straight down to a zope
Tres Seaver wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Peter Bengtsson wrote: I'm trying to send an XML straight into Zope without specifying it as a parameter and with a Content-Length. It seems that Zope's mapply function or whatever it's called digests the raw http body and tries to turn it into parameters? Here's the code on the Zope server (uploadExpenseXML()): def uploadExpenseXML(self): return str(self.REQUEST.form.keys()) Here's the dummy code that sends the XML into my Zope: xml_content = open('validxmlfile.xml').read() http = httplib.HTTP("localhost", 8080) http.putrequest("POST", "/uploadExpenseXML") http.putheader("User-Agent", "Simple") http.putheader("Host", "localhost") http.putheader("Content-Length", "%d" % len(xml_content)) http.endheaders() http.send(xml_content) reply, message, headers = http.getreply() print http.getfile().read() The result I get is: ['\n Obviously, one solution would be to ask the XML sending company to not post it like this but instead post it by parameter which I know will work. But, what if I can't change their minds? PS. When faced with the same problem a long time ago I ended up writing a mod_python app running one a different port that converted the http post from mod_python into a parameter based http post. I don't want to have to do that again. Stock Zope can only handle POST request with XML payloads if they conform to the XMLRPC spec: they must have the 'Content-type' header of 'text/xml', and the document must be encoded as an xmlrpc request. If you can get the vendor to use a PUT request instead of a POST, you could process the result inside a custom object'c 'PUT' method. Otherwise, you are going to need to create a custom derivative of ZPublisher.HTTPRequest, and override its 'processInputs' to handle the vendor's non-standard dump. You could make that server listen on a different port, for instance (I'm guessing you can tell them what URL to POST to, right?) Cool. Thanks for the suggestion. I've tried to make them change the way they post it to me and if that's not possible I'll consider your advice about either PUT or digging into ZPublisher which I was hoping not to have to do. Tres. - -- === Tres Seaver +1 202-558-7113 [EMAIL PROTECTED] Palladion Software "Excellence by Design"http://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFLRMX+gerLs4ltQ4RAuLVAJ9YJUQBTQzWxwEFlC5Wq/3OhUAVqACfUslN YgO7r1gy0aepLprIi0S8LNo= =ZHoA -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] Re: Sending XML straight down to a zope
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Peter Bengtsson wrote: > I'm trying to send an XML straight into Zope without specifying it as > a parameter and with a Content-Length. It seems that Zope's mapply > function or whatever it's called digests the raw http body and tries > to turn it into parameters? > > > Here's the code on the Zope server (uploadExpenseXML()): > def uploadExpenseXML(self): >return str(self.REQUEST.form.keys()) > > > Here's the dummy code that sends the XML into my Zope: > > xml_content = open('validxmlfile.xml').read() > http = httplib.HTTP("localhost", 8080) > http.putrequest("POST", "/uploadExpenseXML") > http.putheader("User-Agent", "Simple") > http.putheader("Host", "localhost") > http.putheader("Content-Length", "%d" % len(xml_content)) > http.endheaders() > http.send(xml_content) > reply, message, headers = http.getreply() > print http.getfile().read() > > > The result I get is: > [' > If I debug the value of that single REQUEST.form variable, it starts > like this: > '"1.0" encoding="ISO-8859-1" standalone="yes" ?>\n Version="1.0"> > > Obviously, one solution would be to ask the XML sending company to not > post it like this but instead post it by parameter which I know will > work. > But, what if I can't change their minds? > > > > PS. When faced with the same problem a long time ago I ended up > writing a mod_python app running one a different port that converted > the http post from mod_python into a parameter based http post. I > don't want to have to do that again. Stock Zope can only handle POST request with XML payloads if they conform to the XMLRPC spec: they must have the 'Content-type' header of 'text/xml', and the document must be encoded as an xmlrpc request. If you can get the vendor to use a PUT request instead of a POST, you could process the result inside a custom object'c 'PUT' method. Otherwise, you are going to need to create a custom derivative of ZPublisher.HTTPRequest, and override its 'processInputs' to handle the vendor's non-standard dump. You could make that server listen on a different port, for instance (I'm guessing you can tell them what URL to POST to, right?) Tres. - -- === Tres Seaver +1 202-558-7113 [EMAIL PROTECTED] Palladion Software "Excellence by Design"http://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFLRMX+gerLs4ltQ4RAuLVAJ9YJUQBTQzWxwEFlC5Wq/3OhUAVqACfUslN YgO7r1gy0aepLprIi0S8LNo= =ZHoA -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )