AnsweredAssumed Answered

Can not read binary content fron input stream

Question asked by wael.shaban on Apr 30, 2007
Latest reply on May 4, 2007 by kevinr
I have Alfresco deployed on LR 4.2.1. And I am creating LR portlet for uploading and playing/converting media files. I am using Alfresco web-service API to save the media files inside the Alfresco repository.
All goes well with me with creating folders, creating content and saving the content (file bytes). I am also can open the alfresco space through the browser and see my file there and can download it with no problems.

My problem exist when I am trying to download the file using the web-service API to play it inside the portlet.
My code is:

AuthenticationUtils.startSession(USERNAME, PASSWORD);
Reference reference = new Reference(STORE, null, "/app:company_home/cm:"+userID+"/*[@cm:name=\"" + vid_.getName() + "\"]");

Node[] nodes = WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{reference}, STORE, null));
         
if (nodes!=null && nodes.length>0){
            
    Content[] readResult = WebServiceFactory.getContentService().read(
                        new Predicate(new Reference[]{nodes[0].getReference()}, STORE, null),
                        Constants.PROP_CONTENT);

    Content content = readResult[0];
            
    InputStream inputStream = ContentUtils.getContentAsInputStream(content);

    byte[] contentBytes = new byte[(int)content.getLength()];
    inputStream.read(contentBytes);
    vid_.setContent(contentBytes);
    inputStream.close();
}
where "vid_" is my object that holds the media name and content. After that I save the file bytes inside tmp file to stream it to my media player.

But when I ran this code, I found Alfresco server have the following error logs:

13:34:50,910 WARN  [springframework.util.FileCopyUtils] Could not close OutputStream
ClientAbortException:  java.net.SocketException: Broken pipe
        at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:366)
        at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:433)
        at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:314)
        at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:278)
        at org.apache.catalina.connector.CoyoteOutputStream.close(CoyoteOutputStream.java:103)
        at org.springframework.util.FileCopyUtils.copy(FileCopyUtils.java:132)
        at org.alfresco.repo.content.AbstractContentReader.getContent(AbstractContentReader.java:342)
        at org.alfresco.web.app.servlet.BaseDownloadContentServlet.processDownloadRequest(BaseDownloadContentServlet.java:252)
        at org.alfresco.web.app.servlet.DownloadContentServlet.doGet(DownloadContentServlet.java:98)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:746)
        at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:433)
        at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:348)
        at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:769)
        at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:123)
        at org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:579)
        at org.apache.coyote.Response.doWrite(Response.java:559)
        at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:361)
        … 24 more
13:34:50,916 ERROR [[localhost].[/alfresco].[downloadContent]] Servlet.service() for servlet downloadContent threw exception
org.alfresco.error.AlfrescoRuntimeException: Error during download content servlet processing: Failed to copy content to output stream:
   accessor: ContentAccessor[ contentUrl=store://2007/4/30/12/58/8c255a6d-f71a-11db-816d-c71666ab2a00.bin, mimetype=vide/x-flv, size=652423, encoding=null]
        at org.alfresco.web.app.servlet.BaseDownloadContentServlet.processDownloadRequest(BaseDownloadContentServlet.java:269)
        at org.alfresco.web.app.servlet.DownloadContentServlet.doGet(DownloadContentServlet.java:98)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)
Caused by: org.alfresco.service.cmr.repository.ContentIOException: Failed to copy content to output stream:
   accessor: ContentAccessor[ contentUrl=store://2007/4/30/12/58/8c255a6d-f71a-11db-816d-c71666ab2a00.bin, mimetype=vide/x-flv, size=652423, encoding=null]
        at org.alfresco.repo.content.AbstractContentReader.getContent(AbstractContentReader.java:347)
        at org.alfresco.web.app.servlet.BaseDownloadContentServlet.processDownloadRequest(BaseDownloadContentServlet.java:252)
        … 17 more
Caused by: ClientAbortException:  java.net.SocketException: Broken pipe
        at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:366)
        at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:433)
        at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:348)
        at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:392)
        at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:381)
        at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:88)
        at org.springframework.util.FileCopyUtils.copy(FileCopyUtils.java:118)
        at org.alfresco.repo.content.AbstractContentReader.getContent(AbstractContentReader.java:342)
        … 18 more
Caused by: java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:746)
        at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:433)
        at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:348)
        at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:769)
        at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:125)
        at org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:579)
        at org.apache.coyote.Response.doWrite(Response.java:559)
        at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:361)
        … 25 more
Apr 30, 2007 1:34:50 PM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Exception, location=/jsp/error.jsp]
java.lang.IllegalStateException
        at org.apache.coyote.Response.reset(Response.java:296)
        at org.apache.catalina.connector.Response.reset(Response.java:645)
        at org.apache.catalina.connector.Response.reset(Response.java:909)
        at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:356)
        at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:212)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:134)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)

I don't understand what's happen or what's wrong in my code?!

Can you help me please?

thanks in advance

Outcomes