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

12 Discussion Service

The Discussion service provides methods for working with discussions resources.

Three kinds of operations are available:

Example: Create Board, Post Message, and Post Reply

The following sample creates a board in a specified workspace, or retrieves the board if one with the same name already exists. It then posts a message on the board, then posts a reply to that message:

Example 12-1 DiscussionServiceSample.java

package oracle.sample.workspaces.ws;
 
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import oracle.workspaces.ws.AuthenticationService;
import oracle.workspaces.ws.DiscussionService;
import oracle.workspaces.ws.DiscussionServiceServiceLocator;
import oracle.workspaces.ws.DiscussionServiceSoapBindingStub;
import oracle.workspaces.ws.HomeService;
import oracle.workspaces.ws.beans.BoardDefinition;
import oracle.workspaces.ws.beans.BoardItem;
import oracle.workspaces.ws.beans.MessageDefinition;
import oracle.workspaces.ws.beans.MessageItem;
import oracle.workspaces.ws.beans.ThreadItem;
import oracle.workspaces.ws.beans.WorkspaceItem;
import oracle.workspaces.ws.exceptions.CwWSException;
import org.apache.axis.transport.http.HTTPConstants;
 
public class DiscussionServiceSample 
{
  public static DiscussionService configureDiscussionService(
    String szAuthCookie) throws ServiceException
  {
    DiscussionServiceServiceLocator dssl =
      new DiscussionServiceServiceLocator();
    DiscussionService discussionService =
      dssl.getDiscussionService();
    ((DiscussionServiceSoapBindingStub)discussionService).
      setMaintainSession(true);
    ((javax.xml.rpc.Stub) discussionService).
      _setProperty(HTTPConstants.HEADER_COOKIE, szAuthCookie);
    return discussionService;
  }
  
  public static MessageItem createMessage(
    DiscussionService szDiscussionService,
    String szBoardID,
    String szWorkspaceID) throws RemoteException, CwWSException
  {
    MessageItem myMessage = null;
    String[] mAttrib = {"CONTENT","CONTENT_TYPE","SIZE",
      "LEVEL_IN_THREAD","IS_MARKED_DELETED",
      "PRIORITY","HAS_ATTACHMENTS"};
 
    MessageDefinition msgDef = new MessageDefinition();
    msgDef.setContentType("text/plain");
    msgDef.setText("Text of my new message2");
    msgDef.setSubject("Subject of my new message2");
    myMessage = szDiscussionService.createMessage(
      szWorkspaceID,
      szBoardID,
      null, // Create a new thread with this message
      msgDef,
      mAttrib);
      
    return myMessage;
  }
  
  public static MessageItem postReply(
    DiscussionService szDiscussionService,
    String szBoardID,
    String szWorkspaceID,
    String szMessageID,
    String szThreadID) throws RemoteException, CwWSException
  {
    // Post a reply to the message specified by szMessageID
    
    MessageItem myMessage = null;
    String[] mAttrib = {"CONTENT","CONTENT_TYPE","SIZE",
       "LEVEL_IN_THREAD","IS_MARKED_DELETED",
      "PRIORITY","HAS_ATTACHMENTS"};
 
    MessageDefinition msgDef = new MessageDefinition();
    msgDef.setContentType("text/plain");
    msgDef.setText("Text of my reply2");
    msgDef.setSubject("Subject of my reply2");
    msgDef.setMessageRepliedTo(szMessageID);
    
    myMessage = szDiscussionService.createMessage(
      szWorkspaceID,
      szBoardID,
      szThreadID,
      msgDef,
      mAttrib);
      
    return myMessage;
    
  }
  
  public static BoardItem createDiscussionBoard(
    DiscussionService szDiscussionService,
    String szWorkspaceID) throws RemoteException, CwWSException
  {
    
    BoardItem myBoard = null;
    
    // Create a board definition object and set its attributes.
    BoardDefinition boardDef = new BoardDefinition();
    boardDef.setDescription("Board1 desc");
    boardDef.setName("Board1 name");
    boardDef.setDisplayName("Board1 name");
    boardDef.setBoardEditDeletePolicy("NONE");
    boardDef.setEmailInboundPolicy("NONE");
    String[] attrib = {"EDIT_DELETE_POLICY","INBOUND_POLICY"};
    
    // Invoke method to create board within workspace.
    
    try {
      myBoard = szDiscussionService.createBoard(
        szWorkspaceID,
        boardDef,
        attrib);
    } catch (CwWSException cwwse) 
    {
      // createBoard will throw an exception if a board
      // of the same name already exists.
      // 
      // Attempt to retrieve the board with the same name
      
      myBoard = szDiscussionService.getBoardByName(
        szWorkspaceID,
        "Board1 name",
        null);
    }
    return myBoard;
  }
  
 public static void main(String[] args)
  {
    try {
      // Get authentication cookie
      
      AuthenticationService myAuthenticationService =
        AuthenticationSample.configureAuthenticationService(
          "rg4",
          "welcome1");
          
      String authCookie = AuthenticationSample.getAuthenticationCookie
        (myAuthenticationService);
        
      System.out.println("Retrieved authentication cookie : " + authCookie);
      
      // Get DiscussionSerivce and set authentication cookie
      
      DiscussionService myDiscussionService =
        DiscussionServiceSample.configureDiscussionService(authCookie);
      
      // Retrieve HomeService and set authentication cookie
      HomeService myHomeService =
        HomeServiceSample.configureHomeService(authCookie);
        
      // Create new workspace (or retrieve it if it already exists)
      WorkspaceItem myWorkspace =
        HomeServiceSample.createOrRetrieveWorkspace(
          myHomeService,
          "NewWorkspace",
          "My New Workspace",
          "Description of My New Workspace",
          "WRITER",
          "ENABLED");
          
      System.out.println("Retrieved or created workspace");
      
      BoardItem myBoard = DiscussionServiceSample.createDiscussionBoard(
        myDiscussionService,
        myWorkspace.getWorkspaceUid());
      
      System.out.println("Created or retrieved discussion board");
 
      // Create a new message
  
      MessageItem myMessage = DiscussionServiceSample.createMessage(
        myDiscussionService,
        myBoard.getId(),
        myWorkspace.getWorkspaceUid());
      
      System.out.println("Created message");
      
      // Post a reply to that message
      
      DiscussionServiceSample.postReply(
        myDiscussionService,
        myBoard.getId(),
        myWorkspace.getWorkspaceUid(),
        myMessage.getId(),
        myMessage.getThreadUid());
 
      System.out.println("Posted a reply");        
 
      myAuthenticationService.logout();             
 
    } catch (CwWSException cwwse) 
    {
      System.out.println("CwWSException caught: " + cwwse.getMessage());
      cwwse.printStackTrace();
    } catch (Exception e) 
    {
      System.out.println("Exception caught: " + e.toString());
    }
  }
}