[英]Problem accesing image in Azure bolb storage from Spring app via URL
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.我在 Azure blob 存储中有一个图像,我需要在 Spring 引导应用程序中访问它以填充 Jasper 报告。 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.
在我的本地机器上工作正常,代码运行,获取图像并填充报告,但在我的 DEV 环境中它不工作。
The DEV envionrment is basically an Azure VM with Nginx as reverse proxy, and docker to run the containers. DEV 环境基本上是一个 Azure VM,Nginx 作为反向代理,docker 运行容器。 The spring app is up and running there but when I try to get the image it is not working.
spring 应用程序在那里启动并运行,但当我尝试获取图像时它无法正常工作。 I receive a FileNotFound exception.
我收到 FileNotFound 异常。
However if I try to retrieve the image via a cUrl get i can download it form the VM and from the container itself.但是,如果我尝试通过 cUrl 获取图像,我可以从 VM 和容器本身下载它。 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...
有一些公司配置和代理,但由于我可以从容器访问它,我想我也应该能够从我的 java 代码访问它......
The URL and ip are mapped in the hosts file in the docker container. URL和ip映射到docker容器的hosts文件中。
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.编辑:从 Jasper 添加堆栈跟踪,当我在自己的代码中打开 stream 时几乎相同。
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]
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.此异常
Error opening input stream from URL
通常由 FileInputStream、FileOutputStream 抛出。
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. 1.要从任何 URL 获取输入 stream 是通过
URL.openStream()
或URL.getConnection().getInputStream()
,这是等效的,但如果需要,您可以有其他原因获取 URLConnection。
example:例子:
InputStream input = new
URL("https://MY_BLOB.blob.core.windows.net/images/explosive.png").openStream();
See java - InputStream from a URL - Stack Overflow请参阅java - 来自 URL 的 InputStream - 堆栈内存溢出
jrxml File: jrxml文件:
<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
3. 尝试在报告中创建以下参数,以便稍后从绝对或外部参考中引用它们: java - Spring JasperReports 图像位置 - 堆栈内存溢出
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:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.