Jasper Rest API, run a report

2019-02-27 02:36发布

问题:

I am currently trying to run a report thanks to Jasper Rest API and get the output (PDF), the interessant part of the doc is here

So I tried this : http://localhost:8080/jasperserver/rest/report/reports/samples/report_mongodb_new_basic

Knowing that my report is in reports/samples and its Resource ID is : report_mongodb_new_basic

So I still tried to run it with nodejs here is my code : (request is a nodejs module available here )

Login :

var request = require("request");   
request.post({url: "http://localhost:8080/jasperserver/rest/login", 
qs: {j_username: "jasperadmin", j_password: "jasperadmin"}},
function(err, res, body) {
    if(err) {
        return console.error(err);
    }

After login, as the doc show I need to do a PUT request to run the report :

     request.put("http://localhost:8080/jasperserver/rest
     /report/reports/samples/report_mongodb_new_basic")

This isn't working of course, even when i directly go on this url with Firefox, it say

"Report not found (uuid not found in session)"

The uuid should be created thanks to this PUT request

So what is the good syntax of the URL and the good syntax of a PUT request to get the uuid and after if possible the pdf with a get?

回答1:

jonny provided a correct answer. But here is a simpler one, using the REST_v2 interface that allows you to run and get a report output in a single request:

        request.get("http://localhost:8080/jasperserver/rest_v2/reports/samples/report_mongodb_new_basic.pdf")

This is described in section 3.2.1 of web services documentation.



回答2:

Recently I have same problem.

After login and before running you PUT, you should run GET request on

http://localhost:8080/jasperserver/rest/report/reports/samples/report_mongodb_new_basic

answer body is resourceDescriptor

 <resourceDescriptor>
 ... 
 </resourceDescriptor>

then you should run your PUT request with request body set to resourceDescriptor

you can add report parameters to report unit definition. In fact, I use XMLRemoteDatasource to fetch my data so I add a parameter to report_unit

  ...
    <parameter name="XML_URL" class="java.lang.String">
        <![CDATA[http://$ENV{HTTP_HOST}/some_url]]>
    </parameter>
</resourceDescriptor>

this helped me for Jasper Server 4.5 Community Edition



回答3:

Example of a complete script for get a Report in Jasper, but in Ruby http://www.redrails.com.br/2013/03/07/ruby-client-para-rest-api-do-jasper-report-server/