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

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

  • August 2, 2018
  • 12 replies
  • 13561 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
New Participant
August 3, 2018

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 Builder API org.eclipse.jetty.io.EofException in AEM 6.3

arunpatidar
arunpatidarAccepted solution
New Participant
August 2, 2018

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
joerghoh
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

Jitendra_S_Toma
New Participant
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.

smacdonald2008
New Participant
August 2, 2018

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

rubenf42159101
New Participant
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
New Participant
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
New Participant
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
New Participant
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.