0

I have an image in Azure blob storage and I need access to it within an Spring boot app in order to populate a Jasper report. In my local machine is working just fine, the code runs, gets the image and populates de reports but in my DEV environment it is not working.

The DEV envionrment is basically an Azure VM with Nginx as reverse proxy, and docker to run the containers. The spring app is up and running there but when I try to get the image it is not working. I receive a FileNotFound exception.

However if I try to retrieve the image via a cUrl get i can download it form the VM and from the container itself. There are some company configurations and proxy but as I can access it from the container I think I should be able to access it from my java code as well...

The URL and ip are mapped in the hosts file in the docker container.

Does anyone has any idea what may be happening? That I can retrieve the image from the container but not form the code?

EDIT: Adding Stack trace from Jasper, pretty much the same when I open a stream in my own code.

2022-03-23 12:37:54.604 ERROR 1 --- [http-nio-8080-exec-9] n.s.j.engine.fill.JRFillSubreport : Fill 1: exception

net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error opening input stream from URL: https://MY_BLOB.blob.core.windows.net/images/explosive.png.
at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:139) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.InputStreamPersistenceService.load(InputStreamPersistenceService.java:51) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.DefaultRepositoryService.getResource(DefaultRepositoryService.java:196) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.RepositoryUtil.findInputStream(RepositoryUtil.java:195) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.RepositoryUtil.getBytesFromLocation(RepositoryUtil.java:211) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.renderers.util.RendererUtil.getNonLazyRenderable(RendererUtil.java:179) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:526) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:451) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:548) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummaryNoLastFooterSamePage(JRVerticalFiller.java:1265) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerticalFiller.java:1216) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVerticalFiller.java:308) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:126) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:622) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:433) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:830) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:61) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:221) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
Caused by: net.sf.jasperreports.engine.JRException: Error opening input stream from URL: https://MY_BLOB.blob.core.windows.net/images/explosive.png.
at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:343) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:122) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
... 21 common frames omitted
Caused by: java.io.FileNotFoundException: https://MY_BLOB.blob.core.windows.net/images/explosive.png
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1920) ~[na:na]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520) ~[na:na]
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250) ~[na:na]
at java.base/java.net.URL.openStream(URL.java:1165) ~[na:na]
at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:339) ~[jasperreports-6.17.0.jar!/:6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd]
Alex K
  • 22,315
  • 19
  • 108
  • 236
arkhadi
  • 41
  • 2
  • 10

1 Answers1

0

Please check if any of the following ways can work.

This exception Error opening input stream from URL will be usually thrown by the FileInputStream, FileOutputStream .

  • FileInputStream is for files and not for URLs.

1.To get an input stream from any URL is via URL.openStream(), or URL.getConnection().getInputStream(), which is equivalent but you can have other reasons to get the URLConnection if required.

example:

InputStream input = new
     URL("https://MY_BLOB.blob.core.windows.net/images/explosive.png").openStream();

See java - InputStream from a URL - Stack Overflow


  1. Try adding that image as an image resource in the main 'images' folder, then try to change that line of xml to be the following:

jrxml File:

    <imageExpression><![CDATA["https://...../images/explosive.png "]]></imageExpression>

Or

. 3. Try to create the following parameters in reports to reference them later from absolute or external reference : java - Spring JasperReports Images Location - Stack Overflow

This allows the images directory to be relative to the ROOT_DIR
path. It also allows you to change ROOT_DIR dynamically. The
parameters must be declared in their relative order.

    <imageExpression class="java.lang.String">
       <![CDATA[$P{ROOT_DIR}+"explosive.png"]]>
    </imageExpression>

Please check the below references .

References:

  1. java - Using JasperReports with a relative path - Stack Overflow
  2. Jasper: error opening input stream from url - Stack Overflow
  3. java - How to show an image on jasper report? - Stack Overflow
kavyaS
  • 8,026
  • 1
  • 7
  • 19