org.eclipse.jetty.io.EofException in AEM 6.3 | Community
Skip to main content
rubenf42159101
August 2, 2018
Solved

org.eclipse.jetty.io.EofException in AEM 6.3

  • August 2, 2018
  • 12 replies
  • 13564 views

Hi,

I'm trying to call a servlet using GET to download an asset from DAM in AEM 6.3.2.0. Asset gets download with file size as zero and I get below exception in the log

org.apache.sling.engine.impl.helper.ClientAbortException: org.eclipse.jetty.io.EofException

at org.apache.sling.engine.impl.log.RequestLoggerResponse$LoggerResponseOutputStream.write(RequestLoggerResponse.java:401)

at com.sample.servlet.DownloadAssetServlet.doGet(DownloadAssetServlet.java:87)

at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:270)

at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:346)

at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:378)

at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:552)

at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44)

..........................................................................

..........................................................................

at org.eclipse.jetty.server.Server.handle(Server.java:499)

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)

at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)

at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)

at java.lang.Thread.run(Thread.java:748)

Caused by: org.eclipse.jetty.io.EofException: null

at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:192)

at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:408)

at org.eclipse.jetty.io.WriteFlusher.completeWrite(WriteFlusher.java:364)

at org.eclipse.jetty.io.SelectChannelEndPoint.onSelected(SelectChannelEndPoint.java:111)

at org.eclipse.jetty.io.SelectorManager$ManagedSelector.processKey(SelectorManager.java:641)

at org.eclipse.jetty.io.SelectorManager$ManagedSelector.select(SelectorManager.java:612)

at org.eclipse.jetty.io.SelectorManager$ManagedSelector.run(SelectorManager.java:550)

at org.eclipse.jetty.util.thread.NonBlockingThread.run(NonBlockingThread.java:52)

... 3 common frames omitted

Caused by: java.io.IOException: Broken pipe

at sun.nio.ch.FileDispatcherImpl.write0(Native Method)

at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)

at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)

at sun.nio.ch.IOUtil.write(IOUtil.java:65)

at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)

at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:170)

... 10 common frames omitted

Is this an issue in AEM 6.3?

Regards,

Ruben Fernando

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi Ruben,

Your code is fine, works for me.

aem63app-repo/DownloadAssetsImage.java at master · arunpatidar02/aem63app-repo · GitHub

Problem is somewhere else, you should check the other endpoint.

12 replies

smacdonald2008
August 2, 2018

Hey - can you please post your code example so the community can look at it. It will make it much easier for the community to help you with the code.

arunpatidar
Community Advisor
Community Advisor
August 2, 2018

Hi,

The most common reason to have "broken pipe" exception is that one machine (of a pair communicating via socket) has shut down its end of the socket before communication was complete. About half of those were because the program communicating on that socket had terminated. If the program sending bytes sends them out and immediately shuts down the socket or terminates itself, it is possible for the socket to cease functioning before the bytes have been transmitted and read.

Try putting pauses anywhere you are shutting down the socket and before you allow the program to terminate to see if that helps.

FYI: "pipe" and "socket" are terms that get used interchangeably sometimes.

Arun Patidar
smacdonald2008
August 2, 2018

We have a very old article on this use case - 5.6. We are going to update it to 6.4 and test to make sure the servelt retrieves assets from the DAM and lets you download them.  Post back soon with a video too.

arunpatidar
Community Advisor
Community Advisor
August 2, 2018
rubenf42159101
August 2, 2018

Thanks Scott and Arun.

I have looked into the above article and even tried it. It will download the asset as a zip file. My use case is to download the asset as it is and not as zip file.

Please find the piece of code which I have used

ResourceResolver resolver = slingRequest.getResourceResolver();

Resource resource = resolver.getResource(fileUrl);

Asset asset = resource.adaptTo(Asset.class);

Resource original = asset.getOriginal();

InputStream stream = original.adaptTo(InputStream.class);

contentType = asset.getMetadataValue(dc:format");

if (StringUtils.isNotEmpty(contentType)) {

resp.setContentType(contentType);

}

else {

resp.setContentType("application/pdf");

}

resp.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

int maxByteBufferSize = 208896;

byte[] byteBuffer = new byte[maxByteBufferSize];

while ((stream != null) && ((length = stream.read(byteBuffer)) != -1)) {

outStream.write(byteBuffer, 0, length);

}

stream.close();

outStream.close();

Kindly let me know if I'm missing something here.

Thanks and Regards,

Ruben Fernando

smacdonald2008
August 2, 2018

Change the Java app logic to so. The objective of that article was to show how to download a file (a ZIP was just an example) that contains assets from the DAM. I am updating the article for 6.4. I will show both a ZIP and a individual file. 

rubenf42159101
August 2, 2018

Hi Scott,

The code posted above was to download individual file. Kindly post the article url here once you have updated.

Thanks and Regards,

Ruben Fernando

smacdonald2008
August 2, 2018

Will do! We will also create a video and post that too!

Jitendra_S_Toma
August 2, 2018

Hey @rubenf42159101,

Just reduce your buffer size. Make it 2048. it should work in my view. let me know if it does not.

joerghoh
Adobe Employee
Adobe Employee
August 2, 2018

Hi Ruben,

as Arun already pointed out, the problem is that the "other side" of the communication channel closed the connection unexpectedly. If the other endpoint is a browser that's something you need to expect. If the other endpoint is a program you should deal with it, because this shouldn't happen.

Jörg