我能够弄清楚如何使用带有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'}>
任何帮助/指导将不胜感激。谢谢。
答案 0 :(得分:1)
我和minidom有过很多糟糕的经历。我建议你使用lxml。我对肥皂本身没有任何经验,所以我不能谈论剩下的问题。
答案 1 :(得分:1)
在不了解Jasper的任何内容的情况下,我可以向您保证,您可以更好地使用基于the excellent suds library的简单客户端替换您的硬编码SOAP请求。它抽象出SOAP并为您留下干净利落的API访问权限。
easy_install suds
和the docs应足以让你前进。