• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Subrreport Jasper: Could not load object from location - getOutputStream()

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody!!

My name is Unai and this is my first time on this forum, this is a great place to solve problems, thank you very much.

The problem is this. We have an J2EE aplicattion, JRE 6, mysql 5.5, running on Tomcat 5.5. We have several Jasperreports working right but there is one of them that causes the following Tomcat error:



Eclipse's console:



The method to generate the report is this (uncomplete, only the call and few more things):




This report worked fine few weeks ago, but now it doesn't. I've tried using code from the backup from the time when it worked ok, but the problem is still there. Maybe I changed configuration or something, I don't know... Please can you help me? I can't find the solution... Thank you very much!!
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Unai!

The filename path in question is a relative path. You should avoid using relative paths in webapps, since there is no concept of a "current" or "working" directory in J2EE, and even if you set one, some other part of the webapp (or some other webapp) could change it on you unexpectedly. So use an absolute path.

Also, JSF should avoid code that does things like "getOutputStream". If you need internal access to the response object, then you're interfering with JSF's mechanisms. It's far better to offload that code into a non-JSF servlet.

 
unai trecet
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Tim. I've tried to use absolute paths, but I get this error:



I'm using this path:



The path would be: C:\Documents and Settings\Administrador\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\phnemos_ph\iReport\
But it doens't works... Maybe I'm not using a correct path.
 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

unai trecet wrote:
Could not load object from location : ..\..\iReport\PDFInformeCuadroGestionSub1.jasper
net.sf.jasperreports.engine.JRException: Could not load object from location : ..\..\iReport\PDFInformeCuadroGestionSub1.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:271)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:311)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:260)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:426)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1380)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:692)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:888)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:810)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
at com.tsystems.web.ModuloInformes.InformesNuevos.InformeGestion.Actions.InformeGestionAction.generarReporte(InformeGestionAction.java:1573)
at com.tsystems.web.ModuloInformes.InformesNuevos.InformeGestion.Actions.InformeGestionAction.generarInformeGestion(InformeGestionAction.java:207)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.tsystems.web.common.FiltroSeguridad.doFilter(FiltroSeguridad.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)



Could you place some code from the file InformeGestionAction.java specially line 1573

I guess the file path for PDFInformeCuadroGestionSub1.jasper is not being declared correctly.
 
unai trecet
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Vishall, this is part of the code you asked:



I maintained the first path I had, the second one I tried, is commented bellow (bellow String ruta = ".." +). I tried two ways that are commented. The path used by the app to find .jasper files, seems to be set in Tomcat (....../workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/phnemos_ph/iReport/), that's why I tried to set it as a total path. The rest of the reports work fine , bur they don't have subreports, this is the only one using them. Thank you for your help.
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the actual location of the PDFInformeCuadroGestionSub1.jasper ?

It seems you are expecting a path relative to your Servlet Context path , but the path you put is not a relative one but turned out to be an absolute one. Try followed by your path to the jasper file.
 
unai trecet
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The actual location where .jasper are compiled is C:/Documents and Settings/Administrador/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/phnemos_ph/iReport/ (I thimk so). Jaspers are compiled during execution they are generated from jrxml when you execute the report.
Sorry Vishal, bur I don't know how to use your instruction:



I tried it, but nothing to do... I'm doing somethig wrong...
Thank you!
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
servletContext.getRealPath can return null in certain cases. I definitely wouldn't expect this method to work accessing a file that's outside of the WAR, and it doesn't always work even inside a WAR. There are better ways to locate and use resources than to access them as files.

For an external file or directory external to the WAR, you can code the absolute path in a properties file or you can code it as a JNDI object in the server-specific deployment descriptor (Context, if you're using Tomcat). Or keep it in a database, etc. What's important is not that where it's stored or how you obtain it, it's that the path should be an absolute path and not a relative path.
 
unai trecet
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Tim, thank you. I'll try again with an absolute path, only one question. You suggested me to set the path in Tomcat's context or database etc. Is it possible to set it directly in the action java code as I try before? I tried I path like this as path parameter for the report (in java action):



But I get this error:



Thanks a lot.
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

unai trecet wrote:Ok Tim, thank you. I'll try again with an absolute path, only one question. You suggested me to set the path in Tomcat's context or database etc. Is it possible to set it directly in the action java code as I try before? I tried I path like this as path parameter for the report (in java action):



But I get this error:



Thanks a lot.



Your problem is that Jasper allows sources other than just files. For example, report templates served up by a web server.

The URL format for a local file looks like this:



Note that there are 3 slashes after the "file:" protocol specification. That's important. I also replaced the blanks with "+" because a proper URL shouldn't contain spaces, and if I'm not mistaken, a "+" will convert to a blank when the URL is parsed. If not, try "%20" instead of "+".

Hopefully, this isn't the same path you intend to use when the webapp goes into production, since you're using an Eclipse internal metadata definition as your source and that won't be possible on a production server.

And, just to repeat, this kind of code should be in its own servlet, because stuff like this gives JSF indigestion. Besides, you don't need JSF to output a Jasper Report.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic