cancel
Showing results for 
Search instead for 
Did you mean: 

BaseResourceContextException while accessing km

anil_kumar259
Active Contributor
0 Kudos

Hi Experts,

  I am trying load the image from KM using the webdynpro java application . when i am running my webdynpro application i am getting the follwoing error.

   Initially the screen loaded ok, after doing some changes when i redeploy the application i am getting the error.

In NWA i am getting error message like this.

Can any help me how fix this ???  i am using nwds 7.3 and portal 7.4

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, Check below code. //Reading the image file...... BufferedInputStream bufIn = new BufferedInputStream(resourceimg.getContent().getInputStream()); byte[] imagebyte = new byte[bufIn.available()]; bufIn.read(imagebyte); IWDCachedWebResource cachedWebResource = null;   cachedWebResource = WDWebResource.getWebResource(bufIn, WDWebResourceType.JPG_IMAGE);   ele.setImagepath(cachedWebResource.getURL());

anil_kumar259
Active Contributor
0 Kudos

I am using the same code but i am getting the error at byte[] imagebyte = new byte[bufIn.available()];

Former Member
0 Kudos

Hi, Check this code.. //Reading the image file...... BufferedInputStream bufIn = new BufferedInputStream(resourceimg.getContent().getInputStream()); IWDCachedWebResource cachedWebResource = null;   cachedWebResource = WDWebResource.getWebResource(bufIn, WDWebResourceType.JPG_IMAGE);   cachedWebResource.getUrl(WDFileDownloadBehaviour.ALLOW_SAVE.ordinal()) ;     wdContext.currentContextElement().setDownload(cachedWebResource); download attribute map to lnk

anil_kumar259
Active Contributor
0 Kudos

Excellent......Thank you so much Arun..

Answers (2)

Answers (2)

anil_kumar259
Active Contributor
0 Kudos

Hi Experts,

  Any inputs...??

Former Member
0 Kudos

Dear Anil,

Have you tried the code after removing the space from KM Folder name -"Alice In Wonderland" ?

Thanks & Regards,

Patralekha

anil_kumar259
Active Contributor
0 Kudos

Hi Patraleka,

Yes after changing the KM path i deployed my application, it loaded image successfully without any errors.

But when i deploy second time without doing any changes in my code i am getting the error in the imagebyte = new byte[bufIn.available()];

Any suggestions to fix the issue.

Former Member
0 Kudos

Dear Anil,

Can you pleaseb try to read the file like this & don't forget to close the BufferedInputStream ?

BufferedInputStream bufIn = new BufferedInputStream(resourceimg.getContent().getInputStream());

while( bufIn .available() > 0 ){

                              

wdComponentAPI.getMessageManager().reportSuccess(" bufIn" +(char)bufIn .read());

                        }

                      

                }

                catch(FileNotFoundException e)

                {

                        System.out.println("File not found" + e);

                }

                catch(IOException ioe)

                {

                        System.out.println("Exception while reading the file " + ioe);

                }

                finally

                {

                        //close the BufferedInputStream using close method

                        try{

                                if(bufIn  != null)

                                        bufIn .close();

                                      

                        }catch(IOException ioe)

                        {

                                System.out.println("Error while closing the stream : " + ioe);

                        }

                      

                }

Thanks & Regards,

Patralekha

anil_kumar259
Active Contributor
0 Kudos

Hi Patraleka,

Thanks for giving reply. I have your code but no luck i am getting the same error. When ever i use the method  bufIn .available()   i am getting the error.

I am able to print the bufIn value using below code, but i don't know where i made mistake

BufferedInputStream bufIn = new ufferedInputStream(resource.getContent().getInputStream());

I have undeployed and deployed the application, but still same error.

govardan_raj
Contributor
0 Kudos

Hi Anil ,

what changes you made in UI ? and at which point you are getting the above error  ?

Regards

Govardan


anil_kumar259
Active Contributor
0 Kudos

Initially i have created one image UI element and i have binded the image to the UI element.

when deploy it was working fine. and then i added one linktoURL element and then try to deploy

then i am getting the following above error.

BufferedInputStream bufIn = new BufferedInputStream(resourceimg.getContent().getInputStream());

  In the above code i am getting error while reading the getContent.

I have checked this thread where facing the same issue

where it saying to upgrade KMC-WPC upgrade with latest patch, i have requested my basis team upgrade the patch level.

anil_kumar259
Active Contributor
0 Kudos

Hi,

   After upgrading the KMC-WPC component also i am getting the same error .

I have created a DC and deployed, but still i am getting the same error.

Can anyone help me to fix this issue please...

govardan_raj
Contributor
0 Kudos

hi ANil,

while building the DC is it build successfully  ?

Regards

Govardan

anil_kumar259
Active Contributor
0 Kudos

Yes Govardhan. No problem while building the dc's.

Upto here code is running fine without any runtime errors.

try {

  IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

  IUser sapUser = wdClientUser.getSAPUser();

     com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);

     //Getting the Resource.........

     IResourceContext resourseContext = new ResourceContext(ep5User);

     IResourceFactory resourseFactory = ResourceFactory.getInstance();

        

       //path to the KM Folder ("/documents/Alice In Wonderland/alice.gif")

     RID pathRIDimg = RID.getRID(path);

     com.sapportals.wcm.repository.IResource resourceimg =resourseFactory.getResource(pathRIDimg, resourseContext);

        wdComponentAPI.getMessageManager().reportSuccess("resourceimg"+resourceimg);

When i try add the resource content to the BufferReader i am getting the error .

BufferedInputStream bufIn = new BufferedInputStream(resourceimg.getContent().getInputStream());

        byte[] imagebyte = new byte[bufIn.available()];

        bufIn.read(imagebyte);

        wdComponentAPI.getMessageManager().reportSuccess(" bufIn" +imagebyte.length);

if i execute the above code, i am not getting any build errors but runtime i am getting the error.

pls help me.....

govardan_raj
Contributor
0 Kudos


Hi Anil,

Here in this code

BufferedInputStream bufIn = new BufferedInputStream(resourceimg.getContent().getInputStream());

        byte[] imagebyte = new byte[bufIn.available()];

        bufIn.read(imagebyte);

        wdComponentAPI.getMessageManager().reportSuccess(" bufIn" +imagebyte.length);

in which line you are getting the error ?

Regards

Govardan

anil_kumar259
Active Contributor
0 Kudos

Hi Govardhan,

Upto here its ok , i am able to print the bufin also.

BufferedInputStream bufIn = new BufferedInputStream(resourceimg.getContent().getInputStream());


But when i execute byte[] imagebyte = new byte[bufIn.available()]; i am getting error . Issue is due to bufin.available(),

When i try to print bufin.available() i am getting the error.