The reportExecutions Service¶
As described in The reports Service, synchronous report execution blocks the client waiting for the response. Synchronous report execution slows down or uses many threads, each waiting for a report, when:
-
Managing large reports that may take minutes to complete
-
Running a large number of reports simultaneously
The rest_v2/reportExecutions service provides asynchronous report execution, so that the client does not need to wait for report output. Instead, the client obtains a request ID to check the status of the report periodically. This is also called polling. When the report is finished, the client downloads the output. Alternatively, the client can check when specific pages are finished and download available pages. The client can also send an asynchronous request for other export formats (PDF, Excel, and others) of the same report. Again the client can check the status of the export and download the result when the export has been completed.
Reports scheduled on the server also run asynchronously. reportExecutions allows you to access jobs triggered by the scheduler. Finally, the reportExecutions service allows the client to stop and remove any report execution or job that has been triggered.
This chapter includes the following sections:
- Running a Report Asynchronously
- Polling Report Execution
- Requesting Page Status
- Requesting Report Execution Details
- Requesting Report Output
- Requesting Report Bookmarks
- Exporting a Report Asynchronously
- Modifying Report Parameters
- Polling Export Execution
- Finding Running Reports and Jobs
- Stopping Running Reports and Jobs
- Removing a Report Execution
Running a Report Asynchronously¶
To run a report asynchronously, the reportExecutions service provides a method to specify all the parameters needed to open a report. Report parameters are all sent as a reportExecutionRequest object. The response from the server contains the request ID needed to track the execution until completion.
Method |
URL |
||
|---|---|---|---|
POST |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions http://<host>:<port>/jrio/rest_v2/reportExecutions |
||
Content-Type |
Content |
||
application/xml application/json |
A complete A complete |
||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content contains a ReportExecution descriptor. See below for an example |
403 Forbidden–When the logged-in user does not have permission to access the report in the request. 404 Not Found – When the report URI specified in the request does not exist. |
||
The following example shows the structure of the ReportExecutionRequest:
<reportExecutionRequest>
<reportUnitUri>/supermart/details/CustomerDetailReport</reportUnitUri>
<async>true</async>
<reportContainerWidth>900</reportContainerWidth>
<freshData>false</freshData>
<saveDataSnapshot>false</saveDataSnapshot>
<outputFormat>html</outputFormat>
<interactive>true</interactive>
<ignorePagination>false</ignorePagination>
<pages>1-5</pages>
<parameters>
<reportParameter name="someParameterName">
<value>value 1</value>
<value>value 2</value>
</reportParameter>
<reportParameter name="someAnotherParameterName">
<value>another value</value>
</reportParameter>
</parameters>
</reportExecutionRequest>
{
"reportUnitUri":"/samples/reports/chartthemes/ChartThemesReport",
"async":true,
"interactive":true,
"pages":"1-5",
"attachmentsPrefix":"/jrio/rest_v2/reportExecutions/
{reportExecutionId}/exports/{exportExecutionId}/attachments/",
"baseUrl":"/jrio",
"parameters":
{
"reportParameter":
[
{"name":"chartTheme","value":["aegean"]},
{"name":"anotherParamName","value":["value 1","value 2"]}
]
}
}
The following table describes the properties that you can specify in the ReportExecutionRequest:
Property |
Required or Default |
Description |
|---|---|---|
reportUnitUri |
Required |
Repository path (URI) of the report to run. For commercial editions with organizations, the URI is relative to the logged-in user’s organization. Repository path (URI) of the report to run. |
outputFormat |
Required |
Specifies the desired output format: pdf, html, xlsx, rtf, csv, xml, docx, odt, ods, jrprint. As of JasperReports Server 6.0, it is also possible to specify json if your reports are designed for data export. For more information, see the JasperReports Library samples documentation. Specifies the desired output format:
data_csv, data_xlsx, data_json |
freshData |
false |
When data snapshots are enabled, it specifies whether the report should get fresh data by querying the data source. If false, use a previously saved data snapshot (if any). By default, if a saved data snapshot exists for the report it is used when running the report. |
saveDataSnapshot |
false |
When data snapshots are enabled, it specifies whether the data snapshot for the report should be written (or overwritten) with data from the report execution. |
interactive |
true |
In a commercial edition of the server where Highcharts are used in the report, this property determines whether the required JavaScript is generated. It is returned as an attachment when exported to HTML. If false, the chart is generated as a non-interactive image file (also as an attachment). |
allowInlineScripts |
true | Affects HTML export only. If true, then inline scripts are allowed, otherwise no inline script is included in the HTML output. |
ignorePagination |
Optional |
When set to true, the report is generated as a single long page. This can be used with HTML output to avoid pagination. When omitted, the ignorePagination property on the JRXML, if any, is used. |
pages |
Optional |
Specify a page range to generate a partial report. The format is: |
async |
false |
Determines whether reportExecution is synchronous or asynchronous. When set to true, the response is provided immediately and the client must poll the report status. They can download the results when ready. By default, this property is false and the operation pauses until the report execution is complete. The client must wait but can download the report immediately after the response. |
transformerKey |
Optional |
Advanced property used when requesting a report as a JasperPrint object. This property can specify a JasperReports Library generic print element transformer of the class net.sf.jasperreports.engine.export.GenericElementTransformer. These transformers are pluggable as JasperReports Library extensions. |
attachmentsPrefix |
attachments |
For HTML output, this property specifies the URL path to use for downloading the attachment files (JavaScript and images). The full path of the default value is: {contextPath}/rest_v2/reportExecutions/{reportExecutionId}/exports/{exportExecutionId}/attachments/ You can specify a different URL path using the placeholders {contextPath}, {reportExecutionId}, and {exportExecutionId}. |
baseUrl |
String | Specifies the base URL that the report uses to load static resources such as JavaScript files. You can also set the deploy.base.url property in the .../WEB-INF/js.config.properties file to set this value permanently. If both are set, the baseUrl parameter in this request takes precedence. Specifies the base URL that the report uses to load static resources such as JavaScript files. |
parameters |
A list of input control parameters and their values. By default, the parameter values are case-sensitive. To change them to case insensitive, set |
|
reportContainerWidth |
Optional | This property specifies the width of the report container. A report specifying this parameter with integer values receives the current screen size width when the report is run. |
When successful, the reply from the server contains the reportExecution descriptor. This descriptor contains the request ID and status needed for the client to request the output. There are two statuses, one for the report execution itself, and one for the chosen output format.
The following descriptor shows that the report is still running (<status>execution</status>).
The following descriptor shows that the report was placed in the report execution queue ("status":"queued"):
<reportExecution>
<currentPage>1</currentPage>
<exports>
<export>
<id>html</id>
<status>queued</status>
</export>
</exports>
<reportURI>/supermart/details/CustomerDetailReport</reportURI>
<requestId>f3a9805a-4089-4b53-b9e9-b54752f91586</requestId>
<status>execution</status>
</reportExecution>
{
"requestId":"9ecf5c6f-b70d-4170-8a3b-b305db4c2253",
"reportURI":"/samples/reports/chartthemes/ChartThemesReport",
"status":"queued"
}
The value of async in the request determines if the report output is available after receiving a response. Your client should implement either synchronous or asynchronous processing of the response depending on the value you set for the async property.
Set the async property.
Polling Report Execution¶
When requesting reports asynchronously, use the following method to poll the status of the report execution. The request ID in the URL is the one returned in the reportExecution descriptor.
This service supports the extended status value that includes an appropriate message.
Method |
URL |
||
|---|---|---|---|
GET |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/status/ http://<host>:<port>/jrio/rest_v2/reportExecutions/requestID/status/ |
||
Options |
Sample Return Value | ||
accept: application/xml (default) |
|
||
accept: application/status+xml |
|
||
accept: application/json |
|
||
accept: application/status+json |
|
||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content contains the report status, as shown above. In the extended format, error reports contain error messages suitable for display. |
404 Not Found – When the specified requestID does not exist. |
||
Requesting Page Status¶
When requesting reports asynchronously, you can also poll the status of a specific page during the report execution. The request ID in the URL is the one returned in the reportExecution descriptor.
When requesting reports asynchronously, you can also poll the status of a specific page during the report execution. The executionId in the URL is the one returned in the reportExecution descriptor. This service returns a response containing reportStatus, pageFinal, and pageTimestamp attributes.
Method |
URL |
||
|---|---|---|---|
GET |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/pages/pageNumber/status http://<host>:<port>/jrio/rest_v2/reportExecutions/<executionId>/pages/<pageNumber>/status |
||
Options |
Sample Response Content |
||
accept: application/status+json |
|
||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content contains the page status, as shown above. |
404 Not Found – When the request ID specified in the request does not exist. |
||
Requesting Report Execution Details¶
Once the report is ready, your client must determine the names of the files to download by requesting the reportExecution descriptor again. Specify the requestID in the URL as follows:
Method |
URL |
||
|---|---|---|---|
GET |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID http://<host>:<port>/jrio/rest_v2/reportExecutions/requestID |
||
Options |
|||
accept: application/xml accept: application/json |
|||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content contains a |
404 Not Found – When the request ID specified in the request does not exist. |
||
The reportExecution descriptor now contains the list of exports for the report, including the report output itself and any other file attachments. File attachments such as images and JavaScript occur only with HTML export.
{
"status": "ready",
"totalPages": 47,
"requestId": "cce63cba-1685-4708-ba4f-b70f277a1cd5",
"reportURI": "/public/Samples/Reports/AllAccounts",
"exports": [
{
"status": "ready",
"outputResource": {
"contentType": "text/html,"
"output final": true,
"outputTimestamp": 0
},
"id": "db9acf02-8add-4196-9ab5-ce86844bfc2e",
"attachments": [
{
"contentType": "image/png",
"fileName": "img_0_0_0"
}
]
}
{
"status": "ready",
"totalPages": 47,
"requestId": "b487a05a-4989-8b53-b2b9-b54752f998c4",
"reportURI": "/reports/samples/AllAccounts",
"exports": [{
"id": "195a65cb-1762-450a-be2b-1196a02bb625",
"options": {
"outputFormat": "html",
"attachmentsPrefix": "./images/",
"allowInlineScripts": false
},
"status": "ready",
"outputResource": {
"contentType": "text/html"
},
"attachments": [{
"contentType": "image/png",
"fileName": "img_0_46_0"
},
{
"contentType": "image/png",
"fileName": "img_0_0_0"
},
{
"contentType": "image/jpeg",
"fileName": "img_0_46_1"
}]
},
{
"id": "4bac4889-0e63-4f09-bbe8-9593674f0700",
"options": {
"outputFormat": "html",
"attachmentsPrefix": "{contextPath}/rest_v2/reportExecutions/{reportExecutionId}/exports/{exportExecutionId}/attachments/",
"baseUrl": "http://localhost:8080/jrio",
"allowInlineScripts": true
},
"status": "ready",
"outputResource": {
"contentType": "text/html"
},
"attachments": [{
"contentType": "image/png",
"fileName": "img_0_0_0"
}]
}]
}
When exporting a chart report to HTML, the image produced for the chart is a part of HTML, and can be in two formats - JavaScript or SVG:
- When "interactive" is set to true, it is embedded as JavaScript in HTML that uses Highcharts js to render the chart.
- When "interactive" is set to false, the chart image is embedded as SVG as part of HTML.
When the option net.sf.jasperreports.force.html.embed.image=false in WEB-INF/classes/jasperreports.properties in combination with interactive=false, this puts the SVG images into attachments instead of HTML.
Requesting Report Output¶
After requesting a report execution and waiting synchronously or asynchronously for it to finish, your client is ready to download the report output.
Every export format of the report has an ID that is used to retrieve it. For example, the HTML export in the previous example has the ID 195a65cb-1762-450a-be2b-1196a02bb625. To download the main report output, specify this export ID in the following method:
Method |
URL |
||
|---|---|---|---|
GET |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/exports/ exportID/outputResource http://<host>:<port>/jrio/rest_v2/reportExecutions/requestID/exports/ exportID/outputResource |
||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content is the main output of the report. The format specified by the |
400 Bad Request – When invalid values are provided for export options in the request body. 404 Not Found – When the request ID specified in the request does not exist. |
||
For example, to download the main HTML of the report execution response above, use the following URL:
Note
JasperReports Server does not support exporting Highcharts charts with background images to PDF, ODT, DOCX, or RTF formats. When exporting or downloading reports with Highcharts that have background images to these formats, the background image is removed from the chart. The data in the chart is not affected.
Note
JasperReports IO does not support exporting Highcharts charts with background images to PDF, ODT, DOCX, or RTF formats. When exporting or downloading reports with Highcharts that have background images to these formats, the background image is removed from the chart. The data in the chart is not affected.
To download file attachments for HTML output, use the following method. Download all attachments to display the HTML content properly. The given URL is the default path, but it can be modified with the attachmentsPrefix property in the reportExecutionRequest, as described in Running a Report Asynchronously.
Method |
URL |
||
|---|---|---|---|
GET |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/exports/exportID/attachments/fileName http://<host>:<port>/jrio/rest_v2/reportExecutions/requestID/exports/exportID/attachments/fileName |
||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content is the attachment in the format specified in the image/png |
404 Not Found – When the request ID specified in the request does not exist. |
||
For example, to download the one of the images for the HTML report execution response above, use the following URL:
Requesting Report Bookmarks¶
Some reports have additional meta-information associated with them, such as bookmarks and indexes of report sections or parts. Clients can use this information to create a table of contents for the report. The table of contents contains the links to the bookmarks and the parts defined in the report. After running a report, you can request this information using the same request ID.
Method |
URL |
||
|---|---|---|---|
GET |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/info http://<host>:<port>/jrio/rest_v2/reportExecutions/{executionId}/info |
||
Options |
Sample Response Content |
||
accept: application/json accept: application/xml |
A structure that contains bookmarks and report parts, as shown below. |
||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content contains the report meta-information, as shown below. |
404 Not Found – When the request ID specified in the request does not exist. |
||
Example of a request URL:
https://localhost:8080/jasperserver[-pro]/rest_v2/reportExecutions/70b9b169-1c0e-431c-b8bc-a6f49328bc75/info
JSON:
{
"bookmarks": {
"id": "bkmrk_1058907116",
"type": "bookmarks",
"bookmarks": [
{
"label": "USA shipments",
"pageIndex": 22,
"elementAddress": "0",
"bookmarks": [
{
"label": "Albuquerque",
"pageIndex": 22,
"elementAddress": "4",
"bookmarks": null
},
{
"label": "Anchorage",
"pageIndex": 23,
"elementAddress": "116",
"bookmarks": null
},
...
]
}
]
},
"parts": {
"id": "parts_533304192",
"type": "reportparts",
"parts": [
{
"idx": 0,
"name": "Table of Contents"
},
{
"idx": 3,
"name": "Overview"
},
{
"idx": 22,
"name": "USA shipments"
}
]
}
}
Exporting a Report Asynchronously¶
After running a report and downloading its content in a given format, you can request the same report in other formats. As with exporting report formats through the user interface, the report does not run again because the export process is independent of the report.
Method |
URL |
||
|---|---|---|---|
POST |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/exports/ http://<host>:<port>/jrio/rest_v2/reportExecutions/requestID/exports/ |
||
Content-Type |
Content |
||
application/xml application/json |
Send an Send an |
||
Options |
|||
accept: application/xml (default) accept: application/json |
|||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content contains an |
404 Not Found – When the request ID specified in the request does not exist. |
||
The following example shows the exportExecution descriptor that the server sends in response to the export request:
{
"id":"6b7ce8fa-f1d7-4d53-9af6-4569edb05d1b",
"status":"queued"
}
<exportExecution>
<id>html;attachmentsPrefix=./images/</id>
<status>ready</status>
<outputResource>
<contentType>text/html</contentType>
</outputResource>
</exportExecution>
Modifying Report Parameters¶
You can update the report parameters, also known as input controls, through a separate method before running a report execution again. For more operations with input controls, see The inputControls Service.
You can update the report parameters, also known as input controls, through a separate method before running an existing report execution again. Use the following method to rerun the report with a different set of parameter values:
Method |
URL |
||
|---|---|---|---|
POST |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/parameters http://<host>:<port>/jrio/rest_v2/reportExecutions/requestID/parameters |
||
Argument |
Type/Value |
Description |
|
freshData |
true |
When data snapshots are enabled, you must set this to true to force the server to get fresh data when you change parameters. This overrides the default value of false, as explained in the table of properties in Running a Report Asynchronously. |
|
| Media-Type | Content | ||
application/json |
|
||
| application/xml | |
||
Return Value on Success |
Typical Return Values on Failure |
||
204 No Content–There is no content to return. |
404 Not Found – When the request ID specified in the request does not exist. |
||
Polling Export Execution¶
As with the execution of the main report, you can also poll the execution of the export process. This service supports the extended status value that includes an appropriate message.
As with the execution of the main report, you can also poll the execution of the export process. This service supports the extended status value that includes an appropriate message.
Method |
URL |
||
|---|---|---|---|
GET |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/exports/ http://<host>:<port>/jrio/rest_v2/reportExecutions/requestID/exports/ |
||
Options |
Sample Return Value | ||
accept: application/xml (default) |
|
||
accept: application/status+xml |
|
||
accept: application/json |
|
||
accept: application/status+json |
|
||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content contains the export status, as shown above. In the extended format, error reports contain error messages suitable for display. |
404 Not Found – When the specified request ID does not exist. |
||
For example, to get the status of the HTML export in the previous example, use the following URL:
When the status is "ready", the client can download the new export output and any attachments as described in Requesting Report Output. For example:
Finding Running Reports and Jobs¶
The reportExecutions service provides a method to search for reports that are running on the server. It includes asynchronous reports that are still running and those that are finished but in cache and available by their request ID.
The search for reports also includes report jobs triggered by the scheduler, both running and finished but still in the cache.
To search for running or finished reports, use the search arguments with the following URL:
Method |
URL |
||
|---|---|---|---|
GET |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions?<arguments> |
||
Argument |
Type/Value |
Description |
|
reportURI |
Optional String |
This string matches the repository URI of the running report, relative to the currently logged-in user’s organization. |
|
jobID |
Optional String |
For scheduler jobs, this argument matches the ID of the job that triggered the running report. |
|
jobLabel |
Optional String |
For scheduler jobs, this argument matches the name of the job that triggered the running report. |
|
userName |
Optional String |
For scheduler jobs, this argument matches the user ID that created the job. |
|
fireTimeFrom |
Optional |
For scheduler jobs, the fire time arguments define a range of time. You can check if the current job was triggered during this time. You can specify either or both of the arguments. Specify the date and time in the following pattern: yyyy-MM-dd'T'HH:mmZ. |
|
fireTimeTo |
|||
Options |
|||
accept: application/xml (default) accept: application/json |
|||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – The content is a descriptor for each of the matching results. |
204 No Content – When the search results are empty. |
||
The response contains a list of summary reportExecution descriptors, for example in XML:
<reportExecutions>
<reportExecution>
<reportURI>repo:/supermart/details/CustomerDetailReport</reportURI>
<requestId>2071593484_1355224559918_5</requestId>
</reportExecution>
</reportExecutions>
Given the request ID, you can obtain more information about each result by downloading the full reportExecution descriptor, as described in Requesting Report Execution Details.
For security purposes, the search for running reports has the following restrictions:
- The system administrator (
superuser) can see and cancel any report running on the server. - An organization admin (
jasperadmin) can see every running report, but can cancel only the reports that were started by a user from the same or child organization. - A regular user can see every running report, but can cancel only the reports that he initiated.
Stopping Running Reports and Jobs¶
To stop a running report and cancel its output, use the PUT method and set the status as cancelled.
Method |
URL |
||
|---|---|---|---|
PUT |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID/status/ http://<host>:<port>/jrio]/rest_v2/reportExecutions/requestID/status/ |
||
Content-Type |
Content |
||
application/xml application/json |
Send a Send a XML: JSON: |
||
Options |
|||
accept: application/xml (default) accept: application/json |
|||
Return Value on Success |
Typical Return Values on Failure |
||
200 OK – When the report execution was successfully stopped, the server replies with the same status: XML: JSON: { "value": "cancelled" } 204 No Content – When the report specified by the request ID is not running, either because it finished running, failed, or was stopped by another process. |
404 Not Found – When the request ID specified in the request does not exist. |
||
Removing a Report Execution¶
Deleting a report that has run removes it from the cache and makes its output no longer available. If the report execution is still running, it is stopped automatically then removed.
Method |
URL |
||
|---|---|---|---|
DELETE |
http://<host>:<port>/jasperserver[-pro]/rest_v2/reportExecutions/requestID http://<host>:<port>/jrio/rest_v2/reportExecutions/<executionID> |
||
Return Value on Success |
Typical Return Values on Failure |
||
204 No Content – The report execution was successfully removed. |
404 Not Found – When the request ID specified in the request does not exist. |
||