Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Andew Jardine
WSRP UserContext -- Accessing Extensions[]
21. Juni 2011 06:49
Antwort

Andew Jardine

Rang: Regular Member

Nachrichten: 184

Eintrittsdatum: 22. Dezember 2010

Neue Beiträge

I'm trying to get something to go with a WSRP implementation. What I have is a UserContext object (as defined by the OASIS standard). In addition to a handful of the default list of settings for a user, I have an extension that is defined. My extensions are all using the suggested String format meaning that I should be able to loop through the Extensions[] array that is on the UserContext object to try to find my attribute. Here is what I have --

 1
 2for( Extension e : userContext.getExtensions())
 3{
 4    Deserializer ds = e.getDeserializer( mechType
 5                                   String.class,
 6                                    new QName("urn:oasis:names:tc:wsrp:v2:types", "NamedString") );
 7    ...
 8    ...
 9}


The problem I have is that I don't understand what the first parameter is supposed to be. "mechType" which is of type String. Not the most descriptive. I have been scouring the web but haven't found anything to explain yet -- all the javadoc provides no explanation of the parameters.

Can anyone help?
Andew Jardine
RE: WSRP UserContext -- Accessing Extensions[]
21. Juni 2011 10:53
Antwort

Andew Jardine

Rang: Regular Member

Nachrichten: 184

Eintrittsdatum: 22. Dezember 2010

Neue Beiträge

I've managed to figure it out (I think -- just need to figure out how to test it emoticon ).

Liferay actually provides (THANKS LIFERAY!) a ExntesionUtil class under the com.liferay.wsrp.util package. I use that to retrieve an array of MessageElement object (you need axis.jar to resolve this class) and then loop through the elements to try to find the one I am looking for. No doubt there is a more elegant way to do this, but here is my code -- One of the parameters I pass to my method is the PortletRequest object.

 1
 2        HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
 3        HttpServletRequest original = PortalUtil.getOriginalServletRequest(httpRequest);
 4       
 5        // retrieve the object from the header (where the UserCotnext is supposed to be stored)
 6        Object o = original.getHeader( USER_CONTEXT_OBJECT_ATTRIBUTE_NAME );
 7       
 8        // make sure what we pulled back is infact a User Context object.
 9        if ( o instanceof UserContext )
10        {
11            logger.debug("User context object found in HTTP HEADERS.");
12            
13            // cast the geneeric to the WSRPv2 User Context Object
14            UserContext userContext = (UserContext) o;
15            
16            // set the real user id. We don't set the "user id" because impersonation
17            // does not occur when we are working with remote users.
18            mdexQueryLog.setRealUserId( userContext.getUserContextKey() );            
19            logger.debug( "Found Real User ID in User Context object with value: " + userContext.getUserContextKey() );
20            
21            // get the message elements that make up the extensions.
22            MessageElement[] messageElements = ExtensionUtil.getMessageElements( userContext.getExtensions() );
23            logger.debug("Found " + messageElements.length + " extensions attached to user context.");
24            
25            // loop through the message elements and try to find the organization id.
26            for( MessageElement m : messageElements )
27            {
28                // if we matched the attribute we're looking for
29                if (m.getName().equalsIgnoreCase( CURRENT_ORGANIZATION_ID_ATTRIBUTE_NAME ))
30                {
31                    logger.debug( "Found element with name " + CURRENT_ORGANIZATION_ID_ATTRIBUTE_NAME );
32                    logger.debug( "Element value: " + m.getValue() );
33                   
34                    mdexQueryLog.setOrganizationId( m.getValue() );
35                }
36            }
37                   
38        }
39        else
40        {
41            // no object was found, or we found an object with an unexpected type.
42            if ( o == null )
43                logger.error("Expected to find User Context object in headers at key: " + USER_CONTEXT_OBJECT_ATTRIBUTE_NAME + " - but found no object." );
44            else
45                logger.warn("Expected to find User Context object in headers but found object of type " + o.getClass() + " instead.");
46        }


Andew Jardine:
I'm trying to get something to go with a WSRP implementation. What I have is a UserContext object (as defined by the OASIS standard). In addition to a handful of the default list of settings for a user, I have an extension that is defined. My extensions are all using the suggested String format meaning that I should be able to loop through the Extensions[] array that is on the UserContext object to try to find my attribute. Here is what I have --

 1
 2for( Extension e : userContext.getExtensions())
 3{
 4    Deserializer ds = e.getDeserializer( mechType
 5                                   String.class,
 6                                    new QName("urn:oasis:names:tc:wsrp:v2:types", "NamedString") );
 7    ...
 8    ...
 9}


The problem I have is that I don't understand what the first parameter is supposed to be. "mechType" which is of type String. Not the most descriptive. I have been scouring the web but haven't found anything to explain yet -- all the javadoc provides no explanation of the parameters.

Can anyone help?