Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.StreamCorruptedException: invalid stream header: EFBFBDEF

I'm developing an java web application, where I'm using maven like tool of project managmentand now I'm becaming crazy with this problem. I try to build an jasper report from my application, this report is composed from many sub-report that i have in the src/main/resources. I try to load these subreports in the following way:

//Sub Report 1 
InputStream fileSubRep1=(BufferedInputStream) getClass().getResourceAsStream("/fileSubReport1.jasper");
map.put("fileSubRep1",(JasperReport) JRLoader.loadObject(fileSubRep1));

//Sub Report 2 
InputStream fileSubRep2=(BufferedInputStream) getClass().getResourceAsStream("/fileSubReport2.jasper");
map.put("fileSubRep1",(JasperReport) JRLoader.loadObject(fileSubRep2));

the problem is that the call at this method JRLoader.loadObject(fileSubRep1) generates the following exception:

        net.sf.jasperreports.engine.JRException: Error loading object from InputStream
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:248)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:228)
    at it.aiemonline.report.jasper.GeneraFattureServiceImpl.createMapFileJasper(GeneraFattureServiceImpl.java:292)
    at it.aiemonline.report.jasper.GeneraFattureServiceImpl.executeStreamByteFatturaPdf(GeneraFattureServiceImpl.java:890)
    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.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.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
    at it.aiemonline.utility.logger.SystemLogger.aroundExecuteLog(SystemLogger.java:187)
    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.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    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.$Proxy78.executeStreamByteFatturaPdf(Unknown Source)
    at it.aiemonline.vaadin.application.gui.fatturazione.visualizza.VisualizzaFatturaPanel.visualizzaPdf(VisualizzaFatturaPanel.java:236)
    at it.aiemonline.vaadin.application.gui.fatturazione.visualizza.VisualizzaFatturaPanel$1.itemClick(VisualizzaFatturaPanel.java:109)
    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 com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
    at com.vaadin.ui.Table.handleClickEvent(Table.java:3057)
    at com.vaadin.ui.Table.changeVariables(Table.java:2853)
    at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:396)
    at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:221)
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
    at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
    at org.eclipse.jetty.server.Server.handle(Server.java:346)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1065)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:823)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:58)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:243)
    ... 69 more

Where am I doing wrong? How can I to fix it?

like image 899
Skizzo Avatar asked Jun 06 '14 09:06

Skizzo


3 Answers

Finally after 3 day of headache I solved my trouble. I'm using maven like tool of project managment and I'm working on a modular project with this structure

|-- parent
   |-- model
    --pom.xml
   |-- services
    --pom.xml
   |-- web-app
    --pom.xml

The porblem was that the file that I try to load like Input stream was in the src/main/resources in the services module, but in the web-app's pom.xml I enable the resource filtering, and since that web-app module depends of service the filtering was extended at the services module.

In filtering section of the maven web site Filtering I found:

Warning: Do not filter files with binary content like images! This will most likely result in corrupt output. If you have both text files and binary files as resources, you need to declare two mutually exclusive resource sets. The first resource set defines the files to be filtered and the other resource set defines the files to copy unaltered as illustrated below:

Then I removed the following code from my web-app module and everything works

<resources>
     <resource>
         <directory>src/main/resources</directory>
         <filtering>true</filtering>
    </resource>
</resources>
like image 169
Skizzo Avatar answered Nov 04 '22 03:11

Skizzo


Thanks for this solution @skizzo

A less drastic way, if you still need to filter some other files, or copy all the files is simply to include all files you need to filter (java, xml, properties...).

Here is the solution I just implemented thanks to your help:

        <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.java</include>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>**/*.java</exclude>
                <exclude>**/*.xml</exclude>
                <exclude>**/*.properties</exclude>
            </excludes>
        </resource>
    </resources>

It didn't seemed related at all, and I was looking for it for several hours already. It really saved my day! ;-)

like image 6
Théo camb. Avatar answered Nov 04 '22 02:11

Théo camb.


I had exactly the same problem, i was solved adding the following plug-in in my pom.xml

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
              <nonFilteredFileExtensions>
                <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
                <nonFilteredFileExtension>jasper</nonFilteredFileExtension>
              </nonFilteredFileExtensions>
            </configuration>
          </plugin>
like image 6
OJVM Avatar answered Nov 04 '22 02:11

OJVM