on 08-31-2015 1:47 PM
Hi,
I am working on a portal application that personalize's iView property via APIs. The code snippet I am using is as follows:
import java.util.Hashtable;
import com.sap.portal.directory.Constants;
import com.sap.portal.pcm.admin.IAdminBase;
import com.sap.portal.pcm.admin.IAttributeSet;
import com.sap.portal.pcm.admin.PcmConstants;
import com.sapportals.portal.pcd.gl.IPcdContext;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
env.put(Context.SECURITY_PRINCIPAL, user);
env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_ADMINISTRATION);
IPcdContext pcdContext = (IPcdContext) new com.sapportals.portal.prt.jndisupport.InitialContext(env).lookup("");
IAdminBase adminBase = (IAdminBase)pcdContext.lookup(path_to_iView);
IAttributeSet attrSet = (IAttributeSet)adminBase.getImplementation(IAdminBase.ATTRIBUTE_SET);
attrSet.putAttribute("com.sap.portal.pcm.Title", Locale.ENGLISH ,title);
attrSet.save();
I have added the following JARs specific to the above code:
com.sap.portal.pcm.admin.apiservice_api.jar
gl_api.jar
prtjndisupport.jar
tc~epbc~pcm~adminapi~java.jar
In SharingReference of portalapp.xml I have added the entries com.sap.portal.pcd.glservice, com.sap.portal.pcm.admin.apiservice, com.sap.portal.ivs.connectorservice, com.sap.portal.navigation.api_service
At runtime when I execute the application I get the following exception:
java.lang.ClassCastException: class com.sapportals.portal.pcd.gl.PcdGlContext:com.sapportals.portal.prt.util.ApplicationClassLoader@44d2247a@com.sapportals.portal.prt.util.ApplicationClassLoader@44d2247a(D:\usr\sap\TT1\JC01\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\com.sap.portal.pcd.glservice\private\lib\com.sap.portal.pcd.glservice_core.jar;D:\usr\sap\TT1\JC01\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\com.sap.portal.pcd.glservice\private\lib\concurrency.jar;D:\usr\sap\TT1\JC01\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\com.sap.portal.pcd.glservice\private\lib\gl_core.jar;) incompatible with interface com.sap.portal.pcm.admin.IAdminBase:com.sap.engine.core.service630.container.ComponentClassLoader@52fe21c2@library:tc~epbc~pcm~adminapi~java
This occurs at line 12 in the code above.
Any help would be highly appreciated.
Regards,
Melwyn
Hi Assaf & Chhaya,
Thanks a lot for your responses.
I modified the code to use InitialContext instead of IPcdContext. However I do get the same error again.
In Assaf's code, it skips the if block and the obj doesn't seem to be instance of IAdminBase.
In Chhaya's code, I get the error in iCtx.lookup(objId)line.
Does the path have to be like "portal_content/com.test.Cust/iview1" or should it be "pcd:portal_content/com.test.Cust/iview1" ?
Also, does the error having anything to do with missing/incorrect jars that I used ?
Regards,
Melwyn
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Melwyn,
There could be several reasons why your code fails:
1) With which user you do the lookup? Does this user has permission on the content?
2) Are you sure the content you do the lookup exists? Are you sure it is not a broken delta link?
When you debug the code what instance do you get from the lookup?
Please post you latest code, exception, screenshot of the content to show it exists in portal content catalouge.
Also you are doing changes on PCD content and in the posted code I do not see usage for locking and transactions that are needed when writing to the PCD.
Best Regards,
Assaf
Hi Melwyn,
As Asaaf mentioned, use following code, instead of initializing through IPcdContext, initialize through InitialContext :
Sample:
InitialContext iCtx;
IAdminBase adminBase = null;
try {
iCtx = new InitialContext(env);
adminBase = (IAdminBase)iCtx.lookup(objId);
} catch (NamingException ne) {
}Refer link (for more details):https://help.sap.com/saphelp_nw74/helpdata/en/4a/1b0bfba988100ce10000000a42189b/content.htmP.S.: Please assign points if you find this as helpfulRegards,
Chhaya Gupta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Melwyn,
Instead of:
IPcdContext pcdContext = (IPcdContext) new com.sapportals.portal.prt.jndisupport.InitialContext(env).lookup("");
You can do:
import javax.naming.InitialContext;
InitialContext iCtx = new IntialContext(env);
Object obj = pcdContext.lookup(path_to_iView);
if (obj instanceof IAdminBase)
{
IAdminBase adminBase = (IAdminBase)obj;
IAttributeSet attrSet = (IAttributeSet)adminBase.getImplementation(IAdminBase.ATTRIBUTE_SET);
attrSet.putAttribute("com.sap.portal.pcm.Title", Locale.ENGLISH ,title);
attrSet.save();
}
Do not do lookup to IPCDContext and then lookup to IAdminBase from the IPcdContext.
Furthermore you do not have a guarantee that the object returned in the lookup will be IAdminBase, e.g. the object you do lookup on in BrokenDeltaLink.
Best Regards,
Assaf
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.