trboyden Posted October 25, 2018 Posted October 25, 2018 Jasper Reports newbie here...In a nutshell, what I am looking to do is have a Jasper Report that uses json as a data source, that is passed to it at execution time, via the REST API.In more detail... The json data would come from my ERP system and would be sent to the Jasper Server as part of the web request to run the report. The output in general would be PDF, but sometimes Excel, CSV, or HTML depending on the report and the needs of the user. What are the high-level steps to do this, and can you point me in the direction of the documentation that covers each step?I have created a Jasper Report in Jaspersoft Studio, that uses a json file as its datasource via a DataAdapter. I have the Jasper Server installed and running as a Docker instance against a Mariadb cluster. Now I just need to connect the dots. The Jasper Reports server would not have direct access to the ERP system database, hence using Jasper as a web service and passing it the data I want to use in the report. Program language doesn't matter per se, but C# or Visual Basic examples would be ideal. I understand the basic concept of sending a POST request to run the report, but I don't see a way in the API that you can pass the report the data to use during execution.Thanks in advance for any assistance anyone can provide!-Tim
Solution narcism Posted October 25, 2018 Solution Posted October 25, 2018 First you should get somehow familiar with the REST API that is described here: https://community.jaspersoft.com/documentation/tibco-jasperreports-server-rest-api-reference/v710/rest-api-overviewBased on that API, there is this Java client created by Jaspersoft: https://github.com/Jaspersoft/jrs-rest-java-client. The Readme there covers a lot of topics.If you're not into a Java-based solution you could use the API directly. My answer here: https://stackoverflow.com/a/37441567/5882963 covers a similar topic to yours but starts off with how to pass XML data to sample report and then how to modify the report in order to pass JSON data.
trboyden Posted October 26, 2018 Author Posted October 26, 2018 As an update, and so hopefully Googlers can find a decent example to get themselves going, here is some example VB.Net code that works:Imports System.NetModule ModuleMain Sub Main() ' WebClient Class Implementation ' Dim wc As WebClient = New WebClient() ' Authorize the http request ' Dim cc As CredentialCache = New CredentialCache() cc.Add(New Uri("http://<JasperServerHostname>:8080/"), "Basic", New NetworkCredential("admin", "admin")) wc.Credentials = cc ' Set the base address of the Reports service ' wc.BaseAddress = "http://<JasperServerHostname>:8080/jasperserver/rest_v2/reports/" ' Create the inputControl parameter to send to JasperServer as a QueryString parameter ' Dim data As Specialized.NameValueCollection = New Specialized.NameValueCollection() data.Add("jsonString", Uri.EscapeDataString("[{""CustNum"":"" 2"",""CustSeq"":""0"",""Name"":""Coordinated Bicycles - North""}]")) wc.QueryString = data ' Setup the file to download the report to ' Dim outputBasePath As String = "\<ERPServerReportOutputDirectory>" Dim fileName As String = "CustomerReport-" & DateTime.Now.ToString("yyyyMMdd_HHmmssff") & ".pdf" ' Submit the http request and get the output resource ' wc.DownloadFile("Reports/CustomerReport.pdf", outputBasePath & fileName) ' Launch the PDF file using the default PDF viewer application ' System.Diagnostics.Process.Start(outputBasePath & fileName) End SubEnd Module[/code]Replace the values between "<Variable>" with your specific implementation configuration. As narcism mentioned, his answer, contains the information you need to setup the JasperReports jrxml file to use json as an inputControl /parameter to the report.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now