Jasper Report how to get a sibling node with parameter of another sibling? - xpath

I am working on a new Jaspert Report. It should print all data of a xml text.
The xml text looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<invoice:invoiceMessage>
<invoice>
<invoiceIdentification></invoiceIdentification>
<seller>
<address>
<name></name>
<city></city>
<cityCode></cityCode>
</address>
</seller>
</invoice>
</invoice:invoiceMessage>
And the Jasper Report looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.1.0.final using JasperReports Library version 6.4.3 -->
<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="main_report_xml1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="24a4119c-6e8f-4411-bbb5-c069ab379330">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="ireport.jasperserver.url" value="http://10.100.10.236/jasperserver-pro/"/>
<property name="ireport.jasperserver.user" value="reko"/>
<property name="ireport.jasperserver.reportUnit" value="/Reko/main_report_xml1"/>
<subDataset name="pageHeader" uuid="cf87fcbb-cbcd-4c3b-bf87-3cf147854adb">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<queryString language="xPath">
<![CDATA[//seller/address]]]>
</queryString>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="name"/>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="streetAdressOne" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="streetAdressOne"/>
<fieldDescription><![CDATA[streetAdressOne]]></fieldDescription>
</field>
<field name="cityCode" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="cityCode"/>
<fieldDescription><![CDATA[cityCode]]></fieldDescription>
</field>
<field name="city" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="city"/>
<fieldDescription><![CDATA[city]]></fieldDescription>
</field>
</subDataset>
<parameter name="xmlString" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA[xmlText]]></defaultValueExpression>
</parameter>
<parameter name="XML_INPUT_STREAM" class="java.io.InputStream">
<defaultValueExpression><![CDATA[new java.io.ByteArrayInputStream($P{xmlString}.getBytes("ISO-8859-1"))]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[/invoiceMessage/invoice[invoiceIdentification/entityIdentification=9000009029]]]>
</queryString>
<field name="value" class="java.lang.String">
<fieldDescription><![CDATA[creationDateTime]]></fieldDescription>
</field>
<pageHeader>
<band height="38"/>
</pageHeader>
<columnHeader>
<band height="31" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="488" splitType="Stretch">
<componentElement>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="21" width="552" height="30" isRemoveLineWhenBlank="true" uuid="fc7d22c7-8c60-4ecb-974f-c842becc4bf7"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="pageHeader" uuid="1e20fa2b-bb3a-475f-b721-5a13d3c374eb">
<datasetParameter name="XML_DATE_PATTERN">
<datasetParameterExpression><![CDATA[$P{XML_DATE_PATTERN}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_NUMBER_PATTERN">
<datasetParameterExpression><![CDATA[$P{XML_NUMBER_PATTERN}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_LOCALE">
<datasetParameterExpression><![CDATA[$P{XML_LOCALE}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_TIME_ZONE">
<datasetParameterExpression><![CDATA[$P{XML_TIME_ZONE}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//*[entityIdentification=9000009029]/parent::*/seller")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30">
<textField isStretchWithOverflow="true">
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="552" height="15" uuid="eac696b9-e20f-48a3-b70d-b186f5e649d6"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
</jasperReport>
My question is:
What should my dataSourceExpression in the componentElement be, so I can get the data out of it?
I also have some data in the invoice node that I need to show and thats why i set it like this in the query string. And I need to filter by the parameter that is stored inside of invoiceIdentification node.

Related

How to fix "Field not found" error in case using two XPath expressions in single report?

I've been struggling with my problem since 7 days.
I have 1 XML input data and want to convert that into desired PDF file with line chart
XML
<?xml version="1.0" encoding="utf-8"?>
<sample-data xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:ht="urn:xyz.com/xslt/extensions">
<section name="relative-performance">
<historic-valuations>
<valuation-list>
<valuation>
<value>890000</value>
<date>2014-12-01T00:00:00</date>
</valuation>
<valuation>
<value>923789</value>
<date>2015-12-01T00:00:00</date>
</valuation>
<valuation>
<value>897978</value>
<date>2016-12-01T00:00:00</date>
</valuation>
<valuation>
<value>957883</value>
<date>2017-12-01T00:00:00</date>
</valuation>
<valuation>
<value>919203</value>
<date>2018-12-01T00:00:00</date>
</valuation>
<valuation>
<value>950000</value>
<date>2019-12-01T00:00:00</date>
</valuation>
</valuation-list>
</historic-valuations>
<local-market-index>
<local-market>HA7 3</local-market>
<index-value-list>
<index-value>
<value>890000</value>
<date>2014-12-01T00:00:00</date>
</index-value>
<index-value>
<value>931069</value>
<date>2015-12-01T00:00:00</date>
</index-value>
<index-value>
<value>912244</value>
<date>2016-12-01T00:00:00</date>
</index-value>
<index-value>
<value>980893</value>
<date>2017-12-01T00:00:00</date>
</index-value>
<index-value>
<value>948882</value>
<date>2018-12-01T00:00:00</date>
</index-value>
<index-value>
<value>988654</value>
<date>2019-12-01T00:00:00</date>
</index-value>
</index-value-list>
</local-market-index>
</section>
</sample-data>
My JRXML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.11.0.final using JasperReports Library version 6.11.0-0c4056ccaa4d25a5a8c45672d2f764ea3498bebb -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f3e693aa-b906-4972-95b4-4a7430cabd45">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="NewData"/>
<subDataset name="subData" uuid="87538cc6-4a9e-4953-acaa-3190030517a8">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="NewData"/>
<queryString language="xPath">
<![CDATA[/sample-data/section[#name='relative-performance']/historic-valuations/valuation-list/valuation]]>
</queryString>
<field name="value" class="java.lang.Integer">
<property name="net.sf.jasperreports.xpath.field.expression" value="value"/>
<fieldDescription><![CDATA[value]]></fieldDescription>
</field>
<field name="date" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="date"/>
<fieldDescription><![CDATA[date]]></fieldDescription>
</field>
</subDataset>
<queryString language="xPath">
<![CDATA[/sample-data/section[#name='relative-performance']/local-market-index/index-value-listindex-value]]>
</queryString>
<field name="value1" class="java.lang.Integer">
<property name="net.sf.jasperreports.xpath.field.expression" value="value1"/>
<fieldDescription><![CDATA[value]]></fieldDescription>
</field>
<field name="date1" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="date1"/>
<fieldDescription><![CDATA[date]]></fieldDescription>
</field>
<detail>
<band height="370" splitType="Stretch">
<lineChart>
<chart evaluationTime="Report">
<reportElement x="0" y="40" width="550" height="290" uuid="9bdc21fd-9b73-4ea9-919e-2c8807153f78"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset resetType="Report"/>
<categorySeries>
<seriesExpression><![CDATA["Estimated capital value"]]></seriesExpression>
<categoryExpression><![CDATA[$F{date}]]></categoryExpression>
<valueExpression><![CDATA[$F{value}]]></valueExpression>
<labelExpression><![CDATA[""]]></labelExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Local market index"]]></seriesExpression>
<categoryExpression><![CDATA[$F{date1}]]></categoryExpression>
<valueExpression><![CDATA[$F{value1}]]></valueExpression>
<labelExpression><![CDATA[""]]></labelExpression>
</categorySeries>
</categoryDataset>
<linePlot>
<plot/>
<categoryAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat labelColor="#000000" tickLabelColor="#000000" axisLineColor="#000000"/>
</valueAxisFormat>
</linePlot>
</lineChart>
</band>
</detail>
</jasperReport>
I searched a lot and come to know that In my situation I need to make subDataSource so I did from
How to use multiple xpath datasets on XML datasource using PHP Jasper?
But I'm still getting this error
There are compilation error please fix the design
Field not found:date ---net.sf.jasperreports.xpath.field.expression#95d1b2c
Field not found:date ---net.sf.jasperreports.xpath.field.expression#62032410
I want to make line chart in jasper report then make it pdf in java which is another part but main issue is I'm not able to make a desired PDF which is

jpos Gateway : Not able to send back the response message received from the remote host to the client requested

I am new to jpos. trying to use jpos-2_1_3 out of the box. I can see the message forwarded to remote host and response back but the response message is not delivered to the requested client.Getting the below error
[HOST_UNREACHABLE] o.j.t.p.QueryHost.expired:111 'mux.rsc' does not respond
I checked the client status which is connected and waiting for the response
My config files are as below
50_server.xml
<server class="org.jpos.q2.iso.QServer" logger="Q2" name="bnet-server-7003" realm="bnet-server-8000">
<attr name="port" type="java.lang.Integer">6003</attr>
<channel class="org.jpos.iso.channel.NACChannel"
packager="org.jpos.iso.packager.GenericPackager"
type="server"
logger="Q2"
header="6000000000"
>
<property name="packager-config" value="cfg/packager/CISebcdic.xml" debug="True" />
<property name="timeout" value="18000"/>
</channel>
<request-listener class="org.jpos.iso.IncomingListener" logger="Q2" realm="incoming-request-listener">
<property name="space" value="tspace:default" />
<property name="queue" value="RSCTXNMGR" />
<property name="ctx.DESTINATION" value="rsc" />
</request-listener>
</server>
10_channel.xml
<?xml version="1.0" ?>
<channel-adaptor name='rsc-channel' class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
<channel class="org.jpos.iso.channel.BCDChannel"
packager="org.jpos.iso.packager.GenericPackager" header="6000000000" logger="Q2" >
<property name="packager-config" value="cfg/packager/CISascii.xml" debug="True" />
<property name="host" value="127.0.0.1" />
<property name="port" value="9000" />
<property name="keep-alive" value="true" />
</channel>
<in>rscbnet-send</in>
<out>rscbnet-receive</out>
<reconnect-delay>10000</reconnect-delay>
</channel-adaptor>
20_mux.xml
<?xml version="1.0" ?>
<mux class="org.jpos.q2.iso.QMUX" logger="Q2" name="rsc">
<in>rscbnet-receive</in>
<out>rscbnet-send</out>
<ready>rsc-channel.ready</ready>
<key>41,11</key>
<unhandled>rsc-channel-unhandled</unhandled>
</mux>
30_txnmgr.xml
<?xml version='1.0'?>
<txnmgr class="org.jpos.transaction.TransactionManager" logger="Q2">
<property name="queue" value="RSCTXNMGR"/>
<property name="sessions" value="10"/>
<property name="max-sessions" value="128"/>
<property name="debug" value="true"/>
<participant class="org.jpos.transaction.participant.QueryHost" logger="Q2"/>
<participant class="org.jpos.transaction.participant.SendResponse" logger="Q2" />
</txnmgr>
in the log i can see message is send to the remote host and response is received
<log realm="channel/127.0.0.1:9000" at="2020-02-22T17:11:39.114">
<send>
<isomsg direction="outgoing">
<!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISascii.xml] -->
<header>6000000000</header>
<field id="0" value="0400"/>
<field id="2" value="4113550001234586"/>
<field id="3" value="003000"/>
<field id="4" value="000000005000"/>
<field id="7" value="0218135108"/>
<field id="11" value="570164"/>
<field id="12" value="005106"/>
<field id="13" value="0219"/>
<field id="14" value="1906"/>
<field id="18" value="7399"/>
<field id="22" value="812"/>
<field id="32" value="001529"/>
<field id="33" value="004601"/>
<field id="37" value="702011961044"/>
<field id="39" value="00"/>
<field id="41" value="W1Q99999"/>
<field id="42" value="25233065 "/>
<field id="43" value="Apple NZ GCS Sydney AU"/>
<field id="48" value="543432303730313033323130363331355649533237333634353032313920203230303153" type="binary"/>
<field id="49" value="036"/>
<field id="61" value="10251040066000362000"/>
<field id="90" value="010057016402181351080000000152900000004601"/>
</isomsg>
</send>
</log>
<log realm="channel/127.0.0.1:9000" at="2020-02-22T17:11:39.115" lifespan="179071ms">
<receive>
<isomsg direction="incoming">
<!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISascii.xml] -->
<header>6000000000</header>
<field id="0" value="0410"/>
<field id="2" value="4113550001234586"/>
<field id="3" value="003000"/>
<field id="4" value="000000005000"/>
<field id="7" value="0221223852"/>
<field id="11" value="620156"/>
<field id="12" value="093850"/>
<field id="13" value="0222"/>
<field id="14" value="1906"/>
<field id="18" value="7399"/>
<field id="22" value="812"/>
<field id="32" value="001529"/>
<field id="33" value="004601"/>
<field id="37" value="702011079220"/>
<field id="39" value="00"/>
<field id="41" value="W1Q99999"/>
<field id="42" value="25233065 "/>
<field id="43" value="Apple NZ GCS Sydney AU"/>
<field id="48" value="543432303730313033323130363331353030303030303030303030303020203230303153" type="binary"/>
<field id="49" value="036"/>
<field id="61" value="10251040066000362000"/>
<field id="90" value="010062015602212238520000000152900000004601"/>
</isomsg>
</receive>
</log>
<log realm="org.jpos.transaction.TransactionManager" at="2020-02-22T17:12:09.115" lifespan="30001ms">
<abort>
txnmgr-9:idle:2
<context>
TIMESTAMP: Sat Feb 22 17:11:39 AEDT 2020
SOURCE: org.jpos.iso.channel.NACChannel#795c411
REQUEST:
<isomsg direction="outgoing">
<!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISascii.xml] -->
<header>6000000000</header>
<field id="0" value="0400"/>
<field id="2" value="4113550001234586"/>
<field id="3" value="003000"/>
<field id="4" value="000000005000"/>
<field id="7" value="0218135108"/>
<field id="11" value="570164"/>
<field id="12" value="005106"/>
<field id="13" value="0219"/>
<field id="14" value="1906"/>
<field id="18" value="7399"/>
<field id="22" value="812"/>
<field id="32" value="001529"/>
<field id="33" value="004601"/>
<field id="37" value="702011961044"/>
<field id="39" value="00"/>
<field id="41" value="W1Q99999"/>
<field id="42" value="25233065 "/>
<field id="43" value="Apple NZ GCS Sydney AU"/>
<field id="48" value="543432303730313033323130363331355649533237333634353032313920203230303153" type="binary"/>
<field id="49" value="036"/>
<field id="61" value="10251040066000362000"/>
<field id="90" value="010057016402181351080000000152900000004601"/>
</isomsg>
DESTINATION: rsc
**RESULT:
<result>
<fail>
[HOST_UNREACHABLE] o.j.t.p.QueryHost.expired:111 'mux.rsc' does not respond
</fail>
</result>**
:paused_transaction:
id: 2
</context>
prepare: o.j.t.p.QueryHost PREPARED PAUSE READONLY NO_JOIN
prepare: o.j.t.p.SendResponse ABORTED READONLY NO_JOIN
in-transit=0, head=3, tail=3, paused=0, outstanding=0, active-sessions=10/128, tps=0, peak=1, avg=0.00, elapsed=30001ms
<profiler>
prepare: o.j.t.p.QueryHost [0.3/0.3]
resume [30000.5/30000.8]
prepare: o.j.t.p.SendResponse [0.1/30001.0]
end [1.1/30002.2]
</profiler>
</abort>
</log>
<log realm="Q2.system" at="2020-02-22T17:12:43.242">
it will be great if i get some help to solve this issue.thanks in advance.
To summarize in an answer what was explained in comments, problem was field 11 not being matched by response. Because of that the mux didn't know that the incoming message was a response for the request.
You can see default fields used to match responses to requests by QMUX, and learn how to configure a different set of keys in jPOS programmers guide section 8.3.2

Passing a bearer token in a 'Web Test' without Visual Studio?

I want to import a ".webtest" in Azure's Application Insights availability feature. I dont have a test edition of Visual Studio, but this MSDN article suggests using Fiddler as another option to creating web tests.
I need to perform 2 requests on a REST API:
Request a bearer token from the connect/token endpoint.
Perform a GET at api/resources with the bearer token (retrieved from the above request) in the header.
It's a typical client credentials OAuth 2 flow.
I cannot seem to figure out how to do this with Fiddler. Basically I need to extract a value from the response body of request 1 and use it as the header value in request 2.
This is what the web test looks like without passing the token:
<?xml version="1.0" encoding="utf-8"?>
<TestCase Name="FiddlerGeneratedWebTest" Id="" Owner="" Description="" Priority="0" Enabled="True" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="" RequestCallbackClass="" TestCaseCallbackClass="">
<Items>
<Request Method="POST" Version="1.1" Url="https://example.com/connect/token" ThinkTime="8" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8">
<Headers>
<Header Name="Content-Type" Value="application/x-www-form-urlencoded" />
</Headers>
<FormPostHttpBody ContentType="application/x-www-form-urlencoded">
<FormPostParameter Name="client_id" Value="myclientid" UrlEncode="True" />
<FormPostParameter Name="client_secret" Value="password123" UrlEncode="True" />
<FormPostParameter Name="grant_type" Value="client_credentials" UrlEncode="True" />
<FormPostParameter Name="scope" Value="myscopes" UrlEncode="True" />
</FormPostHttpBody>
</Request>
<Request Method="GET" Version="1.1" Url="https://example.com/api/resources" ThinkTime="0" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8">
<Headers>
<Header Name="Authorization" Value="Bearer {{token}}" />
</Headers>
</Request>
</Items>
</TestCase>
Assuming this comes back as the following example you can use a regex extraction to get it.
{"token_type":"Bearer","scope":"user_impersonation","expires_in":"3600 ... "access_token":"{{TOKEN}}", ...}
<?xml version="1.0" encoding="utf-8"?>
<TestCase Name="FiddlerGeneratedWebTest" Id="" Owner="" Description="" Priority="0" Enabled="True" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="" RequestCallbackClass="" TestCaseCallbackClass="">
<Items>
<Request Method="POST" Version="1.1" Url="https://example.com/connect/token" ThinkTime="8" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8">
<ExtractionRules>
<ExtractionRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractRegularExpression, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" VariableName="token" DisplayName="Extract Regular Expression" Description="Extract text from the response matching a regular expression and place it into the test context.">
<RuleParameters>
<RuleParameter Name="RegularExpression" Value=".*"access_token":"([^"]*)".*" />
<RuleParameter Name="IgnoreCase" Value="True" />
<RuleParameter Name="Required" Value="True" />
<RuleParameter Name="Index" Value="0" />
<RuleParameter Name="HtmlDecode" Value="True" />
<RuleParameter Name="UseGroups" Value="True" />
</RuleParameters>
</ExtractionRule>
</ExtractionRules>
<Headers>
<Header Name="Content-Type" Value="application/x-www-form-urlencoded" />
</Headers>
<FormPostHttpBody ContentType="application/x-www-form-urlencoded">
<FormPostParameter Name="client_id" Value="myclientid" UrlEncode="True" />
<FormPostParameter Name="client_secret" Value="password123" UrlEncode="True" />
<FormPostParameter Name="grant_type" Value="client_credentials" UrlEncode="True" />
<FormPostParameter Name="scope" Value="myscopes" UrlEncode="True" />
</FormPostHttpBody>
</Request>
<Request Method="GET" Version="1.1" Url="https://example.com/api/resources" ThinkTime="0" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8">
<Headers>
<Header Name="Authorization" Value="Bearer {{token}}" />
</Headers>
</Request>
</Items>
</TestCase>
To compliment James Davis's answer, if you need to login to https://yourapp.com/auth/login by posting the JSON:
{
user: 'youruser',
password: 'yourpassword'
}
first base64 encode the json:
> echo "{user: 'youruser', password: 'yourpassword'}" | base64
e3VzZXI6ICd5b3VydXNlcicsIHBhc3N3b3JkOiAneW91cnBhc3N3b3JkJ30K
Then pass this base64 value in a StringHttpBody tag
<?xml version="1.0" encoding="utf-8"?>
<WebTest Name="login-healthcheck" Id="e91b6e1d-3fa0-475f-a18b-b694b463589c" Owner="" Priority="0" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale="">
<Items>
<Request Method="POST" Guid="ef9d1d00-5663-476a-a3cb-ccf49c4d2229" Version="1.1" Url="https://yourapp.com/auth/login" ThinkTime="8" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
<Headers>
<Header Name="Content-Type" Value="application/json" />
</Headers>
<ExtractionRules>
<ExtractionRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractRegularExpression, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" VariableName="token" DisplayName="Extract Regular Expression" Description="Extract text from the response matching a regular expression and place it into the test context.">
<RuleParameters>
<RuleParameter Name="RegularExpression" Value=".*"access_token":"([^"]*)".*" />
<RuleParameter Name="IgnoreCase" Value="True" />
<RuleParameter Name="Required" Value="True" />
<RuleParameter Name="Index" Value="0" />
<RuleParameter Name="HtmlDecode" Value="True" />
<RuleParameter Name="UseGroups" Value="True" />
</RuleParameters>
</ExtractionRule>
</ExtractionRules>
<StringHttpBody ContentType="application/json" InsertByteOrderMark="False">e3VzZXI6ICd5b3VydXNlcicsIHBhc3N3b3JkOiAneW91cnBhc3N3b3JkJ30K</StringHttpBody>
</Request>
<Request Method="GET" Guid="d566422f-af74-47bf-90aa-0c66db6ef567" Version="1.1" Url="https://yourapp.com/api/v1/healthcheck" ThinkTime="0" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
<Headers>
<Header Name="Authorization" Value="Bearer {{token}}" />
</Headers>
</Request>
</Items>
</WebTest>
Worked for me on Azure Application Insights Availability checking

Spring Batch Integration with BeanIO

I am trying to integrate BeanIO with spring batch. Using BeanIO I am reading a fixed length stream file. I have tested and verified the code to read the flat file using a standalone class and it works seamlessly but when I tried to integrate it with Spring Batch the doRead() method of BeanIOFlatFileItemReader is not getting invoked and some how directly the RedemptionEventCustomProcessor written by me is getting invoked.
I get below stacktrace on console.:
:::::::::::::In Processor::::::::::::::::
Exit Status : FAILED job Id 0 [java.lang.NullPointerException]
Done
Please find the dependencies used below:
spring-batch-core version 2.1.9.RELEASE
spring-batch-infrastructure 2.1.9.RELEASE
beanio-2.1.0.M2
Please find below the resources files as mentioned below:
earn-api-batch - spring batch xml file
earn-api-batch-context - spring batch context xml file
earn-api-mapping.xml - BeanIO mapping xml file
earn-api-batch.xml:
<import resource="classpath:earn-api-batch-context.xml" />
<batch:job id="processEventJob">
<batch:step id="step">
<batch:tasklet>
<batch:chunk reader="RedemptionFileReader" writer="RedemptionEventCustomWriter" processor="RedemptionEventCustomProcessor" commit-interval="1"></batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="RedemptionFileReader" class="org.beanio.spring.BeanIOFlatFileItemReader">
<property name="streamMapping" value="classpath:/earn-api-mapping.xml" />
<property name="streamName" value="redemptionFile" />
<property name="resource" value="classpath:/RedemptionTest" />
</bean>
<bean id="RedemptionEventCustomWriter" class="org.beanio.spring.BeanIOFlatFileItemWriter">
<property name="streamMapping" value="classpath:/earn-api-mapping.xml" />
<property name="streamName" value="redemptionFile" />
<property name="resource" value="file:Redemption.txt" />
</bean>
earn-api-batch-context:
<context:component-scan base-package="com.aexp.earn.api.batch" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository">
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
</constructor-arg>
</bean>
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
earn-api-mapping.xml:
<beanio xmlns="http://www.beanio.org/2012/03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org /2012/03/mapping.xsd">
<stream name="redemptionFile" format="fixedlength">
<!-- 'class' binds the header record to a java.util.HashMap -->
<record name="header" class="map">
<!-- 'rid' indicates this field is used to identify the record -->
<field name="recordType" length="1" rid="true" literal="1" />
<field name="fileSeqNo" length="10" padding=" " justify="right" />
<!-- 'format' can be used to provide Date and Number formats -->
<field name="fileDate" length="8" type="date" format="yyyyMMdd" />
</record>
<record name="nar" class="com.aexp.earn.api.batch.vo.NonAirline">
<field name="recordType" length="1" ignore="true" />
<field name="redeemType" rid="true" literal="1" length="1" />
<field name="mmNo" length="10" />
<field name="cmNo" length="19" padding=" " justify="right" />
<field name="rewardProgCode" length="2" padding="0" justify="right" />
<field name="certNo" length="10"/>
<field name="certFaceValue" length="13" padding=" " justify="right" />
<field name="redeemTimeStamp" length="26" />
<field name="statusCode" length="2" />
<field name="statusTimeStamp" length="26" />
<field name="rewardCode" length="4" />
<field name="rewardSubCode" length="4" />
<field name="transId" length="15" />
<field name="transSrcId" length="3" />
<field name="narRequestId" length="14" />
<field name="narRequestLnId" length="5" padding=" " justify="right" />
</record>
<record name="ar" class="com.aexp.earn.api.batch.vo.Airline">
<field name="recordType" length="1" ignore="true" />
<field name="redeemType" rid="true" literal="2" length="1" />
<field name="partnerTransferType" length="1" />
<field name="mmNo" length="10" />
<field name="cmNo" length="19" padding=" " justify="right" />
<field name="rewardProgCode" length="2" />
<field name="frequentFlyerNo" length="15" />
<field name="partnerCode" length="2"/>
<field name="redeemTimeStamp" length="26" />
<field name="transferedMiles" length="12" padding=" " justify="right" />
<field name="transferedStatus" length="1" />
<field name="statusTimeStamp" length="26" />
<field name="originSourceCode" length="3" />
<field name="transId" length="15" />
<field name="transSrcId" length="3" />
<field name="arRequestId" length="14" />
<field name="arRequestLnId" length="5" padding=" " justify="right" />
</record>
<record name="pwp" class="com.aexp.earn.api.batch.vo.PWP">
<field name="recordType" length="1" ignore="true" />
<field name="redeemType" rid="true" literal="3" length="1" />
<field name="mmNo" length="10" />
<field name="cmNo" length="19" padding=" " justify="right" />
<field name="rewardProgCode" length="2" />
<field name="redeemTimeStamp" length="26" />
<field name="adjustMiles" length="12" />
<field name="adjustCD" length="4" />
<field name="transId" length="15" />
<field name="transSrcId" length="3" />
<field name="pwpRequestId" length="14" padding=" " justify="right" />
<field name="pwpRequestLnId" length="5" />
</record>
<record name="pap" class="com.aexp.earn.api.batch.vo.PAP">
<field name="recordType" length="1" ignore="true" />
<field name="redeemType" rid="true" literal="4" length="1" />
<field name="mmNo" length="10" />
<field name="cmNo" length="19" padding=" " justify="right" />
<field name="rewardProgCode" length="2" />
<field name="redeemTimeStamp" length="26" />
<field name="chnlPtnrId" length="5" />
<field name="orderId" length="32" />
<field name="partnerReserId" length="32" />
<field name="confirmId" length="16" padding=" " justify="right" />
<field name="actPtCnt" length="12" />
<field name="rewdActTypeCd" length="3" />
<field name="seqNo" length="5" />
</record>
<!-- 'target' binds the trailer record to the Integer record count field -->
<record name="trailer" target="recordCount">
<!-- 'literal' is used to define constant values -->
<field name="recordType" rid="true" literal="9" length="2" />
<!-- 'type' can be declared where bean introspection is not possible -->
<field name="recordCount" length="7" type="int" />
</record>
</stream>
</beanio>
Find below the classes:
Main class:
public class EventStart {
#SuppressWarnings("resource")
public static void main(String[] args) {
String[] springConfig =
{
"earn-api-batch.xml"
};
ClassPathXmlApplicationContext appContext = null;
appContext = new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) appContext.getBean("jobLauncher");
Job job = (Job) appContext.getBean("processEventJob");
try {
JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Exit Status : " + execution.getStatus() + " job Id " + execution.getJobId() + " " + execution.getAllFailureExceptions());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
}
}
Reader Class:
#Component(value = "RedemptionFileReader")
#Scope("step")
public class RedemptionFileReader extends BeanIOFlatFileItemReader<Map<String,Object>>{
/* #Value("#{batchProps['redemption.server.file.path']}")
private Resource resource;*/
Map<String,Object> map = new HashMap<String,Object>();
/*#Override
public String read() throws Exception, UnexpectedInputException,
ParseException, NonTransientResourceException {
System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
// TODO Auto-generated method stub
return null;
}*/
#Override
public Map<String,Object> doRead() throws Exception, UnexpectedInputException,
ParseException, NonTransientResourceException {
System.out.println("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
/*if (null != recordsCount) {
return null;
}*/
map = identifyRecord();
return map;
}
private Map<String,Object> identifyRecord() throws FileNotFoundException {
Map<String,Object> map=new HashMap<String,Object>();
ArrayList<NonAirline> narList = new ArrayList<NonAirline>();
ArrayList<Airline> arList = new ArrayList<Airline>();
ArrayList<PWP> pwpList = new ArrayList<PWP>();
ArrayList<PAP> papList = new ArrayList<PAP>();
// create a StreamFactory
StreamFactory factory = StreamFactory.newInstance();
// load the mapping file
factory.load("src/main/resources/earn-api-mapping.xml");
// use a StreamFactory to create a BeanReader
BeanReader in = factory.createReader("redemptionFile", new File("src/main/resources/RedemptionTest"));
Object record = null;
String recordCount = "";
while ((record = in.read()) != null) {
if ("header".equals(in.getRecordName())) {
//Map<String,Object> header = (Map<String,Object>) record;
//System.out.println(header.get("fileDate"));
System.out.println("Header");
}
else if ("nar".equals(in.getRecordName())) {
NonAirline nar = (NonAirline) record;
System.out.println("NAR Redeem Type: " + nar.getRedeemType());
System.out.println("NAR MM No.: " + nar.getMmNo());
System.out.println("NAR CM No.: " + nar.getCmNo());
narList.add(nar);
}
else if ("ar".equals(in.getRecordName())) {
Airline ar = (Airline) record;
System.out.println("AR Redeem Type: " + ar.getRedeemType());
System.out.println("AR MM No.: " + ar.getMmNo());
System.out.println("AR CM No.: " + ar.getCmNo());
arList.add(ar);
}
else if ("pwp".equals(in.getRecordName())) {
PWP pwp = (PWP) record;
System.out.println("PWP Redeem Type: " + pwp.getRedeemType());
System.out.println("PWP MM No.: " + pwp.getMmNo());
System.out.println("PWP CM No.: " + pwp.getCmNo());
pwpList.add(pwp);
}
else if ("pap".equals(in.getRecordName())) {
PAP pap = (PAP) record;
System.out.println("PAP Redeem Type: " + pap.getRedeemType());
System.out.println("PAP MM No.: " + pap.getMmNo());
System.out.println("PAP CM No.: " + pap.getCmNo());
papList.add(pap);
}
else if ("trailer".equals(in.getRecordName())) {
recordCount = (String) record;
System.out.println("Trailer");
System.out.println(recordCount + " contacts processed");
}
}
map.put("NAR", narList);
map.put("AR", arList);
map.put("PWP", pwpList);
map.put("PAP", papList);
in.close();
return map;
}
}
Processor Class:
#Component(value = "RedemptionEventCustomProcessor")
public class RedemptionEventCustomProcessor implements ItemProcessor<Map<String,Object>, Map<String,Object>> {
ArrayList<NonAirline> narList = new ArrayList<NonAirline>();
ArrayList<Airline> arList = new ArrayList<Airline>();
ArrayList<PWP> pwpList = new ArrayList<PWP>();
ArrayList<PAP> papList = new ArrayList<PAP>();
#SuppressWarnings("unchecked")
#Override
public Map<String,Object> process(Map<String,Object> map) throws Exception {
System.out.println(":::::::::::::In Processor::::::::::::::::");
narList = (ArrayList<NonAirline>) map.get("NAR");
for(int i=0; i <= narList.size(); i++)
{
NonAirline nar = narList.get(i);
System.out.println("CM No. " + nar.getCmNo());
}
return map;
}
}
Please let me know if any other information is required. Any help will be really appreciated, please consider I am new to both BeanIO and spring as well.
If anyone could share a working example of BeanIO using Spring Batch that should also help.
Thank You in advance.
I too am using beanio with spring batch. The error you are getting is perhaps for the version issue. Here is my xsd config from job xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

List as subreport parameter

I need to pass to my subreport a list of integers which will be used as parameter for a IN statement in my query like this:
SELECT * FROM my_tables WHERE $X{IN, table.id || '', PARAMETER_LIST}
I have tried various syntax to instance a list on my master report but none of them lead to
a functional report ; eg :
<subreportParameter name="PARAMETER_LIST">
<subreportParameterExpression><![CDATA[[1,2]]]></subreportParameterExpression>
</subreportParameter>
Is there a solution to my problem?
I've tried to use $X{IN, attributeName, parameterName} with List component.
The main steps (parameters names are from the sample below):
Declare listParam parameter as java.util.List in main report
Declare quantityParam parameter as java.util.List in subDataset
Make mapping from listParam parameter to quantityParam parameter with help of ArrayList constructor
Add $X{} expression to subDataset query.
The working sample with language property as Java:
<jasperReport ...>
...
<subDataset name="dataset1">
<parameter name="ProductId" class="java.lang.Integer"/>
<parameter name="quantity" class="java.util.List"/>
<queryString>
<![CDATA[SELECT
POSITIONS."DOCUMENTID" AS POSITIONS_DOCUMENTID,
POSITIONS."POSITIONNO" AS POSITIONS_POSITIONNO,
POSITIONS."PRODUCTID" AS POSITIONS_PRODUCTID,
POSITIONS."QUANTITY" AS POSITIONS_QUANTITY,
POSITIONS."PRICE" AS POSITIONS_PRICE
FROM
"PUBLIC"."POSITIONS" POSITIONS WHERE PRODUCTID=$P{ProductId} AND $X{IN, QUANTITY, quantityParam}]]>
</queryString>
<field name="POSITIONS_DOCUMENTID" class="java.lang.Integer"/>
<field name="POSITIONS_POSITIONNO" class="java.lang.Integer"/>
<field name="POSITIONS_PRODUCTID" class="java.lang.Integer"/>
<field name="POSITIONS_QUANTITY" class="java.lang.Integer"/>
<field name="POSITIONS_PRICE" class="java.math.BigDecimal"/>
</subDataset>
<parameter name="listParam" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[Arrays.asList("1", "2")]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
PRODUCT."ID" AS PRODUCT_ID,
PRODUCT."NAME" AS PRODUCT_NAME,
PRODUCT."COST" AS PRODUCT_COST
FROM
"PUBLIC"."PRODUCT" PRODUCT]]>
</queryString>
<field name="PRODUCT_ID" class="java.lang.Integer"/>
<field name="PRODUCT_NAME" class="java.lang.String"/>
<field name="PRODUCT_COST" class="java.math.BigDecimal"/>
...
<detail>
...
<componentElement>
<reportElement x="200" y="2" width="313" height="29"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="dataset1">
<datasetParameter name="ProductId">
<datasetParameterExpression><![CDATA[$F{PRODUCT_ID}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="quantityParam">
<datasetParameterExpression><![CDATA[new ArrayList($P{listParam})]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="29" width="313">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{POSITIONS_QUANTITY}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{POSITIONS_PRICE}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
...
</jasperReport>
The sample is also works with report's language property as groovy.
I think that this solution can be applied to subreport.

Resources