[Pywps-devel] problem with CGI and Wget

Jachym Cepicky jachym.cepicky at gmail.com
Fri Jan 23 08:55:25 CET 2009


One more little thing:

nowhere in the standard it is said (again: correct me, if I'm wrong),
that the input data in XML encoding using HTTP POST should be send via
some kind of web-form. The data are always assumed to be in "raw
format".

Jachym

2009/1/23 Jachym Cepicky <jachym.cepicky at gmail.com>:
> Hi,
> sorry the delay,
>
>
>
> 2009/1/21 Jorge de Jesus <jorge.de-jesus at jrc.it>:
>> Hi to all
>>
>> I had some problems, with the WPS service
>>
>> 1. I made the following command:
>> wget -nv -q -O - --post-file=dummyprocess.xml
>> http://localhost/cgi-bin/wps.py
>
> try wget --post-data -- it should work
>
> [...]
>>
>> Everything is fine, the problem is that when using CGI, the sysin contains
>> the content headers and footer
>>
>> -----------------------------101407164111186312061014035381
>> Content-Disposition: form-data; name="file"; filename="dummyrequest.xml"
>> Content-Type: text/xml
>> [...]
>
> there should be some function in the pythonish cgi package. But in
> wps.py, we do parse the inputs directly (from sys.stdin)
>
>>
>> 3. Code to solve the problems
>> The first problem was solved by adding the following to the wps.py (I att.
>> the new file in the email)
>>
>>         try:
>>             if int(os.environ["CONTENT_LENGTH"]):
>>             parser = Post(self)
>>                     parser.parse(sys.stdin)
>>             else:
>>             raise Exceptions.NoApplicableCode("Couldn't get the POST request
>> or empty POST request")
>>         except:
>>         parser = Post(self)
>>                 parser.parse(sys.stdin)
>>
>> On the post.py file I had a simple rsplit algorithm that splits the strings
>> by "\n\r" and then assumes that the XML request should be the biggest
>> string:
>>
>>
>>  # read the document
>>         if maxFileSize > 0:
>>         inputXmlRaw = file.read(maxFileSize)
>>             if file.read() != "":
>>                 raise self.wps.exceptions.FileSizeExceeded()
>>         else:
>>             inputXmlRaw = file.read()q
>>
>>     #The input XML may have the header from the HTTP-POST request, therefore
>> it needs to be clean
>>     rawStringList=inputXmlRaw.rsplit("\r\n")
>>     inputXml=rawStringList[0]
>>     for item in rawStringList:
>>           if len(item)>len(inputXml):
>>               inputXml=item
>>
>>         # make DOM from XML
>>
>> Maybe this could be done in a more elegant way......
>
>
> I agree, that the solution does not look nice. IMHO it is not needed
> actualy (correct me, if I'm wrong)
>
> If you use wget --post-data, than it works
>
> If you want to run the process from the web browser, you can use Ajax:
>
> // build the XML file as String object
> var executeRequest = "<?xml version=\"1.0\" ?>"+
>     "<wps:Execute service=\"WPS\" version=\"1.0.0\"
> xmlns:wps=\"http://www.opengis.net/wps/1.0.0\""+
>     "xmlns:ows=\"http://www.opengis.net/ows/1.1\"
> xmlns:xlink=\"http://www.w3.org/1999/xlink\""+
>     "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
> xsi:schemaLocation=\"http://www.opengis.net/wps/1.0.0/wpsExecute_request.xsd\">"+
>        "<ows:Identifier>exampleBufferProcess</ows:Identifier>"+
>        "<wps:DataInputs>"+
>                "<wps:Input>"+
>       .....
>     "</wps:Execute>";
>
> // define Ajax request
> var httpRequest = new XMLHttpRequest();
>
> // define the function for parsing resulting file
> httpRequest.onreadystatechange = function(){
>        if (httpRequest.readyState == 4) {
>            if (httpRequest.status == 200) {
>
>             //little hack -  convert responseText to DOM
>             try {
>                  var xmldom = new ActiveXObject('Microsoft.XMLDOM');
>                  xmldom.loadXML(httpRequest.responseText);
>                  parseExecuteResponse(xmldom);
>              } catch(e) {
>                  try {
>
> parseExecuteResponse(DOMParser().parseFromString(httpRequest.responseText,
> 'text/xml'));
>                 catch(e) {}
>            }
>
>
>            } else {
>                alert('There was a problem with the request.');
>            }
>        }
>
> };
>
> // Execute the process
> httpRequest.open('POST', 'http://localhost/cgi-bin/wps.py', true);
> httpRequest.send(executeRequest); // <- there we go with the "form submition"
>
>
> // here is the DO SOMETHING function
> parseExecuteResponse = function(dom) {
>    // we have DOM of the Execute response here
> };
>
>
> I hope, this is clear. Would it be helpful for you as well?
>
> Jachym
>
> --
> Jachym Cepicky
> e-mail: jachym.cepicky gmail com
> URL: http://les-ejk.cz
> GPG: http://les-ejk.cz/pgp/JachymCepicky.pgp
>



-- 
Jachym Cepicky
e-mail: jachym.cepicky gmail com
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/pgp/JachymCepicky.pgp


More information about the Pywps-devel mailing list