6

我能够弄清楚如何使用带有 SOAPpy 和 xml.dom minidom 的 Python 在 JasperServer 上运行报告、下载文件、列出文件夹等。

这是一个执行报告请求的示例,它有效:

repositoryURL = 'http://user@pass:myjasperserver:8080/jasperserver/services/repository'
repositoryWSDL = repositoryURL + '?wsdl'
server = SOAPProxy(repositoryURL, repositoryWSDL)
print server._ns(repositoryWSDL).runReport('''
  <request operationName="runReport" locale="en">
    <argument name="RUN_OUTPUT_FORMAT">PDF</argument>
    <resourceDescriptor name="" wsType="" uriString="/reports/baz">
      <label>null</label>
      <parameter name="foo">bar</parameter>
    </resourceDescriptor>
  </request>
''')

但是,我无法正确格式化服务器“ReportScheduler”部分的请求。我已经查阅了位于此处的文档(http://jasperforge.org/espdocs/docsbrowse.php?id=74&type=docs&group_id=112&fid=305),并尝试在他们的样本之后对我的请求进行建模,但没有成功(参见第 27 页)。

这是我尝试过的两个示例,它们都返回相同的错误:

schedulingURL = 'http://user@pass:myjasperserver:8080/jasperserver/services/ReportScheduler'
schedulingWSDL = schedulingURL + '?wsdl'
server = SOAPProxy(schedulingURL, schedulingWSDL)

# first request
print server._ns(schedulingWSDL).scheduleJob('''
  <request operationName="scheduleJob" locale="en">
    <job>
      <reportUnitURI>/reports/baz</reportUnitURI>
      <label>baz</label>
      <description>baz</description>
      <simpleTrigger>
        <startDate>2009-05-15T15:45:00.000Z</startDate>
        <occurenceCount>1</occurenceCount>
      </simpleTrigger>
      <baseOutputFilename>baz</baseOutputFilename>
      <outputFormats>
        <outputFormats>PDF</outputFormats>
      </outputFormats>
      <repositoryDestination>
        <folderURI>/reports_generated</folderURI>
        <sequentialFilenames>true</sequentialFilenames>
        <overwriteFiles>false</overwriteFiles>
      </repositoryDestination>
      <mailNotification>
        <toAddresses>my@email.com</toAddresses>
        <subject>test</subject>
        <messageText>test</messageText>
        <resultSendType>SEND_ATTACHMENT</resultSendType>
      </mailNotification>
    </job>
  </request>''')

# second request (trying different format here)
print server._ns(schedulingWSDL).scheduleJob('''
  <ns1:scheduleJob soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.jasperforge.org/jasperserver/ws">
  <job xsi:type="ns1:Job">
    <reportUnitURI xsi:type="xsd:string">/reports/baz</reportUnitURI>
    <username xsi:type="xsd:string" xsi:nil="true"/>
    <label xsi:type="xsd:string">baz</label>
    <description xsi:type="xsd:string">baz</description>
    <simpleTrigger xsi:type="ns1:JobSimpleTrigger">
      <timezone xsi:type="xsd:string" xsi:nil="true"/>
      <startDate xsi:type="xsd:dateTime">2008-10-09T09:25:00.000Z</startDate>
      <endDate xsi:type="xsd:dateTime" xsi:nil="true"/>
      <occurrenceCount xsi:type="xsd:int">1</occurrenceCount>
      <recurrenceInterval xsi:type="xsd:int" xsi:nil="true"/>
      <recurrenceIntervalUnit xsi:type="ns1:IntervalUnit" xsi:nil="true"/>
    </simpleTrigger>
    <calendarTrigger xsi:type="ns1:JobCalendarTrigger" xsi:nil="true"/>
    <parameters soapenc:arrayType="ns1:JobParameter[4]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
    </parameters>
    <baseOutputFilename xsi:type="xsd:string">test</baseOutputFilename>
    <outputFormats soapenc:arrayType="xsd:string[1]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <outputFormats xsi:type="xsd:string">PDF</outputFormats>
    </outputFormats>
    <outputLocale xsi:type="xsd:string" xsi:nil="true"/>
    <repositoryDestination xsi:type="ns1:JobRepositoryDestination">
      <folderURI xsi:type="xsd:string">/reports_generated</folderURI>
      <sequentialFilenames xsi:type="xsd:boolean">false</sequentialFilenames>
      <overwriteFiles xsi:type="xsd:boolean">false</overwriteFiles>
    </repositoryDestination>
    <mailNotification xsi:type="ns1:JobMailNotification" xsi:nil="true"/>
  </job>
  </ns1:scheduleJob>''')

这些请求中的每一个都会导致错误:

SOAPpy.Types.faultType: <Fault soapenv:Server.userException: org.xml.sax.SAXException:
Bad types (class java.lang.String -> class com.jaspersoft.jasperserver.ws.scheduling.Job):
<SOAPpy.Types.structType detail at 14743952>: {'hostname': 'myhost'}>

任何帮助/指导将不胜感激。谢谢你。

4

2 回答 2

1

在完全不了解 Jasper 的情况下,我可以向您保证,您最好用一个基于出色 suds 库的简单客户端来替换硬编码的 SOAP 请求。它抽象出 SOAP 并为您提供干净利落的 API 访问。

easy_install suds并且文档应该足以让您继续前进。

于 2010-03-15T20:58:53.043 回答
1

我在 minidom 方面有过很多不好的经历。我建议您使用lxml。我对肥皂本身没有任何经验,所以我不能谈论这个问题的其余部分。

于 2009-12-13T23:22:34.973 回答