Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

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

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.



Arun Patidar

View solution in original post

12 Replies

Avatar

Level 10

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.

Avatar

Community Advisor

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

Avatar

Level 10

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.

Avatar

Level 3

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

Avatar

Level 10

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. 

Avatar

Level 3

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

Avatar

Level 10

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

Avatar

Level 9

Hey @rubenf42159101,

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

Avatar

Employee Advisor

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

Avatar

Correct answer by
Community Advisor

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.



Arun Patidar

Avatar

Level 10

Here is link to the AEM 6.4 version of this artilce. Updated points include using Maven 13 Archetype project, using AEM 6.4 UBER JAR, and using DS Annotations - all reflect best practices for 6.4 -- Scott's Digital Community: Downloading Adobe Experience Manager 6.4 DAM Assets using the Query Build... org.eclipse.jetty.io.EofException in AEM 6.3