Jump to content
We've recently updated our Privacy Statement, available here ×
  • Using Data Adapters To Fill Reports With JSON Data From Remote URL


    Teodor Danciu
    • Version: v6.7 Product: JasperReports® Library

    This example shows how to use a data adapter to retrieve JSON data from a remote URL and use it to fill a report. 

    The TIBCO JasperReports® Library offers built-in support for loading report data from remote URLs through data adapters.

    Data in JSON, XML, CSV or Excel format, can be loaded from local files or from remote URLs using data adapters and it can then be parsed into records using data format specific report queries (JSON QL, XPath) and/or report field mapping metadata.

    For more details about how this sample report uses the JSONQL query language to process the incoming JSON data into data source records, please see this documentation.

    The following example shows how to retrieve data about the current status of London Tube Network stations in JSON format, from a remote public URL, and use it to generate a report.

    We first need to create a JSON data adapter file to point to this remote source of data and we are using a TIBCO Jaspersoft® Studio wizard to do so:

    captura_de_ecran_din_2018_10.04_la_10_03_49.png.e5f10e8e5609740d3b83c6d99584d06f.png

    captura_de_ecran_din_2018_10.04_la_10_05_29.png.0db064a835494948ac600267845ac9f3.png

    captura_de_ecran_din_2018_10.04_la_10_05_47.png.fb82feac1729cef53029722d175a628e.png

    captura_de_ecran_din_2018_10.04_la_10_06_53.png.f56e54e3b84f87732fd4bbdcc5ea2ee0.png

    The tubestatus.jrxml report attached to this page can be open in Jaspersoft® Studio and previewed using the above created data adapter by selecting it in the data adapter combobox at the top left corner of the report designer preview tab as see below:

    1538637088425.jpg.e0b6801b5c2e85ffb957642a4c866c0d.jpg

    For deploying this report and the data adapter to an instance of JasperReports Server, we would need to first make sure the report references the data adapter, as the preview operation did not actually link the two together.

    We are going to use a relative path to point from within the JRXML to the data adapter resource we are going to create in TIBCO JasperReports® Server. This is because the JRXML will be uploaded to a JasperReports® Server report unit, which acts itself like a subfolder containing its own resources and thus the JRXML would not be considered as being in the same folder as the data adapter resource. Use two dots to point to the data adapter resource as being in a parent repository folder as seen below:

    1538637171732.jpg.240844e01d1acba34ac7478ac8530c05.jpg

    Now let's upload the two files to JasperReports Server. We can do this using either the Web UI of the JasperReports Server instance, or, in this case, the Jaspersoft® Studio plugin.

    After having configured the connection to our JasperReports Server instance from within JasperReports Server, we create a folder called tubestatus in the Public folder of the JasperReports Server repository.

    Right click the newly created /Public/tubstatus folder and pick the New option to create a new data adapter file resource.

    captura_de_ecran_din_2018_10.04_la_11_07_57.png.c501b5d142ae3cc214d11e94e0d841c1.png

    Make sure you use the name of the XML file as the name of your data adapter resource, because this is how we referenced it from the report in a step above.

    captura_de_ecran_din_2018_10.04_la_11_08_25.png.056260a1845036a22bccb09c2776e5f3.png

    Pick the tubestatusDataAdapter.xml file from the Jaspersoft® Studio project to have it uploaded to JasperReports Server and hit Finish button.

    captura_de_ecran_din_2018_10.04_la_11_09_53.png.79c57f42f5658a52f658dad0546a58b4.png

    Let's create a report unit and upload the JRXML report template file as well.

    captura_de_ecran_din_2018_10.04_la_11_16_29.png.7f8685596a193e47277e8a495dc1610b.png

    We can give any name we want to the report unit and then pick the local JRXML file from the Jaspersoft Studio project in the workspace.

    captura_de_ecran_din_2018_10.04_la_11_17_07.png.3b5a7868863b50403bf23c5badc8a115.png

    captura_de_ecran_din_2018_10.04_la_11_18_01.png.7005c41176886a5128ac1eca30077dc9.png

    captura_de_ecran_din_2018_10.04_la_11_17_31.png.1ccd6a6f42c0f5e7b126b988b7ad66b0.png

    We don't need to specify any data source for this report unit as the data adapter property we set previously in the JRXML report template itself is enough to connect our report to the remote URL from where the JSON data will be read and then processed.

    captura_de_ecran_din_2018_10.04_la_11_18_19.png.fd7c205137b4fdf2a6ba206fba78d497.png

    After the report unit has been created, we can use the JasperReports Server Web UI to navigate to the repository folder where we uploaded it and run it.

    captura_de_ecran_din_2018_10.04_la_11_19_34.png.3c88bf74f5fc99dff6a35f5587a97c4a.png

    captura_de_ecran_din_2018_10.04_la_12_29_44.png.ec0d17f9023eca978c2190f17017c79c.png

     

    captura_de_ecran_din_2018_10.04_la_10_03_49.png.da17bad0008799b74320e8dd4c4bd3d2.png

    captura_de_ecran_din_2018_10.04_la_10_05_29.png.af9c3cee8f7bc4380eeb7d4b4d4391a1.png

    captura_de_ecran_din_2018_10.04_la_10_05_47.png.4f736209598063b78a8e86304557ff26.png

    captura_de_ecran_din_2018_10.04_la_10_06_53.png.6c3ab0a42490b3e331fc6606220b6013.png

    1538637088425.jpg.a257696fe3a4120362dbc6f55b7d42e3.jpg

    1538637171732.jpg.34e4eeb77580a91fa47557781709248b.jpg

    captura_de_ecran_din_2018_10.04_la_11_07_57.png.d284109f01b972b91c3d3394c00bf381.png

    captura_de_ecran_din_2018_10.04_la_11_08_25.png.1e0bc4733669a1e63f6b5dd2347c5cb3.png

    captura_de_ecran_din_2018_10.04_la_11_09_53.png.79efb797880722f304df0fff9ddfb12a.png

    captura_de_ecran_din_2018_10.04_la_11_16_29.png.db42fd8d5de40eb82302392eb91a933a.png

    captura_de_ecran_din_2018_10.04_la_11_17_07.png.f8c4ab5b080e41d8e084b12fcc7fe577.png

    captura_de_ecran_din_2018_10.04_la_11_18_01.png.876b72c9e562f612347bb7fc4569fdaf.png

    captura_de_ecran_din_2018_10.04_la_11_17_31.png.8e0034298425f6326b132ee96f3875b5.png

    captura_de_ecran_din_2018_10.04_la_11_18_19.png.654ad1ee0754c64532226d0ff65e94bb.png

    captura_de_ecran_din_2018_10.04_la_11_19_34.png.42f2ff23eeda31c3d5f0f975a2964418.png

    captura_de_ecran_din_2018_10.04_la_12_29_44.png.160fcd367f75580f09bfeb531fe958a1.png

    tubestatus_0.jrxml

    tubestatusdataadapter.xml


    User Feedback

    Recommended Comments

    I had to use the repo:-Syntax and full path, to make it work on the server. Therefore I had to change the Adapter-Line of Main_jrxml.jrxml after publishing. My uploaded Json adapter file to the /public/-repo is named jsonAdapter.xml.

    Main_jrxml.jrxml:

    <property name="net.sf.jasperreports.data.adapter" value="repo:/public/jsonAdapter.xml"/>

     

    Link to comment
    Share on other sites



    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 account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...