cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to access the KM files

anil_kumar259
Active Contributor
0 Kudos

Hi Experts,

I am using the following code to access the image in the KM folder

//@@begin getImage()

IWDClientUser wdClientUser;

  try {

  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 = com.sapportals.wcm.repository.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);

   //Reading the image file......

     BufferedInputStream bufIn;

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

     byte[] imagebyte;

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

     bufIn.read(imagebyte);

   //Mapping the image as a WebResource....

     IWDWebResource webResource = WDWebResource.getWebResource(imagebyte,WDWebResourceType.JPG_IMAGE);

     wdContext.currentNode_newsElement().setImg(webResource.getURL());

     return webResource;

  } catch (WDUMException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  } catch (UserManagementException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  } catch (ResourceException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  } catch (ContentException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  } catch (IOException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  }catch (WDURLException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  }

  return null;

    //@@end

When i run the application i am getting the following error.

 

Can anyone help me how to fix this issue and load the km image??

I am getting  ResourceContext and pathid correctly but resource i am getting null...

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

does your application need authentication?

anil_kumar259
Active Contributor
0 Kudos

No it does need any authentication, infact the image file which i trying to access from my wd java application is having access to everyone.

I am getting the resource as null, so i am unable to set the url to the attribute in my wdjava application.

Can please tell me where i need to the modification in my code????

junwu
Active Contributor
0 Kudos

make your application authentication required.

anil_kumar259
Active Contributor
0 Kudos

Hi Jun,

  If i run the application with authenticated user also i am getting the resource as null.

below code i used to get the content of the authenticated user

IUser sapUser = wdClientUser.getSAPUser();

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

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

     IResourceContext resourseContext = new ResourceContext(ep5User);

i am able to get the resourcecontext,resourseFactory and pathImg, when i am setting this values into the reource method i.e

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

I am getting the null value.....

anil_kumar259
Active Contributor
0 Kudos

Hi experts,

Any inputs......??

govardan_raj
Contributor
0 Kudos

Hi anil ,

I would like to suggest you to use try catch block and i have spcified the usage of same in this thread

http://scn.sap.com/thread/3566778,

please go this to know the usage of logs , and now in this code above

are you getting pathRIDImg and resourceContext ?

these two parameters have value or it is null ?

please check them

use

if((null != pathRIDimg )&&(null != resourceContenxt))

{

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

}

and check if you are still getting the same null pointer exception

Regards

Govardan

anil_kumar259
Active Contributor
0 Kudos

Hi Govardhan,

Thanks for the reply.

I am getting pathRIDImg and resourceContext values correctly as i told in my previous reply's.

As you suggested below is the code which i have used

IWDClientUser wdClientUser;

  try {

  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);

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

     IResourceFactory resourseFactory = com.sapportals.wcm.repository.ResourceFactory.getInstance();

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

    

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

     RID pathRIDimg = RID.getRID(path);

     wdComponentAPI.getMessageManager().reportSuccess("pathRIDimg :"+pathRIDimg);

     if((null != pathRIDimg )&&(null != resourseContext))

     {

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

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

     }

And i am getting the output as follows

resourseContextResourceContext: user=vc_helpdesk, creationTime=1403156578691, locale=en_US

resourseFactorycom.sapportals.wcm.repository.runtime.CmAdapter@2df91019

pathRIDimg :/documents/Alice In Wonderland/alice.gif

resourceimg :null

  Please tell me where i need to do the changes...

govardan_raj
Contributor
0 Kudos

now in which line you are getting the null pointer exception  ?

i.e at which part of the code you are getting the exceptoin ...  ?

you can see resourceimg is null ... is this being passed to any method ?

Regads

Govardan

anil_kumar259
Active Contributor
0 Kudos

Hi,

if((null != pathRIDimg )&&(null != resourseContext))

     {

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

HERE I AM GETTING resourceimg as NULL

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

     //Reading the image file......

  /*

     BufferedInputStream bufIn;

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

      byte[] imagebyte;

IN THE ABOVE CODE  resourceimg.getContent().getInputStream() i am getting null pointer exception

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

     bufIn.read(imagebyte);

Regards,

Anil

govardan_raj
Contributor
0 Kudos

hi ,

after ging your code , here you can see that resourceimg is null , as the path specified is correct pleas check that .....

and in the path you have the image in the KM ?

is that folder Alice In Wonderland exists in your km ?

Regards

Govardan

vijay_kumar49
Active Contributor
0 Kudos

Anil,

Please check the thread.

Getting an image from KM Documents to be used in Web Dynpro

http://wiki.scn.sap.com/wiki/display/KMC/Getting+an+image+from+KM+Documents+to+be+used+in+Web+Dynpro

anil_kumar259
Active Contributor
0 Kudos

Yes the folder exists in the KM .

anil_kumar259
Active Contributor
0 Kudos

Hi Vijay,

   By using Getting an image from KM Documents to be used in Web Dynpro - Knowledge Management & Collabo... only i have developed my application.

my problem is with the resource..

govardan_raj
Contributor
0 Kudos

hi ,

please do a favour create a folder with single name , i mean no spaces in between ,

like have aliceInWonderland and check that.

Regards

Govardan

vijay_kumar49
Active Contributor
0 Kudos

Space is not taken..please remove space or kept ( _ )

govardan_raj
Contributor
0 Kudos

hi anil,.

if your problem solved ...

please close this thread...

Regards

Govardan

anil_kumar259
Active Contributor
0 Kudos

Hi Govardhan,

Yes that was the mistake i have done. now i am able to get the resource correctly.

But i am not done compleatly, now i am getting another error.

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

     //Reading the image file......

     BufferedInputStream bufIn;

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

      byte[] imagebyte;

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

     wdComponentAPI.getMessageManager().reportSuccess("buffer value"+imagebyte.length);

     bufIn.read(imagebyte);

    

     //Mapping the image as a WebResource....

  IWDWebResource webResource = WDWebResource.getWebResource(imagebyte,WDWebResourceType.JPG_IMAGE);

  wdComponentAPI.getMessageManager().reportSuccess("Webresource URL"+webResource.getURL());

Here when i print the weResource.getURL value i am getting the output correctly.

buffer value13678

Webresource URL../../demo.sap.com/demo1_news/Demo1_App/~wd_cache_/~wd_key_23WXInZVtBI6JstJ/unknown.jpg?sap-wd-download=1&sap-wd-cltwndid=WID1403161765877&sap-wd-secure-id=Vd0YxiMAqKT8AKABd4BoFw%3D%3D&sap-ext-sid=Qd7gwKFzbwspkq*Yt5R28Q--LV4Hmymd91sZKSlw2sE7jw--%2Fpcd%3Aportal_content%2FCorporate_News%2Fdemo.sap.com%2Fdemo1_news%2FDemo1_App%2Fbase%2F&sap-wd-norefresh=X&sap-ep-version=7.40.201312180437

But when i try to add the webResource.URL to context attribute i am getting the error.

 

govardan_raj
Contributor
0 Kudos

Hi,

you are setting the webresource.url to the context attribute , or a attribute of a context node, in this what is the cardinality of the node.

if it is 0..n please create an element of the node and set

or else if it is 1..1 then u can set the value directly.

At which line you are getting error , please share that code..

Regards

Govardan Raj

anil_kumar259
Active Contributor
0 Kudos

Hi Govardhan,

Thank you much for the help. I am able to load the image which is in km now.

Regards,

Anil

govardan_raj
Contributor
0 Kudos

most welcome cheers 🙂

best regards

Govardan

anil_kumar259
Active Contributor
0 Kudos

Govardhan,

I am getting follwoing error

 

Everything was working fine, after doing some UI changes when i re deploy once again i am getting above error.

Please help on that, what i need to change...

govardan_raj
Contributor
0 Kudos

hi anil,

can u give some more detail, like when you are gettign this error ,

and what UI changes you did.. ?

can you build your DC and deploy and check again.

Regards

Govardan

Answers (0)