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:
On their own site they have also some examples about integration to Web Services via php.
Is there any help for this?
You want to include a xml file in your SOAP query or response?
You could encode it base64 like in emails and then require the user on the other end to decode it.
Then just add it in a seperate xml tag in your SOAP query/response.
This is more a comment than an answer, but probably helpful. There is a library called WSO2 WSF/PHP:
I think you're looking for Binary attachment (MTOM).
The following links might be useful as well:
SOAP
request has no attachment support.The idea is how you process your request. The only way I use SOAP requests with attachments is to
Base64 Encode
the data to be attached, and add it to a Text node.Add the tag with attribute
encoded=
"true/false"
. If its a file content, supply the name of the file in the request.In the server side, if you find the node with an attribute
encoded="true"
, You can take the data from the node, Base64Decode it and do what ever you need.The idea of Base64 is to avoid many special characters that a SOAP request doesn't support in Request. Some SOAP processors have the option with "
encoded
" attribute.