jasperserver with php

Asked

Viewed 407 times

1

I found a lib in Git https://github.com/adlermedrado/PHP-JasperServer-Integration that allows PHP to connect with Jasperserver ( java’s ireport server ), I already use and works, but I wanted to add a feature to this project, currently it 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 don’t know how the ireport file would look to receive an Object Array type there, I don’t even know if this is possible

  • You want to pass an object array to use as a parameter in the sql query?

  • that same, in fact I don’t even need to do the sql query, with these objects I would already fill out the form

1 answer

1


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

1) Download the PHP version 2 module (search the Jasperserver website, http://community.jaspersoft.com/wiki/php-client-getting-started)

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

3) add to 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; 
  • thanks Luiz Soares, already solves the problem !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.