JasperReportsIntegration icon indicating copy to clipboard operation
JasperReportsIntegration copied to clipboard

How to call report that have data sources other than jdbc

Open hossam-houssien opened this issue 4 years ago • 1 comments

some times we need to have json or xml data source into jasper report, which we can do, however we can't find a way to call such report from JasperReportsIntegration

here is an example report

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1  -->
<!-- 2021-12-04T15:26:50 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test_report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="98889269-bf0b-444b-a9c1-a9f30e5c8f0c">
	<parameter name="jsonSource" class="java.lang.String">
		<defaultValueExpression><![CDATA["test.json"]]></defaultValueExpression>
	</parameter>
	<parameter name="net.sf.jasperreports.json.source" class="java.lang.String" isForPrompting="false">
		<defaultValueExpression><![CDATA[$P{jsonSource}]]></defaultValueExpression>
	</parameter>
	<queryString language="json">
		<![CDATA[]]>
	</queryString>
	<field name="name" class="java.lang.String">
		<fieldDescription><![CDATA[name]]></fieldDescription>
	</field>
	<field name="age" class="java.lang.Integer">
		<fieldDescription><![CDATA[age]]></fieldDescription>
	</field>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="79" splitType="Stretch"/>
	</title>
	<pageHeader>
		<band height="35" splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band height="30" splitType="Stretch">
			<staticText>
				<reportElement x="96" y="0" width="100" height="30" uuid="1b785850-7e9b-4420-9f1b-d79610c5756a"/>
				<box>
					<topPen lineWidth="0.3"/>
					<leftPen lineWidth="0.3"/>
					<bottomPen lineWidth="0.3"/>
					<rightPen lineWidth="0.3"/>
				</box>
				<textElement textAlignment="Center">
					<paragraph leftIndent="3"/>
				</textElement>
				<text><![CDATA[name]]></text>
			</staticText>
			<staticText>
				<reportElement x="196" y="0" width="100" height="30" uuid="65c2f606-89c9-43a1-9b95-5977bc7ecd02"/>
				<box>
					<topPen lineWidth="0.3"/>
					<leftPen lineWidth="0.3"/>
					<bottomPen lineWidth="0.3"/>
					<rightPen lineWidth="0.3"/>
				</box>
				<textElement textAlignment="Center">
					<paragraph leftIndent="3"/>
				</textElement>
				<text><![CDATA[age]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="54" splitType="Stretch">
			<textField>
				<reportElement x="96" y="0" width="100" height="30" uuid="8eb6281f-de86-4063-ac67-7f16e09cf560"/>
				<box>
					<topPen lineWidth="0.3"/>
					<leftPen lineWidth="0.3"/>
					<bottomPen lineWidth="0.3"/>
					<rightPen lineWidth="0.3"/>
				</box>
				<textElement>
					<paragraph leftIndent="3"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="196" y="0" width="100" height="30" uuid="19c48cd6-392d-4859-b02e-69643b9b25fd"/>
				<box>
					<topPen lineWidth="0.3"/>
					<leftPen lineWidth="0.3"/>
					<bottomPen lineWidth="0.3"/>
					<rightPen lineWidth="0.3"/>
				</box>
				<textElement>
					<paragraph leftIndent="3"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{age}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band height="45" splitType="Stretch"/>
	</columnFooter>
	<pageFooter>
		<band height="54" splitType="Stretch"/>
	</pageFooter>
	<summary>
		<band height="42" splitType="Stretch"/>
	</summary>
</jasperReport>

in above example there is variable $P{jsonSource} which have a default value for a path of a .json file like test.json

the data in json file (for the example) is

{
"name":"hossam",
"id":45
}

when we run this example in jasperdoft studio v6.1.1, it works fine.

we can't find a way to deploy it to JasperReportsIntegration (in reports dir) , each time we try to call it from the test page (removing the datasource name value) it gives:-

Could not connect via JDBC: IO Error: The Network Adapter could not establish the connection

Is there any way to bypass the name of the data source, so it pick up the provided in report? or is there a way to configure and use another data source type?

we are using JasperReportsIntegration v 2.4.0.0

hossam-houssien avatar Dec 04 '21 14:12 hossam-houssien

Interesting.

This use case was never intended. The main use case is to use an Oracle database connection. But you can also connect to any JNDI data source, here you can connect to other (mostly) sql databases. You configure that directly in Tomcat.

In your case I would probably:

  • set up a dummy Oracle connection with a query like select null from dual or something similar.
  • create a second data source in the same report and use $P{jsonSource} as the data source there.

image

Something along those lines.

The use case is interesting, I like the idea of passing the data via xml or json directly to the report engine.

daust avatar Dec 16 '21 17:12 daust