jasperserver with php

1

I found a lib in Git link that allows PHP to connect to JasperServer (java server ), I already use and it works, but I wanted to add a functionality to this project, it currently only accepts an array of parameters as below:

    private function _requestMock($report, $format, $params)
    {

        if (is_array($params)) {
            $reportParams = "";
            foreach ($params as $name => $value) {
                $reportParams .= "<parameter name=\"$name\"><![CDATA[$value]]></parameter>\n";
            }
        } else {
            $reportParams = '';
        }

        $xmlTemplate = <<<XML_TEMPLATE
        <request operationName="runReport" locale="pt_BR">
            <argument name="RUN_OUTPUT_FORMAT">{$format}</argument>
            <resourceDescriptor name="" wsType="" uriString="{$report}" isNew="false">
                <label>null</label>
                {$reportParams}
            </resourceDescriptor>
        </request>
XML_TEMPLATE;
        return $xmlTemplate;
    }

What I wanted to do is to pass an array of objects, but I do not know what the ireport file would look like to get an Array of Objects there, I do not even know if that's possible.

    
asked by anonymous 09.09.2015 / 19:02

1 answer

1

Solution: Abandon the Adler lib and directly use Rest requests for Jasperserver.

1) Download the PHP version 2 module (look on the JasperServer website, link )

2) Make includes of all the php files of the module (I could not make direct inclusion by phar and composer as recommended in the documentation, so I made the files include one by one)

3) add in your code

use Jaspersoft\Client\Client;
use Jaspersoft\Exception\RESTRequestException;

 $jasperclient = new Jaspersoft\Client\Client(
                "http://192.168.56.102:8080/jasperserver",
                "jasperadmin",
                "jasperadmin"
            );

//aqui vai o array de controles e valores conforme o relatório que quer executar
 $controls = array('p_data' => '2017-06-20');

//aqui executa o relatório registrado no jasperserver, passando o array acima
$report = $jasperclient->reportService()->runReport('/reports/teste_telemkt', 'pdf', null, null, $controls);
header('Content-Type: application/pdf');
echo $report; 
    
02.07.2017 / 14:57