Quantcast
Channel: SCN : All Content - SAP Enterprise Portal : Administration and Development
Viewing all articles
Browse latest Browse all 526

WebService for access roles of Portal

$
0
0

Dear Gurus,

 

I really need your help. I've ben struggling my brain in order to develop a webservice which can show the content of one or several roles. Till now I could get a role list, but when trying to get attributes of role's content I'm geting class cast exception

 

I've tried many options, but always ended with a class cast exception

 

All your suggestions will be very appreciatted. Thanks in advance

 

 

 

My base are this posts:

Query pcd roles through api

Exposing the Enterprise Java Bean as a Web Service - Developing Java EE 5 Applications - SAP Library

Browse portal content and object properties - Code Gallery - SCN Wiki

 

This is my code:

 

public List<PortalObject> getContentsFromRole(String roleName)

{

    this.portalObjArray = new ArrayList<PortalObject>();

    Hashtable roleList = getRoleListByName(roleName);

    Enumeration keyEnum = roleList.keys();

    try

    {

        InitialContext ctx = null;

        try

        {

            IUser principalObj = null;

            try

            {

                // getting the SAP user.

                IUserFactory userfact = UMFactory.getUserFactory();

                principalObj = userfact.getUserByLogonID("e_aaceval");

            }

            catch (UMException umex)

            {

                portalObjArray.add(new PortalObject("getContentsFromRole() UMException:" + umex.getMessage()));

            }

 

 

            Hashtable env = new Hashtable();

            env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);

            if (principalObj != null)

            {

                env.put(Context.SECURITY_PRINCIPAL, principalObj);

            }

            env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);

            ctx = new InitialContext(env);

        }

        catch (NamingException nex)

        {

            //TODO

        }

 

 

        while (keyEnum.hasMoreElements())

        {

            String roleKey = (String) keyEnum.nextElement();

            String val = (String) roleList.get(roleKey);

 

 

            PortalObject po = new PortalObject();

            po.setId(roleKey);

            po.setName(val);

 

 

            portalObjArray.add(po); // role data

 

 

            IPcdContext rootRole = (IPcdContext) ctx.lookup(roleKey);

            Object titleObj = rootRole.getAttributes("").get("com.sap.portal.pcm.Title");

            portalObjArray.add(new PortalObject("getContentsFromRole() titleObj:" + titleObj.toString()));

            if (titleObj instanceof IPcdAttribute)

            {

                IPcdAttribute titleAtt = (IPcdAttribute) titleObj;

                String title = titleAtt.get().toString();

                portalObjArray.add(new PortalObject("getContentsFromRole() title:" + title));

            }

        }

    }

    catch (Exception ex)

    {

        //TODO

    }

    return portalObjArray;

}

 

 

And this is the error:

 

Cannot cast class com.sapportals.portal.pcd.gl.PcdGlContext to interface com.sapportals.portal.pcd.gl.IPcdContext


Viewing all articles
Browse latest Browse all 526

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>