on 06-18-2014 3:00 PM
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...
does your application need authentication?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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????
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.....
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
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
| ||
| ||
| ||
|
Please tell me where i need to do the changes...
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
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
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..
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.
|
But when i try to add the webResource.URL to context attribute i am getting the error.
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
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.