I want to run a report from JasperServer using a PHP SOAP client. I found this example online, but I want to attach an XML data source, used for the report data, and I am unsure how it should be correctly attached.
How can I attach my XML data source to the SOAP request, that is acceptable to Jasper Server?
public function requestReport($report, $format, $params) {
$params_xml = "";
foreach ($params as $name => $value) {
$params_xml .= "<parameter name=\"$name\"><![CDATA[$value]]></parameter>\n";
}
$request = "
<request operationName=\"runReport\" locale=\"en\">
<argument name=\"RUN_OUTPUT_FORMAT\">$format</argument>
<resourceDescriptor name=\"\" wsType=\"\"
uriString=\"$report\"
isNew=\"false\">
<label>null</label>
$params_xml
</resourceDescriptor>
</request>
";
$client = new SoapClient(null, array(
'location' => $this->url,
'uri' => 'urn:',
'login' => $this->username,
'password' => $this->password,
'trace' => 1,
'exception'=> 1,
'soap_version' => SOAP_1_1,
'style' => SOAP_RPC,
'use' => SOAP_LITERAL
));
$pdf = null;
try {
$result = $client->__soapCall('runReport', array(
new SoapParam($request,"requestXmlString")
));
$pdf = $this->parseReponseWithReportData(
$client->__getLastResponseHeaders(),
$client->__getLastResponse());
} catch(SoapFault $exception) {
$responseHeaders = $client->__getLastResponseHeaders();
if ($exception->faultstring == "looks like we got no XML document" &&
strpos($responseHeaders, "Content-Type: multipart/related;") !== false) {
$pdf = $this->parseReponseWithReportData($responseHeaders, $client->__getLastResponse());
} else {
throw $exception;
}
}
if ($pdf)
return $pdf;
else
throw new Exception("Jasper did not return PDF data. Instead got: \n$pdf");
}
The full example I found here https://gist.github.com/26205
The goal it to create something like this: