Jasper Rest API, run a report

2019-02-27 01:52发布

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?

3条回答
forever°为你锁心
2楼-- · 2019-02-27 02:38

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/

查看更多
做自己的国王
3楼-- · 2019-02-27 02:49

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

查看更多
Juvenile、少年°
4楼-- · 2019-02-27 02:54

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.

查看更多
登录 后发表回答