Skip to Content
0
Former Member
Apr 12, 2007 at 09:05 AM

Get a PDF with FileDownload UI on demand (Bug???)

16 Views

Hi,

my purpose is to download a pdf from my back-end system (content server) on demand. I use a FileDownload UI with the two Methods below.

The first Method "getOnDemandStream" triggerd only when i click on the FileDownload link.

My problem is that i get not the right inputStream back, so the result looks like this:

--ejjeeffe0

content-Type: application/pdf

content-length: 993051

x-comId: KM_Programming.pdf

%pdf1.2

%ÄEIO

stream H%}..........

Can somebody give advice what i could look at ?


public com.sap.tc.webdynpro.progmodel.api.IWDInputStream
  getOnDemandStream(IPrivateDPView.IContextElement element)
{
	ByteArrayOutputStream outputStream = null;
	try {			
		URL url = new java.net.URL( e.getUrl() );
		URLConnection conn = url.openConnection();
		InputStream is = conn.getInputStream();
		outputStream = new ByteArrayOutputStream();
		int length;			
		byte[] part = new byte[1024 * 4];
		while ((length = is.read(part)) != -1) {
			outputStream.write(part, 0, length);
		}						
		is.close();		
	} catch (Exception ex)	{		
	}		
	return WDResourceFactory.createInputStream( outputStream.toByteArray() );
}

 
public void wdDoInit()
{
		IWDAttributePointer attributePointer = 
			wdContext.currentContextElement().getAttributePointer("onDemandStream");
	
		IWDResource resource = WDResourceFactory.createResource(
				attributePointer,
				"test.pdf",
				WDWebResourceType.PDF
				);	
 
		wdContext.currentContextElement().setResource(resource);
}

regards,

Sharam