Run a report using Rest_v2 and java

0

Hey,

I'm new in the JasperReport community.

I've been using this solution for 3 weeks. I first used iReport to creat my reports and JasperReport Server to run and schedule them but my compagny want to use this solution in their own application.

So I tried to developped a solution using java and rest. I can run a report and it works.

But we need to use rest_v2 in our application because we need to be able to get the statut of a report (when scheduling) and I can't make it run.

It works when I just put the URL in FireFox but when I use a little programm in java to run it, I get a 403 forbidden error even if the programm (almost the same one) works with Rest (v1).

 

Here is an example of my really little programm to run with Rest_v2 a report :

 

public class Get_Rapport {
    public static void main(String[] args) throws Exception {
        
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope("localhost", 8080),
                new UsernamePasswordCredentials("jasperadmin", "jasperadmin"));
        
        CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider).build();
        try {
            HttpGet httpget = new HttpGet("http://localhost:8080/jasperserver/rest_v2/reports/reports/samples/Essai...");
            System.out.println("executing request" + httpget.getRequestLine());
            CloseableHttpResponse response = httpclient.execute(httpget);
            System.out.println(response.getStatusLine());

  } finally {
            httpclient.close();
        }

 

 

It would be really nice to explain me what's wrong, cause I really don't get it :(

I'm a student and that's the topic ofmy placement so I have to find a way to do it...

Thanks.

Jb

 

------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Do someone has an example of runing a report with Rest_v2 in Java if you don't know the issue i'm facing ?

 

Thanks :)

 

jbgauche57's picture
Joined: May 21 2013 - 12:23am
Last seen: 6 years 4 months ago

3 Answers:

1

Ok, here we are. I attached an eclipse sample project archive. It is based on an example for the REST API I found somewhere on the Jaspersoft pages.

I left in the original example "BasicResourceCRUDTest" which creates a folder on the jasperserver, uploads and downloads an image file, and finally deletes the folder. It makes heavy use of the two main classes "RestAPIUtils" and "Consts", which manage all the http-connection relevant things. The most of it was not my effort, so thanks to the Jaspersoft people.

"RESTV2Test" shows how to execute and export a report remotely (report "Employees" from the foodmart demo-installation) as a PDF file, and writes the result to a local directory (directory is hard-coded, report output type can be changed by changing the extension ".pdf" to sth. else).

I hope this helps, have fun.

Cheers, Thomas

http://www.thomaszimmer.net

Attachments: 
AttachmentSize
Package icon eclipse demo project REST / RESTv2908.63 KB
Thomas Zimmer's picture
Joined: Oct 2 2012 - 1:35am
Last seen: 5 days 13 hours ago

P.S.: I used Eclipse Juno, Jasperserver 5.0.x, dk 1.6.0_22 for this and added the required third-party libs for this...

Thomas Zimmer - 6 years 5 months ago

Thank you so much !
Everything is working now ! :)
I think that the problem was coming from my authentification but it solved now.

I hope I don't abuse of you but if anyone have an exemple or a tutorial of a scheduling in java, I'm here !

Thanks again.

jbgauche57 - 6 years 5 months ago
0

hi, I have such an example. and I saw your last posts concerning this, too... unfortunately I didn´t have the time yet (working) to review and post it. I´ll try this evening.

Cheers, Thomas

http://www.thomaszimmer.net

Thomas Zimmer's picture
Joined: Oct 2 2012 - 1:35am
Last seen: 5 days 13 hours ago

Thanks a lot !
That's really nice.

I'll continue the other part of my project waiting for your help :)

Thanks again

jbgauche57 - 6 years 5 months ago
0

Hi Thomas Zimmer.

Can you please give us the code for report creation in jasperserver using rest_v2.

We are unable to create the ReportUnit for the report.

rajesh.majoju's picture
Joined: Feb 8 2014 - 1:57am
Last seen: 3 years 10 months ago
Feedback