JSON Data Adapter - error before input parameters prompt

I have a jasper report that uses a JSON data adapter to retrieve data from a rest api.  The url is being set dynamically in the report using parameters and the user is prompted to supply a value for paramId:

<parameter name="paramId" class="java.lang.String" evaluationTime="Early">
        <defaultValueExpression><![CDATA["1"]]></defaultValueExpression>
</parameter>
<parameter name="url" class="java.lang.String" isForPrompting="false" evaluationTime="Early">
    <property name="net.sf.jasperreports.http.data.url"/>     
<defaultValueExpression><![CDATA["http://aServiceEndpointUrl/" + $P{paramId}]]></defaultValueExpression>
</parameter>

This all works well if the paramId supplied in the default value expression results in a valid json response from the endpoint call. However they way our endpoints are written, if the supplied paramId does not find any data it returns a 404 response. In this case I get a "There was an error on the server. Try again or contact site administrators. (Error UID: 5d62fb9a-204c-447e-8634-6f703699926d)" error on the report even before the input parameters screen is displayed and I don't even get a chance to supply a valid value for paramId. This creates a dependency on data supplied in the default value expression always being valid. Is the solution to ensure that the endpoint returns an empty string rather than a 404 error or is there a better way to implement this?

I notice that based on the following thread the data adapter gets run twice.

https://community.jaspersoft.com/questions/1111291/web-service-using-json-data-adapter-passing-http-parameters-url-body-through

min_3's picture
6
Joined: Oct 2 2018 - 11:19pm
Last seen: 5 months 1 week ago

1 Answer:

Hello There,

Did you explore Auto REST Driver?  Here is KBA: https://community.jaspersoft.com/wiki/autonomous-rest-connector-tibco-ja...

Auto REST says you can pass dynamically the params in the rest config. Please refer to this documentation and check if you can accomplish this using AutoREST Driver. 

https://docs.progress.com/bundle/datadirect-autonomous-rest-connector-jd...

Hope that helps! Please keep us posted on your findings so that other users can benefit from the outcome.

JRS-SE's picture
4117
Joined: Oct 30 2017 - 12:56pm
Last seen: 1 hour 52 min ago
Feedback