Link to home
Create AccountLog in
Avatar of ctangent
ctangent

asked on

Problem with calling webservice from python CGI in Tomcat

My program is:

#!c:\python24\python -u
from SOAPpy import WSDL

def header():
      print "Content-type: text/html"
      print
      print "<HTML><HEAD>"
      print "<TITLE>CGI Test</TITLE>"
      print "</HEAD>"
      print "<BODY>"
      
def footer():
      print "</BODY></HTML>"

if __name__ == "__main__":
      header()

      wsdlFile = 'http://localhost/axis/services/DateService?wsdl'      
      service = WSDL.Proxy(wsdlFile)
      out = service.getCurrentTimeMillis()
            
      print '<h6>'
      print out
      print '</h6>'
      footer()

When run from the command prompt, it succeeds with the output being:
<HTML><HEAD>
<TITLE>CGI Test</TITLE>
<?HEAD>
<BODY>
<h6>
1143129399317
</h6>
</BODY></HTML>

However, when I run the cgi through tomcat by typing the command into the web browser:
http://localhost/testcount-gui/cgi-bin/date.cgi

I get this as a response (after right-click, view source):
<HTML><HEAD>
<TITLE>CGI Test</TITLE>
</HEAD>
<BODY>

It fails at this call:
      service = WSDL.Proxy(wsdlFile)

In the Tomcat logs, the only logfile updated is the log that says:
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):Traceback (most recent call last):
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Tomcat 5.5\webapps\testcount-gui\WEB-INF\cgi\date.cgi", line 26, in ?
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    service = WSDL.Proxy(wsdlFile)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Python24\Lib\site-packages\SOAPpy\WSDL.py", line 67, in __init__
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    self.wsdl = reader.loadFromString(str(wsdlsource))
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Python24\Lib\site-packages\SOAPpy\wstools\WSDLTools.py", line 47, in loadFromString
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    return self.loadFromStream(StringIO(data))
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Python24\Lib\site-packages\SOAPpy\wstools\WSDLTools.py", line 28, in loadFromStream
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    document = DOM.loadDocument(stream)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Python24\Lib\site-packages\SOAPpy\wstools\Utility.py", line 602, in loadDocument
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    return xml.dom.minidom.parse(data)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Python24\Lib\site-packages\_xmlplus\dom\minidom.py", line 1915, in parse
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    return expatbuilder.parse(file)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Python24\Lib\site-packages\_xmlplus\dom\expatbuilder.py", line 930, in parse
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    result = builder.parseFile(file)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Python24\Lib\site-packages\_xmlplus\dom\expatbuilder.py", line 207, in parseFile
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    parser.Parse(buffer, 0)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 5

So the error is: xml.parsers.expat.ExpatError: not well-formed (invalid token)

I think it is weird that this works outside of running through Tomcat.  My only thought is that its a permissions issue in Windows, except my Tomcat installation is in C:\Tomcat5\  so this shouldn't be a problem, and my Python installation is C:\Python24\.

Any ideas on what could be causing this problem?

Avatar of mish33
mish33
Flag of United States of America image

What do you get when you type the command into the web browser:
http://localhost/axis/services/DateService?wsdl

Do you get a well formed wsdl file?
Avatar of ctangent
ctangent

ASKER

Yes.  If I run the cgi program through the command line (python date.cgi) it works, which means that SOAPpy is actually taking the WSDL file and creating the Proxy, and then I can use it successfully.  The code also works if I type in the commands into the Python interpreter.  The cgi script fails when I run it through the cgi call on Tomcat, so thats the only difference.  To me it has to be either a permissions issue or a python module is not being accessed by Tomcat, but I don't know how to fix it.
Neither, you can see it from traceback. Please answer _my_ question.
"Do you get a well formed wsdl file?"

Yes, as mentioned in my first response.

"What do you get when you type the command into the web browser:
http://localhost/axis/services/DateService?wsdl"

Sorry, I thought the reql question was "Do you get a well formed wsdl file?"

What do you mean by "Neither, you can see it from traceback"?  Here is the wsdl file below, as shows up when http://localhost/axis/services/DateService?wsdl is typed into the browser:

<wsdl:definitions targetNamespace="urn:Test1">
<!--
WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)
-->
<wsdl:message name="getCurrentTimeMillisRequest">
</wsdl:message>

<wsdl:message name="getDateResponse">
     <wsdl:part name="getDateReturn" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="getDateRequest">
</wsdl:message>

<wsdl:message name="getCurrentTimeMillisResponse">
     <wsdl:part name="getCurrentTimeMillisReturn" type="soapenc:string"/>
</wsdl:message>

<wsdl:portType name="DateService">
     <wsdl:operation name="getCurrentTimeMillis">
     <wsdl:input message="impl:getCurrentTimeMillisRequest" name="getCurrentTimeMillisRequest"/>
     <wsdl:output message="impl:getCurrentTimeMillisResponse" name="getCurrentTimeMillisResponse"/>
     </wsdl:operation>
     <wsdl:operation name="getDate">
     <wsdl:input message="impl:getDateRequest" name="getDateRequest"/>
     <wsdl:output message="impl:getDateResponse" name="getDateResponse"/>
     </wsdl:operation>
</wsdl:portType>

<wsdl:binding name="DateServiceSoapBinding" type="impl:DateService">
     <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

     <wsdl:operation name="getCurrentTimeMillis">
          <wsdlsoap:operation soapAction=""/>
          <wsdl:input name="getCurrentTimeMillisRequest">
               <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
          </wsdl:input>
          <wsdl:output name="getCurrentTimeMillisResponse">
          <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
          </wsdl:output>
     </wsdl:operation>

 
    <wsdl:operation name="getDate">
          <wsdlsoap:operation soapAction=""/>
          <wsdl:input name="getDateRequest">
          <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
          </wsdl:input>
          <wsdl:output name="getDateResponse">
          <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Test1" use="encoded"/>
          </wsdl:output>
     </wsdl:operation>
</wsdl:binding>

<wsdl:service name="DateServiceService">
     <wsdl:port binding="impl:DateServiceSoapBinding" name="DateService">
     <wsdlsoap:address location="http://localhost/axis/services/DateService"/>
     </wsdl:port>
</wsdl:service>

</wsdl:definitions>
>>To me it has to be either a permissions issue or a python module is not being accessed by Tomcat, but I don't know how to fix it.

> Neither, you can see it from traceback

Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    service = WSDL.Proxy(wsdlFile)
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):  File "C:\Python24\Lib\site-packages\SOAPpy\WSDL.py", line 67, in __init__
Mar 23, 2006 10:56:49 AM org.apache.catalina.core.ApplicationContext log
INFO: cgi: runCGI (stderr):    self.wsdl = reader.loadFromString(str(wsdlsource))

As you can see your script was called OK and it calls WSDL.py OK as well.
Permissions it can be but write perm for temp file or something similar.

Check wsdl source (in brouser as well - "View source"), provide first 3 lines here please.
From "view source" after http://localhost/axis/services/DateService?wsdl typed into browser:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:Test1" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:Test1" xmlns:intf="urn:Test1" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.3
Built on Oct 05, 2005 (05:23:37 EDT)-->
<wsdl:message name="getCurrentTimeMillisRequest">
</wsdl:message>

Okay, a little more than first few lines, but you can see that it continues after this to what I displayed in the previous post.  What is so wierd is that there is no error when I run the program by the command line; it works great then.
ASKER CERTIFIED SOLUTION
Avatar of mish33
mish33
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
expat?  The XML parser, or something else?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Any suggestions on how to get this information when I run the command line?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
mish33,
Thank you for your help.  It will be a few days before I can get back to this, but when I do I will post.
Venabili,

Apologies.  The problem was not easily solved, the only solution suggested invovling alot more work and time than I had.  Meanwhile, I found another route to take in my work that avoided the problem alltogether.  Thus, this question has been hanging over my head for sometime, not sure what to do.

If I run across the same problem in the future, however, I will know where to begin in solving the problem (mish33 writes: Aparently execution context is not the same. Please check which expat is loaded in either case (command-line and apache), I suspect they aren't the same.)

I'd like to give him full points for this, with the suggestion to check the expat and how to do this as an assisted answer.

Let me know what you think.
mish33,

Thank you for your support in helping find a solution to this problem.  Since I ran out of time to actually solve the problem, I will accept the possiblity of the XML expat being different, and the fact that the cgi was running in two different contexts.

-- ctangent
Any time