Oracle® Workspaces Web Services Application Developer's Guide 10g Release 1 (10.1.2.2) Part Number B28207-01 |
|
|
View PDF |
The Discussion service provides methods for working with discussions resources.
Three kinds of operations are available:
Board operations allow you to create, update, delete, and retrieve boards (which are called forums in the Oracle Workspaces user interface).
Thread operations allow you to retrieve and delete messages within a thread, add and remove messages within a thread to or from a user's favorites, and retrieve popular threads. A thread is an aggregation of related messages. A thread is created when a new message is posted on a board, and that message is not a reply to an existing message.
Message operations allow you to post, retrieve, and delete messages.
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()); } } }