How to add dynamic image URL in Jasper report

0

We are using some jasper API to execute the report

we provide XML as a data source, using this data source we have defined fields in jrxml.

There is one field, which provides image url, and we have added that field as expression for image.

<image hAlign="Center" vAlign="Middle">
                                    <reportElement stretchType="ContainerBottom" x="0" y="0" width="60" height="30" uuid="95cb6b26-6a43-49bd-af76-bdb531955df5"/>
                                    <box topPadding="5" leftPadding="5" bottomPadding="5" rightPadding="5"/>
                                    <imageExpression><![CDATA[$F{ICONURL}]]></imageExpression>
 </image>

 

Where ICONURL value is dynamic, where we are giving icon gif images url's from our applications.

But when we execute reports via integration with our server. getting the following error.

 net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error opening input stream from URL: http://vagrant.ptcnet.ptc.com:2280/Windchill/com/airbus/images/adap-ci.gif.
     at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:139)
     at net.sf.jasperreports.repo.InputStreamPersistenceService.load(InputStreamPersistenceService.java:51)
     at net.sf.jasperreports.repo.DefaultRepositoryService.getResource(DefaultRepositoryService.java:196)
     at net.sf.jasperreports.repo.RepositoryUtil.findInputStream(RepositoryUtil.java:195)
     at net.sf.jasperreports.repo.RepositoryUtil.getBytesFromLocation(RepositoryUtil.java:211)
     at net.sf.jasperreports.renderers.util.RendererUtil.getNonLazyRenderable(RendererUtil.java:179)
     at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:515)
     at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:440)
     at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383)
     at net.sf.jasperreports.engine.fill.JRFillFrame.evaluate(JRFillFrame.java:159)
     at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383)
     at net.sf.jasperreports.components.list.FillListContents.evaluateContents(FillListContents.java:85)
     at net.sf.jasperreports.components.list.VerticalFillList.prepare(VerticalFillList.java:110)
     at net.sf.jasperreports.engine.fill.JRFillComponentElement.prepare(JRFillComponentElement.java:152)
     at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:542)
     at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:453)
     at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:428)
     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2585)
     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:813)
     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:264)
     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:110)
     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:615)
     at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:433)
     at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:162)
     at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:651)
     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:1020)
     at com.ptc.wbr.core.execution.JasperReportExecutor.generateJasperReport(JasperReportExecutor.java:213)
     at com.ptc.wbr.core.execution.JasperReportExecutor.executeReport(JasperReportExecutor.java:95)
     at com.ptc.wbr.core.JasperFacade.executeThirdPartyReport(JasperFacade.java:172)
     at com.ptc.windchill.enterprise.report.StandardReportService.executeReport(StandardReportService.java:717)
     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.base/java.lang.reflect.Method.invoke(Method.java:566)
     at wt.services.ServiceFactory$ServerInvocationHandler.invoke(ServiceFactory.java:399)
     at com.sun.proxy.$Proxy19.executeReport(Unknown Source)
     at org.apache.jsp.netmarkets.jsp.report.jasper.reportView_jsp.getReport(reportView_jsp.java:65)
     at org.apache.jsp.netmarkets.jsp.report.jasper.reportView_jsp._jspService(reportView_jsp.java:252)
     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
     at wt.licenseusage.licensing.LicenseFilter.doFilter(LicenseFilter.java:47)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
     at com.ptc.core.components.filter.JCAFilter.doFilter(JCAFilter.java:97)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
     at com.ptc.core.ui.validation.URLValidationFilter.doFilter(URLValidationFilter.java:86)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
     at wt.httpgw.filter.WTContextBeanFilter.doWithWtContextBeanHandler(WTContextBeanFilter.java:104)
     at wt.httpgw.filter.WTContextBeanFilter.doFilter(WTContextBeanFilter.java:58)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
     at wt.servlet.CompressionFilter.doFilter(CompressionFilter.java:301)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
     at wt.servlet.RequestInterrupter.doFilter(RequestInterrupter.java:335)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
     at wt.servlet.ServletRequestMonitor.doFilter(ServletRequestMonitor.java:1660)
     at wt.servlet.ServletRequestMonitorFilter.doFilter(ServletRequestMonitorFilter.java:56)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
     at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:476)
     at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
     at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1508)
     at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
     at java.base/java.lang.Thread.run(Thread.java:834)
 Caused by: net.sf.jasperreports.engine.JRException: Error opening input stream from URL: http://vagrant.ptcnet.ptc.com:2280/Windchill/com/airbus/images/adap-ci.gif.
     at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:343)
     at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:122)
     ... 84 more
 Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://vagrant.ptcnet.ptc.com:2280/Windchill/com/airbus/images/adap-ci.gif
     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1919)
     at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
     at java.base/java.net.URL.openStream(URL.java:1129)
     at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:339)
     ... 85 more

 

That image URL does not have anonymous access? How could we achieve this?

while creating image on jrxml/jasper it asks for url but we dont have static url, we can not specify field in url? when we specify expression, how we can authenticate it?

is there any parameters in map which we can send and it will get authenticated?

 

ujadhav's picture
Joined: Apr 12 2019 - 1:30am
Last seen: 3 months 1 week ago

hi Leo,

Yes our application is not giving access to image url, that is what i have explained in question, is there any way to authenticate dynamic image url ? by providing parameters while executing report or any other way?

ujadhav - 7 months 3 weeks ago

Thanks for the downvote.
And for sure in Jasper there is no way can you can pass the authenticate param to get the image.
But you can get the image by your application before you create the report and pass it into your template under the InputStream.

I am Leo - 7 months 2 weeks ago

1 Answer:

-1

Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL

I think your application can not get the image from the server.

I am Leo's picture
178
Joined: Jan 3 2020 - 3:13am
Last seen: 1 month 2 weeks ago
Feedback
randomness