JasperServer (AWS) fails to create scheduled PDF report intermittently. (403 error in Google Maps Static API)

0

I have a scheduled report with result saved into PDF file. The report has a static google maps.

Everything was perfect during last couple of years until recently that I started to experience failures intermittently. The scheduler fails to export the report into PDF file apparently due to 403 error accessing Google Maps static API. But I'm quite sure I have not changed anything in my side.

I can open the static map in my browser without any issue. I also can get map content with curl on the same ec2 instance of jasperserver without http error. And just mind you that the error is intermitent.

I found the following exception in logs in /var/log/jasperserver/: 


2018-01-17 16:45:04,929 ERROR ReportExecutionJob,quartzScheduler_Worker-1:309 - The export to pdf was not completed. An error interrupted the process.
 
java.lang.RuntimeException: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error opening input stream from URL : http://maps.google.com/maps/api/staticmap?center=-37.905525,145.12576&size=490x650&zoom=13&maptype=roadmap&format=png&scale=1&markers=label:N%7Cicon:http://labs.google.com/ridefinder/images/mm_20_orange.png%7C-37.878597,145.16536&markers=label:N%7Cicon:http://labs.google.com/ridefinder/images/mm_20_orange.png%7C-37.878597,145.16536&sensor=false&language=en
 
        at net.sf.jasperreports.components.map.MapElementPdfHandler.exportElement(MapElementPdfHandler.java:56)
        at net.sf.jasperreports.engine.export.JRPdfExporter.exportGenericElement(JRPdfExporter.java:2801)
        at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:969)
        at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:920)
        at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:797)
        at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:514)
        at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.exportToPdf(EngineServiceImpl.java:559)
        at sun.reflect.GeneratedMethodAccessor760.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at com.sun.proxy.$Proxy49.exportToPdf(Unknown Source)
        at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.PdfReportOutput.getOutput(PdfReportOutput.java:88)
        at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.executeAndSendReport(ReportExecutionJob.java:516)
        at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.execute(ReportExecutionJob.java:220)
        at com.jaspersoft.ji.report.options.engine.ReportOptionsExecutionJob.execute(ReportOptionsExecutionJob.java:49)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
 
Caused by: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error opening input stream from URL : http://maps.google.com/maps/api/staticmap?center=-37.905525,145.12576&size=490x650&zoom=13&maptype=roadmap&format=png&scale=1&markers=label:N%7Cicon:http://labs.google.com/ridefinder/images/mm_20_orange.png%7C-37.878597,145.16536&markers=label:N%7Cicon:http://labs.google.com/ridefinder/images/mm_20_orange.png%7C-37.878597,145.16536&sensor=false&language=en
 
        at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:117)
        at net.sf.jasperreports.repo.InputStreamPersistenceService.load(InputStreamPersistenceService.java:48)
        at net.sf.jasperreports.repo.DefaultRepositoryService.getResource(DefaultRepositoryService.java:155)
        at net.sf.jasperreports.repo.RepositoryUtil.findInputStream(RepositoryUtil.java:176)
        at net.sf.jasperreports.repo.RepositoryUtil.getBytesFromLocation(RepositoryUtil.java:192)
        at net.sf.jasperreports.engine.RenderableUtil.getRenderable(RenderableUtil.java:121)
        at net.sf.jasperreports.components.map.MapElementImageProvider.getImage(MapElementImageProvider.java:211)
        at net.sf.jasperreports.components.map.MapElementPdfHandler.exportElement(MapElementPdfHandler.java:52)
        ... 22 more
 
Caused by: net.sf.jasperreports.engine.JRException: Error opening input stream from URL : http://maps.google.com/maps/api/staticmap?center=-37.905525,145.12576&size=490x650&zoom=13&maptype=roadmap&format=png&scale=1&markers=label:N%7Cicon:http://labs.google.com/ridefinder/images/mm_20_orange.png%7C-37.878597,145.16536&markers=label:N%7Cicon:http://labs.google.com/ridefinder/images/mm_20_orange.png%7C-37.878597,145.16536&sensor=false&language=en
 
        at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:302)
        at net.sf.jasperreports.repo.DefaultRepositoryService.getInputStream(DefaultRepositoryService.java:100)
        ... 29 more
 
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://maps.google.com/maps/api/staticmap?center=-37.905525,145.12576&size=490x650&zoom=13&maptype=roadmap&format=png&scale=1&markers=label:N%7Cicon:http://labs.google.com/ridefinder/images/mm_20_orange.png%7C-37.878597,145.16536&markers=label:N%7Cicon:http://labs.google.com/ridefinder/images/mm_20_orange.png%7C-37.878597,145.16536&sensor=false&language=en
 
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1628)
        at java.net.URL.openStream(URL.java:1048)
        at net.sf.jasperreports.engine.util.JRLoader.getInputStream(JRLoader.java:298)
        ... 30 more

kashoory's picture
284
Joined: Apr 23 2014 - 5:19pm
Last seen: 3 months 1 week ago

Due to recent changes in Google Maps API, you now must provide API key with your call to the API.  Keep in mind there are two API: the Javascript API and the Maps Static API (which is need to export Google map to format such as PDF or Excel).  Your key must be valid for both.  I have just recently run into same problem with exporting the map.  I have provided my API key to the call to the Javascript API so my map displays in browser fine but export fails.  I do not know where in Jasper code the call to the Maps Static API is.  I have tried putting key in the jrxml file but was unsuccessful. 

 

Have you solved your problem as of yet?  If so, I would love to know solution.

ktalarico - 1 year 1 month ago

SOLUTION:  provide API key in /WEB-INF/classes/jasperreports.properties as follows

net.sf.jasperreports.components.map.key=YOUR_API_KEY

ktalarico - 1 year 1 month ago

1 Answer:

0

provide API key in /WEB-INF/classes/jasperreports.properties as follows

net.sf.jasperreports.components.map.key=YOUR_API_KEY

ktalarico's picture
553
Joined: Mar 19 2007 - 4:15am
Last seen: 1 week 2 hours ago
Feedback