Skip Headers
Oracle® Workspaces Web Services Application Developer's Guide
10g Release 1 (10.1.2.2)

Part Number B28207-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

5 Home Service

The Home service allows you to perform workspace life cycle operations such as creating, listing, and deleting workspaces and retrieving workspaces by ID or path. The Home service also allows you to search for content within a workspace.

Example: Create New Workspace

The following sample will create a new workspace. If the workspace already exists it will try to retrieve it.

Example 5-1 HomeServiceSample.java

package oracle.sample.workspaces.ws;
 
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import oracle.workspaces.ws.AuthenticationService;
import oracle.workspaces.ws.HomeService;
import oracle.workspaces.ws.HomeServiceServiceLocator;
import oracle.workspaces.ws.HomeServiceSoapBindingStub;
import oracle.workspaces.ws.beans.CreateWorkspaceResponseItem;
import oracle.workspaces.ws.beans.WorkspaceDefinition;
import oracle.workspaces.ws.beans.WorkspaceItem;
import oracle.workspaces.ws.exceptions.CwWSException;
import org.apache.axis.transport.http.HTTPConstants;
 
public class HomeServiceSample 
{
  public static HomeService configureHomeService(
    String szAuthCookie) throws ServiceException
  {
 
    // Once authenticated, the user can invoke any Oracle
    // Workspaces Web service until he or she invokes the logout method.
    //
    // The cookie retrieved from the Authentication service
    // is to be set on every client stub that invokes operations on
    // the Web services server.
    //
    // Initialize the service locator for the Home service.
    // The service location contains the Web services endpoint URL
    // for the category service.
  
    HomeServiceServiceLocator hssl = new HomeServiceServiceLocator();
    
    // Retrieve a reference to the remote Home service.
    
    HomeService hs = hssl.getHomeService();
    
    // Indicate the client's willingness to participate in the session.
    
    ((HomeServiceSoapBindingStub)hs).setMaintainSession(true);
    
    // Set the cookie before invoking the operation on the stub.
    // Setting this cookie indicates that the client's HTTP session
    // credentials have been sent to the server.
    //
    // Sessions are managed through cookies.
    
    ((javax.xml.rpc.Stub)hs).
      _setProperty(HTTPConstants.HEADER_COOKIE,szAuthCookie);
      
    // Now you may use the reference to the remote Home service to
    // invoke Web services methods to perform various operations.      
    
    return hs;
  }
  
  public static WorkspaceItem createOrRetrieveWorkspace(
    HomeService szHomeService,
    String szWorkspaceName,
    String szWorkspaceDisplayName,
    String szWorkspaceDescription,
    String szDefaultMemberRoleType,
    String szMemberAccessSetting)
    throws CwWSException, RemoteException
  {
    
    WorkspaceItem wspc = null;
    
    // Create workspace definition object
      
    WorkspaceDefinition wspcDef = new WorkspaceDefinition();
    wspcDef.setName(szWorkspaceName);
    wspcDef.setDisplayName(szWorkspaceDisplayName);
    wspcDef.setDescription(szWorkspaceDescription);
    wspcDef.setDefaultMemberRoleType(szDefaultMemberRoleType);
    wspcDef.setMemberAccessSetting(szMemberAccessSetting);
    wspcDef.setPubliclyListed(true);
    wspcDef.setAllowPartialSuccess(true);
    
    try {
 
      // Invoke method on home service to create a new workspace
      
      CreateWorkspaceResponseItem resp =
        szHomeService.createWorkspace(wspcDef);
      wspc = resp.getWorkspaceItem();
    }
    catch(CwWSException e)
    {
      // An exception will be thrown if the
      // workspace already exists
      
      System.out.println(
        "CWESException caught: " + e.getErrorMessage());
        
      try {
      
        // Try to retrieve the workspace if
        // it exists
        
        System.out.println("Trying to retrieve " + "/" +
          szWorkspaceName.toUpperCase());
        
        wspc = szHomeService.getWorkspaceByPath(
          "/" + szWorkspaceName.toUpperCase());
      } catch (CwWSException e2) 
      {
        System.out.println("CwWSException caught trying to retrieve " +
          "workspace: " + e2.getMessage());
        throw e2;
      }
    }
    return wspc;
  }
 
  public static void main(String[] args)
  {
    try {
    
      // Get authentication cookie
      
      AuthenticationService myAuthenticationService =
        AuthenticationSample.configureAuthenticationService(
          "orcladmin",
          "welcome1");
          
      String authCookie = AuthenticationSample.getAuthenticationCookie
        (myAuthenticationService);
 
      
      // Retrieve HomeService and set authentication cookie
      HomeService myHomeService =
        HomeServiceSample.configureHomeService(authCookie);
        
      // Create new workspace
      WorkspaceItem myWorkspace =
        HomeServiceSample.createOrRetrieveWorkspace(
          myHomeService,
          "NewWorkspace",
          "My New Workspace",
          "Description of My New Workspace",
          "WRITER",
          "ENABLED");
          
      // Display properties of newly created workspace
      System.out.println("Details of newly created " +
        "(or retrieved) workspace:");
      System.out.println("Workspace Id: " +
        myWorkspace.getWorkspaceUid());
      System.out.println("ContactEmailAddress: " +
        myWorkspace.getContactEmailAddress());
      System.out.println("Workspace Name: " +
        myWorkspace.getName());
      System.out.println("Workspace Owner: " +
        myWorkspace.getOwner());
      System.out.println("Publicly Listed: " +
        myWorkspace.isPubliclyListed());
      System.out.println("Path: " +
        myWorkspace.getPath());
        
      // Invoke the logout method to destroy the user credentials
      // stored in the HTTP session.
      //
      // On logout invocation, the HTTP session is invalidated and
      // the cookie is destroyed.
      // 
      // The user's state is lost and hence the user will not be able
      // to invoke any other Web services methods
      // until he or she logs in again.
      
      myAuthenticationService.logout();      
        
      
    } catch (CwWSException cwwse) 
    {
      System.out.println("CwWSException caught: " + cwwse.getMessage());
    } catch (Exception e) 
    {
      System.out.println("Exception caught: " + e.toString());
    }
    
  }
}