cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a WRR Resource as InputStream

Amey-Mogare
Contributor
0 Kudos

Hello All,

I need to read a file kept in Portal WRR as inputstream.

From below link, I could write code to get instance of IResource and it's URI, but I don't see any 'getContent' or similar method for this object which will give me inputstream for this file.

Accessing the Web Resource Repository - Portal - SAP Library

Hence, first question is,  "Is there any method or standard way to read a WRR Resource as inputstream like we have in KM Resource?"

Then I tried to get inputstream using URI of this object using traditional old URLConnection way.

Hence, I noticed strange thing: -

1. When I try to get inputstream from URL of below pattern, I am able to get the inputstream: -

http : // <host> : <port> / com.sap.portal.resourcerepository / repo / folder1 / Test_Data.csv

2. And when I try to get inputStream using masked hostname URL (the one which actually used by end-users), I get connection timed out error in URLConnection: -

http : // <masked-hostname> / com.sap.portal.resourcerepository / repo / folder1 / Test_Data.csv

Any ideas/pointers?

Thanks & Regards,

Amey

Accepted Solutions (1)

Accepted Solutions (1)

former_member193577
Active Contributor
0 Kudos

Hi,

Do you have proxy configured?

Remember that when reading a file in sever side,  the server itself access the file, whereas when users access it, it may go through reverse proxy ,web dispatcher, etc.

Best Regards,

Tal

Amey-Mogare
Contributor
0 Kudos

Hello Tal,

I checked with Basis/Network team and they said yes, there is a proxy configured.

Could you please advise what changes we would need on portal server side for this?

Do I need to maintain maskedURL's entry in hosts file of server?

Thanks & Regards,

Amey

former_member193577
Active Contributor
0 Kudos

Hi Amey,

Can you try reading the file with relative URL, not including the host?


/ com.sap.portal.resourcerepository / repo / folder1 / Test_Data.csv


Another try is after you get the resource with code:

IResource resource = resourceRepository.getResource(resourcePath, IResource.CSSfalse)Get its path by: IResourceInformation resourceInfo = resource.getResourceInformation(); File file = new File(resourceInfo.getSource());

Best Regards,

Tal

Amey-Mogare
Contributor

Thanks a lot, Tal.

It solved with below approach: -

IResource resource = resourceRepository.getResource(resourcePath, IResource.CSSfalse)IResourceInformation resourceInfo = resource.getResourceInformation()File file = new File(resourceInfo.getSource())

narendra_bendi
Active Participant
0 Kudos

Hi Amey,

Can you let me know the code on how to read the contents from the file in WRR.

I am able to read the absolute path for the path.

Thanks,

Narendra.

Answers (1)

Answers (1)

rohit_singhal
Active Contributor
0 Kudos

Hi Amey,

Can you try using IResource instead of URI?

You can then get the input stream of IResource by the following way:

IResource res

//logic of fetching the resource from WRR is mentioned in the blog mentioned in your question.

IContent content = res.getContent(); //this will return the content of the resource.

InputStream is = content.getInputStream(); // this will return input stream of the resource content.

For more details you can refer to the following documentation:

IResource

IContent

Best Regards,

Rohit Singhal

Amey-Mogare
Contributor
0 Kudos

Hello Rohit,

Thanks for reply.

However, you are confusing between IResource of KM and IResource of WRR:

Below is IResource of KM, where we get inputStream from getContent method. This is already known to me but it is not what this question is about.

IResource

And below is the IResource, which is of WRR, where we dont have any method to retrieve data using any standard method.

IResource

Hence, I am using traditional URLConnection way to connect to URL of file and then read the data.

And at this point of time, I am facing issue described in my question above.

I hope this is clear to you.

Thanks & Regards,

Amey