Timeout when calling external image

Hi all,

I have an image field with this expression:

$F{IMAGE} == null ? null : "http://server:port/service?imageuri=" + $F{IMAGE}

I need that if the server does not return a response after 2 seconds, the expression return null.

I search in the forum and google, but I didn't find anything that can help me.

Do you have any ideas? Thanks

manuel.dadda's picture
Joined: Mar 17 2022 - 8:48am
Last seen: 1 month 3 weeks ago

3 Answers:

I think the cleanest way to do this would be to write a helper class (in Java) that puts a timer around the URL call and returns null if it takes too long, otherwise returns your image. I'm not sure it's possible directly in the expression editor as it will not evaluate the URL in the image field until the report is filled. Do you know how to create a helper class?

mbielkiewicz's picture
Joined: Feb 23 2014 - 9:22pm
Last seen: 3 days 2 hours ago

@mbielkiewicz Thank you for your answer. No, I don't know, my knowledge of java is 0, I mostly use JS.

To do this, do I need to use the scriptlet function of Jasper?

Thank you very much

manuel.dadda's picture
Joined: Mar 17 2022 - 8:48am
Last seen: 1 month 3 weeks ago

Scriptlets and Helper Classes are very similar in nature. Both are written in Java. Both are referenced directly in your jrxml report in Studio. Scriptlets contain predefined methods that execute at certain times during the report execution/fill process but can also include additional methods that can be referenced at any point in your report (like a helper class) and are attached to individual reports during the report design process. Helper classes are essentially user-built utility methods built in java, compiled to a JAR file and included on the server, making them available to all reports at all the times. This is a high level description.

mbielkiewicz's picture
Joined: Feb 23 2014 - 9:22pm
Last seen: 3 days 2 hours ago
Feedback