How to install jrs-rest-php client?

0

Hello,

I have reports set up with iReport on our jaspersoft server. I have the server info and such to log in. I want to create a php web page that displays all information about scheduled reports on our jaspersoft server so we can keep track of it internally.


I have downloaded https://github.com/Jaspersoft/jrs-rest-php-client and read the documents. I have watched the tech talk video and I sitll am having trouble. I placed the folder in our local FTP sandbox for testing and create a test.php page. This is what I have on the page:

<?php
require_once "autoload.dist.php";
 
header('Content-Type: text/html');
 
use Jaspersoft\Client\Client;
 
$c = new Client(
       [redacted]
      );  
 
$report = $c->reportService()->runReport('/reports/MyReport', 'html');
 
echo $report;  
 
?>
 
When I navigate to it, this is the error that I am getting:
 
Fatal error: Class 'Jaspersoft\Client\Client' not found in /home/content/90/11012290/html/analytics/test.php on line 8
 
Can someone advise me on what I did wrong? Thank you
logicgaming's picture
Joined: May 29 2014 - 7:54am
Last seen: 5 years 2 months ago

You may want to remove your url/username/password details

grantbacon - 5 years 2 months ago

If you are using the most recent version of jrs-rest-php-client, the constructor has changed. However, it seems that the autoloader is not being loaded properly... it could be an OS-specific issue. There are a few ways you could solve this: 1) in autoload.dist.php you can replace the line:

 $location = JASPERCLIENT_ROOT . $class . '.php';

with the following:

 $location = JASPERCLIENT_ROOT . str_replace('\\', '/', $class) . '.php';

2) or you could use Composer and have it generate an autoloader for you, and use that autoloader (recommended)

Then you would want to modify your client constructor to use a URL as the first parameter

<?php
require_once("autoload.dist.php");
use Jaspersoft\Client\Client;
 
$client = new Client("http://localhost:8080/jasperserver-pro", "username", "password", "organization_name"); 

grantbacon - 5 years 2 months ago

Dear god, when I saw this reply and I saw that I left the info up, I sprinted up a few floors to fix this immediately. Thank you very much for the heads up, I remembered to tell myself to change that when writing the question and just messed up.

 

Regarding the composer, if the jaspersoft server and database is not sitting locally, will it still work?

logicgaming - 5 years 2 months ago
show 6 more...

Sure, Composer is just a dependency manager, similar to Maven for Java. It just helps manage packages and libraries you use when building your PHP application. 

grantbacon - 5 years 2 months ago

Thanks Grant,

 

Modifying the autload.dist.php seems to have done the trick. It has moved past that line and I'm getting a new error:

 

Fatal error: Call to a member function reportService() on a non-object in /home/content/90/11012290/html/analytics/test.php on line 10

 I've looked up this error it seems like perhaps it's having trouble finding the reportService class? I placed this php file on the same level as the autoload.dist.php so I'm not sure if I need to relocate it to somewhere else.

 

Additionally, I've installed postman on Chrome to test out the API calls prior to this project. For me to see all my scheduled reports, the URL is analy*********.com/an*******s2/rest_v2/jobs

 

Should I replace that with /reports/MyReport in $report? I just noticed that this test page to display reports in HTML is actually an example you gave to another user! Neat!

 

Thanks for your help!

logicgaming - 5 years 2 months ago

The URI you provide to runReport should match the URI within the JasperReports Server. You can get this URI by right clicking on a report in the repository and selecting "Properties.."

The error you show seems like your $c may not have been instantiated properly. You can try using var_dump to ensure that it has created an object properly, and additionally you can try to var_dump the contents of $c->serverInfo() to ensure the connection is being properly made to your JRS instance

 

Additionally, you won't want to change any of the underlying directory structures as the autoloader attempts to load classes as they are needed based on their expected locations within your filesystem

grantbacon - 5 years 2 months ago

Hi Grant, Again, thank you very much for your help. I really do appreciate it. I still have that same error:

 

Fatal error: Call to a member function serverInfo() on a non-object in /home/content/90/11012290/html/analytics/test.php on line 10

 

This time, I decided to see if I can grab the server info and do a var_dump from that and it didn't work. This was my code $c-> serverInfo(); var_dump($c); ?> Tomorrow I will try to use the composer because I actually edited the autoloader file instead of using the composer.

 

If that doesn't work, maybe my credentials are wrong. I log into the system everyday but perhaps I can test some stuff with a GET login credential (http://:/jasperserver[-pro]/rest/login?j_username=[%7C] &j_password=)

logicgaming - 5 years 2 months ago

I don't know if this is going to help you or not but I found it far easier to bypass the autoload and specifically load the classes I need. The idea behind the autoload is really nice (really, really nice) but I was having way too many issues - all of which went away once I started to explicitly load the classes.

bob_8 - 4 years 11 months ago

I got this exception when i run this code,

 

Jaspersoft\Exception\RESTRequestException: An unexpected HTTP status code was returned by the server in

ahesanbvm - 3 years 5 months ago

0 Answers:

No answers yet
Feedback
randomness