cancel
Showing results for 
Search instead for 
Did you mean: 

File download of large files

Former Member
0 Kudos

Hi we generate large excel files on the fly but the they seem so large that we get OutOfMemory Exceptions. Therefore the way of first reading everything into a large byte array and then to put it into the Context is just plainly too resource consumptious. Even if the files are not so large, many users clicking on download just trash the heap of the VM because everything is kept in memory. What I would like to dois the way how I solve the issue with servlets by just writing the dynamic output to the Output Stream of the servlet, therefore saving the step of keeping the content in memory. This is the way how I will eventually solve it by delegating the query to a servlet but I just wanted to know if there is any chance to create an outputstream instead of a byte array. Even Cached Webresource seems not the answer.

Thanks

David

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This will give u the HttpServletRequest object:

HttpServletRequest request = (com.sap.tc.webdynpro.services.sal.adapter.core.IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();

This will give u the HttpServletResponse object:

HttpServletResponse response =((com.sap.tc.webdynpro.services.sal.adapter.core.IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletResponse()

Just check if this is any help to u.

Regards,

Piyush.

Former Member
0 Kudos

Thanks Piyush,

I was aware of getting the HttpServlet Response. But I do not know if I can work with the Outputstream in WebDynpro to return it to the client directly. Maybe there is a way ...

But thanks for your help.

David

Former Member
0 Kudos

David,

Check whether in your environment the following method is available:

WDResourceFactory.createResource
(
  InputStream stream, 
  String name, 
  WDWebResourceType mimeType,
  boolean copyNow
);

If it is available, then you may create attribute of type com.sap.ide.webdynpro.uielementdefinitions.Resource and bind file download control to it. For this type copy of content happens on demand.

VS

Former Member
0 Kudos

Valery,

unfortunately not. There is no com.sap.ide.webdynpro.uielementdefinitions.Resource and no WDResourceFactory. I am still on NW2004 SP14.

rgds

David

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo David,

the only "improvement" or workaround I see in NW 04 is to use the <b>Web Dynpro Binary Cache</b> to store your large resource. In NW 04s there is a more elegant solution called "on demand streams" but it is not applicable in NW 04.

<u>Try the following workaround:</u>

- Do not store your large resource in a context value attribute of type binary (like it is described within the tutorial on <u>FileUp/Download</u> https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/d2201c20-0801-0010-49b3-94f...

- <u>Do not use</u> the <b>FileDownload</b> UI Element

- Instead use a <b>LinkToURL</b> UI Element and bind it to a context attribute with name 'ResourceURL' of type String. The large resource is not written to the context but it is written to the Web Dynpro Binary Cache as an object of type java.io.InputStream.

See <i>ExcelExport Tutorial</i> https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/1208c2cd-0401...

and the <a href="https://media.sdn.sap.com/javadocs/NW04/SPS15/wd/com/sap/tc/webdynpro/services/sal/url/api/WDWebResource.html">JavaDoc on WDWebResource</a>:

<i>static IWDCachedWebResource getWebResource(InputStream input, WDWebResourceType resourceType)

Returns an IWDWebResource for a given web resource.</i>

- Try IWDCachedWebResource.setAttachement(true)

- Store the URL of the cached web resource within the context attribute 'ResourceURL' to which the LinkToURL UI Element is bound to.

Please try out this approach and tell me whether it circumvents your OutOfMemory problem.

Regards, Bertram

Former Member
0 Kudos

Hi Bertram,

sorry, I was not available for one week.

I already have implemented the solution with a servlet that writes directly to the Output Stream. Before I rewrite that could you give me some more information where the cached webresource is stored? If it is held in memory it won't probably solve the issue because a large file means large memory consumption. If it temporarily stored on disc and at no point the whole binary array must me held in memory this could be a solution. The servlet has the advantage it writes line by line directly to the outputstream without keeping all data in memory.

rgds

David

Former Member
0 Kudos

Does anybody knows the answer to this last question, regarding the disk/memory mistery? We have a comparible situation here and want to know if the binary cache is kept in memory or on disk.

Christophe

Former Member
0 Kudos

Hi,

I am using NWDS 2.0.23 and I can not find data type com.sap.ide.uielementdefinitons.Resource to use in an upload application. I dont understand the difference between NW04 and NW04s. Can you guide me with this? Even in NW 2004, how can i develop an upload for km upload and downlow?

Can u guide me,

Thanks

Answers (0)