REST v2 API / PHP Client Errors

I'm using JasperSoft Studio Community Edition (6.3.1 final) and have the Community edition of JasperServer.

I have created reports and successfully published them from Studio to the server. I've also been able to review the reports on the actual server itself through the web app.

My next step is to use the Rest v2 API to display my reports in a project but I've been unsuccessful.

Here is my code (trying to display the server info):

<?php require_once("autoload.dist.php"); use Jaspersoft\Client\Client; $c = new Client("my-server-ip", "my-username", "my-password"); $info = $c->serverInfo(); printf($info); ?>

I removed the organization because there is no organization associated with my account and having the organization parameter would return a 404 error.

Upon testing this code, I receive the following message:

Fatal error: Uncaught exception 'Jaspersoft\Exception\RESTRequestException' with message 'An unexpected HTTP status code was returned by the server' in /var/www/html/jaspersoft-php/src/Jaspersoft/Tool/RESTRequest.php:378 Stack trace: #0 /var/www/html/jaspersoft-php/src/Jaspersoft/Tool/RESTRequest.php(451): Jaspersoft\Tool\RESTRequest->handleError(0, Array, false) #1 /var/www/html/jaspersoft-php/src/Jaspersoft/Client/Client.php(158): Jaspersoft\Tool\RESTRequest->prepAndSend('http://my-ip...', Array, 'GET', NULL, true, 'application/jso...', 'application/jso...') #2 /var/www/html/jaspersoft-php/index.php(22): Jaspersoft\Client\Client->serverInfo() #3 {main} thrown in /var/www/html/jaspersoft-php/src/Jaspersoft/Tool/RESTRequest.php on line 378

Does anyone have any ideas as to why this is happening? I've been stuck on this issue for a day now and would like to get to the bottom of it.

Thank you in advance!

daniel.la's picture
Joined: Jan 19 2017 - 11:36am
Last seen: 5 years 11 months ago

Hi ,

What is the solution for this problem?  Facing this issue for one report when trying to run the report using one of the parameter.

Received following message:RESTRequestException:Exception message: An unexpected HTTP status code was returned by the server Set parameters: Expected status code:Array Error code: Array ( [0] => 200 ) Jaspersoft\Exception\RESTRequestException Object ( [message] => An unexpected HTTP status code was returned by the server [expectedStatusCodes] => Array ( [0] => 200 ) [statusCode] => 0 [jrsMessage] => [errorCode] => [parameters] => [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\lsp\site\local\reports\jrs-rest-php-client-master\src\Jaspersoft\Tool\RESTRequest.php [line:protected] => 409 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\lsp\site\local\reports\jrs-rest-php-client-master\src\Jaspersoft\Tool\RESTRequest.php [line] => 479 [function] => handleError [class] => Jaspersoft\Tool\RESTRequest [type] => -> [args] => Array ( [0] => 0 [1] => Array ( [0] => 200 ) [2] => ) ) [1] => Array ( [file] => C:\xampp\htdocs\lsp\site\local\reports\jrs-rest-php-client-master\src\Jaspersoft\Service\ReportService.php [line] => 40 [function] => prepAndSend [class] => Jaspersoft\Tool\RESTRequest [type] => -> [args] => Array ( [0] => http://localhost:8080/jasperserver/rest_v2/reports/ContentFiles/html/Tea... [1] => Array ( [0] => 200 ) [2] => GET [3] => [4] => 1 ) ) [2] => Array ( [file] => C:\xampp\htdocs\lsp\site\local\reports\teacherperformancereport.php [line] => 146 [function] => runReport [class] => Jaspersoft\Service\ReportService [type] => -> [args] => Array ( [0] => /ContentFiles/html/TeacherPerformanceReport [1] => html [2] => [3] => [4] => Array ( [trackId] => Array ( [0] => 1 ) ) [5] => 1 [6] => 1 ) ) ) [previous:Exception:private] => )

Report run successfully for other parameters.

Kindly help. Thanks in Advance

vspadma01 - 1 year 6 months ago

7 Answers:

nevermind. solved it

daniel.la's picture
Joined: Jan 19 2017 - 11:36am
Last seen: 5 years 11 months ago

Please tell me how to resolve this issue;

Fatal error: Uncaught exception 'Jaspersoft\Exception\RESTRequestException' with message 'An unexpected HTTP status code was returned by the server' in C:\xampp\htdocs\sample\src\Jaspersoft\Tool\RESTRequest.php:378 Stack trace: #0 C:\xampp\htdocs\sample\src\Jaspersoft\Tool\RESTRequest.php(451): Jaspersoft\Tool\RESTRequest->handleError(0, Array, false) #1 C:\xampp\htdocs\sample\src\Jaspersoft\Client\Client.php(158): Jaspersoft\Tool\RESTRequest->prepAndSend('http://192.168....', Array, 'GET', NULL, true, 'application/jso...', 'application/jso...') #2 C:\xampp\htdocs\sample\sample.php(15): Jaspersoft\Client\Client->serverInfo() #3 {main} thrown in C:\xampp\htdocs\sample\src\Jaspersoft\Tool\RESTRequest.php on line 378

germanmary.p's picture
Joined: Aug 24 2017 - 4:11am
Last seen: 6 years 1 month ago

It seems like you're developing locally. Can you test this on a live server? I had the same issues when developing locally, none of my reports would display.

daniel.la's picture
Joined: Jan 19 2017 - 11:36am
Last seen: 5 years 11 months ago

i am new to this i dont undertstand how to do it .

 

i have created the report and tried in server .i used this code with php client  jrs-rest-php-client-2.0.0 after downloading i had written a php file and run through xampp .

 

<?php
/*ini_set('display_errors',1);ini_set('display_startup_errors',1);error_reporting(E_ALL);
*///require_once __DIR__ . "/autoload.dist.php";
  require_once("autoload.dist.php");
use Jaspersoft\Client\Client;
 //require_once "src/Jaspersoft/Client/Client.php";

/*    try {   */
    $d = new Client(
                "http://localhost:8080/jasperserver",
                "jasperadmin",
                "jasperadmin"  ,""
            );

    $info = $d->serverInfo();
  printf($info);
/*} catch (RESTRequestException $e) {
    echo 'RESTRequestException:';
    echo 'Exception message:   ',  $e->getMessage(), "\n";
    echo 'Set parameters:      ',  $e->parameters, "\n";
    echo 'Expected status code:',  $e->expectedStatusCodes, "\n";
    echo 'Error code:          ',  $e->errorCode, "\n";
}
 $conts=array("agtid"=>2);

$report = $c->reportService()->runReport('/reports/samples/Cascading_multi_select_report',"pdf",null,null,$conts);
*/
//echo $report;
?>

germanmary.p's picture
Joined: Aug 24 2017 - 4:11am
Last seen: 6 years 1 month ago

I have the same error. Is there anyone who can suggest something to solve this issue ? Thanks.

 

sterlingman2001's picture
Joined: Jun 16 2017 - 5:25am
Last seen: 5 years 5 months ago

It's a pity that the jasperserver community could not find a solution! I just want to connect php7 with jasperserver7, use httpd in linux centos 7 (64bits). I'm showing the same error. Any light will be welcome

polexito2002_1's picture
Joined: Apr 17 2018 - 8:15am
Last seen: 3 years 2 weeks ago

Use User: jasperadmin and Password: jasperadmin

I don't no why but only this user works. 

thomas.frommelt's picture
Joined: Jan 21 2013 - 12:44am
Last seen: 2 years 7 months ago
Feedback
randomness