Skip Headers
Oracle® Discussions Application Developer's Guide
10g Release 1(10.1.2)
B28208-02
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

12 Understanding the User Service

The User Service interface provides user access operations. It provides the following methods to retrieve user information based on the user attributes.

Retrieving User Information by Nickname

The following is an example for retrieving the user information by nickname:

Example 12-1 Retrieving User Information by Nickname

import java.util.Date;import java.io.*;import java.util.*;import javax.mail.*;import javax.mail.internet.*;

import org.apache.axis.transport.http.HTTPConstants;import oracle.discussions.ws.exceptions.TdWSException;import oracle.discussions.ws.beans.*;import oracle.discussions.ws.AuthenticationServiceServiceLocator;import oracle.discussions.ws.AuthenticationServiceSoapBindingStub;import oracle.discussions.ws.AuthenticationService;import oracle.discussions.ws.UserServiceServiceLocator;import oracle.discussions.ws.UserServiceSoapBindingStub;import oracle.discussions.ws.UserService;

/* * Tests the Oracle Discussions Web Services functionality. * Invokes various web services methods, to retrieve the results and  * check if the results are fine. */public class WSClient{  private static AuthenticationService as = null;    public static String getCookie() throws Exception  {      //STEP - 0: User Login      //Create the service locator for authentication service. The locator
      //contains information about       //the webservices endpoint.       AuthenticationServiceServiceLocator assl = new
                        AuthenticationServiceServiceLocator();             //Get the handle to the actual webservices interface.              as = assl.getAuthenticationService();             //Indicate to the server that the client is interested in maintaining
             //session             //HTTP is stateless and the user state is maintained in the session.             //Unless the user is willing to participate in a session, user state
             //cannot be preserved.              ((AuthenticationServiceSoapBindingStub)as).setMaintainSession(true);
             
             //Invoke the actual login webservices call.               as.login("td_superuser","welcome1");             //Retrieve the cookie. The cookie is set on successful
             //authentication.
              String cookie = (String)((AuthenticationServiceSoapBindingStub)as)
                                ._getCall().getMessageContext()
                                .getProperty(HTTPConstants.HEADER_COOKIE);              System.out.println("Cookie : " + cookie);              return cookie;          }

      public static void main(String args[])       {         try         {              //STEP - 1: User Login              String cookie = getCookie();                 //STEP - 2: Locate the web services end point.             //The Web Services locator contains the webservices end point
             //address. Therefore instantiate the service locator.              UserServiceServiceLocator ussl = new UserServiceServiceLocator();             //Get a handle to the actual web service.              UserService us = ussl.getUserService();                   //Indicate to the server that the user is willing to participate in
             //the session.             //Since HTTP is stateless, all the client data is maintained in the
             //session              ((UserServiceSoapBindingStub)us).setMaintainSession(true);             //Set the cookie retrieved in the call to login webservice.             //The cookie asserts user's identity to the server.              ((javax.xml.rpc.Stub)us)._setProperty(HTTPConstants.HEADER_
                                                  COOKIE,cookie);

             //Invoke the actual web services call.              User user = us.getUserByNickname("td_superuser");              if(user != null)              {                System.out.println("User Nickname :" + user.getNickname());                System.out.println("User Guid :" + user.getGuid());                System.out.println("User Primary Email :" +
                                     user.getPrimaryEmailAddress());                System.out.println("User DN :" + user.getDN());                System.out.println("User Domain :" + user.getDomain());                System.out.println("User Timezone :" + user.getTimeZone());                System.out.println("User Locale :" + user.getLocale());                System.out.println("User Creation date :" +
                                     user.getMemberSince().getTime());          System.out.println("User Last logout time :" +
                               user.getLastLogoutTime().getTime());          System.out.println("User Last login time :" +
                               user.getLastLoginTime().getTime());
          System.out.println("User Displayname :" + user.getDisplayName());          System.out.println("User Presence URL :" + user.getPresenceURL());          System.out.println("User Email id :" + user.getEmail());          System.out.println("User client chat uri :" + user.getClientChatUri());          System.out.println("User presence img url :" +
                               user.getPresenceImgUrl());       }      //STEP - 2: User Logout       logout();    }

    catch(TdWSException ex)    {       System.out.println("Error Code :" + ex.getErrorCode());       System.out.println("Error Message :" + ex.getErrorMessage());       String[] trace = ex.getServerStackTrace();       if(trace != null)       {         for(int i = 0 ; i < trace.length ; i++)           System.out.println("trace[" + i + "]" + trace[i]);        }    }    catch(Exception ex)    {       System.out.println("Never went into tdex :" + ex.getMessage());         ex.printStackTrace();    }
  }

  public static void logout() throws Exception  {    System.out.println("User logout.");   //Once all the webservices operations are done, invoke logout operation
   //On logout, user state is destroyed and the cookie is invalidated.    as.logout();    System.out.println("Done");   }
}

The getUserByNickname() method returns the user information based on the user nickname. An exception is raised if an invalid user nickname is provided.

The sample output for Example 12-1 is as follows:

Cookie : JSESSIONID=8c57046a22b87a5f71b2d03c454fae86e587d7d19393User Nickname :td_superuser
User Guid :09EC74D0F1A043ADE040578CDE022BB2User Primary Email :td_superuser@stacx01.us.oracle.comUser DN :cn=td_superuser,cn=users,dc=us,dc=oracle,dc=comUser Domain :stacx01.us.oracle.comUser Timezone :Pacific Standard TimeUser Locale :en_USUser Creation date :Sun Feb 26 19:54:18 PST 2006User Last logout time :Sun Feb 26 19:54:18 PST 2006User Last login time :Sun Feb 26 19:54:18 PST 2006User Displayname :AdminUser Presence URL :http://stacx01.us.oracle.com:7777/imtapp/Presence?TID=15886&UID=td_superuser%40us.oracle.com&MODE=JS&K1=AD4F6AD5A4A3D359C9F917DA6D00FEA0CBE79A4BUser Email id :td_superuser@stacx01.us.oracle.comUser client chat uri :rtcmsgr:sendmsg?td_superuser&#64us.oracle.comUser presence img url :http://stacx01.us.oracle.com:7777/imtapp/Presence?TID=15886&UID=td_superuser%40us.oracle.com&MODE=IMG&K1=6DDB8CCE52E0A9C70E7E6C78A5A14DAB2D8D9736User logout.Done

Retrieving User Information by E-mail

Following is an example for retrieving the user information by e-mail:

Example 12-2

import java.util.Date;import java.io.*;import java.util.*;import javax.mail.*;import javax.mail.internet.*;

import org.apache.axis.transport.http.HTTPConstants;import oracle.discussions.ws.exceptions.TdWSException;import oracle.discussions.ws.beans.*;import oracle.discussions.ws.AuthenticationServiceServiceLocator;import oracle.discussions.ws.AuthenticationServiceSoapBindingStub;import oracle.discussions.ws.AuthenticationService;import oracle.discussions.ws.UserServiceServiceLocator;import oracle.discussions.ws.UserServiceSoapBindingStub;import oracle.discussions.ws.UserService;

/** * Tests the Oracle Discussions Web Services functionality. * Invokes various Web Services methods to retrieve the results and  * check if the results are fine. */
public class WSClient{  private static AuthenticationService as = null;    public static String getCookie() throws Exception  {    //STEP - 0: User Login    //Create the service locator for authentication service. The locator contains
    //information about the Web Services endpoint     AuthenticationServiceServiceLocator assl = new
                          AuthenticationServiceServiceLocator();    //Get the handle to the actual webservices interface.     as = assl.getAuthenticationService();    //Indicate to the server that the client is interested in maintaining session.    //HTTP is stateless and the user state is maintained in the session.    //Unless the user is willing to participate in a session, user state cannot be
    //preserved.     ((AuthenticationServiceSoapBindingStub)as).setMaintainSession(true);    //Invoke the actual login webservices call.      as.login("td_superuser","welcome1");    //Retrieve the cookie. The cookie is set on successful authentication.
     String cookie = (String)((AuthenticationServiceSoapBindingStub)as)
       ._getCall().getMessageContext().getProperty(HTTPConstants.HEADER_COOKIE);  System.out.println("Cookie : " + cookie);  return cookie;
 }

 public static void main(String args[])  {   try   {       //STEP - 0: User Login       String cookie = getCookie();          //STEP - 1: Locate the Web Services end point.      //The Web Services locator contains the Web Services end point address.      //Hence instantiate the service locator.       UserServiceServiceLocator ussl = new UserServiceServiceLocator();      //Get a handle to the actual web service.       UserService us = ussl.getUserService();            //Indicate to the server that the user is willing to participate in the
      //session.      //Since HTTP is stateless, all the client data is maintained in the session.       ((UserServiceSoapBindingStub)us).setMaintainSession(true);      //Set the cookie retrieved in the call to login webservice.      //The cookie asserts user's identity to the server.       ((javax.xml.rpc.Stub)us)._setProperty(HTTPConstants.HEADER_COOKIE,cookie);      //Invoke the actual web services call.       User user = us.getUserByEmail("td_superuser@stacx01.us.oracle.com");
       if(user != null)       {          System.out.println("User Nickname :" + user.getNickname());          System.out.println("User Guid :" + user.getGuid());          System.out.println("User Primary Email :" +
                            user.getPrimaryEmailAddress());          System.out.println("User DN :" + user.getDN());          System.out.println("User Domain :" + user.getDomain());          System.out.println("User Timezone :" + user.getTimeZone());          System.out.println("User Locale :" + user.getLocale());          System.out.println("User Creation date :" +
                            user.getMemberSince().getTime());          System.out.println("User Last logout time :" +
                            user.getLastLogoutTime().getTime());          System.out.println("User Last login time :" +
                            user.getLastLoginTime().getTime());
          System.out.println("User Displayname :" + user.getDisplayName());          System.out.println("User Presence URL :" + user.getPresenceURL());          System.out.println("User Email id :" + user.getEmail());          System.out.println("User client chat uri :" + user.getClientChatUri());          System.out.println("User presence img url :" +
                            user.getPresenceImgUrl());       }

       //STEP - 2: User Logout        logout();     }     catch(TdWSException ex)     {         System.out.println("Error Code :" + ex.getErrorCode());               System.out.println("Error Message :" + ex.getErrorMessage());               String[] trace = ex.getServerStackTrace();               if(trace != null)               {                  for(int i = 0 ; i < trace.length ; i++)                  System.out.println("trace[" + i + "]" + trace[i]);               }             }           catch(Exception ex)           {              System.out.println("Never went into tdex :" + ex.getMessage());                ex.printStackTrace();           }        }        public static void logout() throws Exception        {              System.out.println("User logout.");             //Once all the webservices operations are done, invoke logout              //operation             //On logout, user state is destroyed and the cookie is invalidated
              as.logout();              System.out.println("Done");          }}

The getUserByEmail() method returns the user based on the e-mail ID of the user. An exception is raised if an invalid user e-mail address is provided. It returns the user bean representing the user. A TdWSException is thrown on any error in retrieving the user information or if the user e-mail is invalid.

The sample output of Example 12-2 is as follows:

Cookie : JSESSIONID=8c57046a22b87a5f71b2d03c454fae86e587d7d19393User Nickname :td_superuser
User Guid :09EC74D0F1A043ADE040578CDE022BB2User Primary Email :td_superuser@stacx01.us.oracle.comUser DN :cn=td_superuser,cn=users,dc=us,dc=oracle,dc=comUser Domain :stacx01.us.oracle.comUser Timezone :Pacific Standard TimeUser Locale :en_USUser Creation date :Sun Feb 26 19:54:18 PST 2006User Last logout time :Sun Feb 26 19:54:18 PST 2006User Last login time :Sun Feb 26 19:54:18 PST 2006User Displayname :AdminUser Presence URL :http://stacx01.us.oracle.com:7777/imtapp/Presence?TID=15886&UID=td_superuser%40us.oracle.com&MODE=JS&K1=AD4F6AD5A4A3D359C9F917DA6D00FEA0CBE79A4BUser Email id :td_superuser@stacx01.us.oracle.comUser client chat uri :rtcmsgr:sendmsg?td_superuser&#64us.oracle.comUser presence img url :http://stacx01.us.oracle.com:7777/imtapp/Presence?TID=15886&UID=td_superuser%40us.oracle.com&MODE=IMG&K1=6DDB8CCE52E0A9C70E7E6C78A5A14DAB2D8D9736User logout.Done