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
 

9 Understanding the Forum Service

The Forum Service interface represents consists of methods that operate on Oracle Discussions Forum. The Web Services interface provides the following operations:

This interface also provides bulk operations to create or delete multiple forums in a single invocation.

This chapter addresses the following tasks:

Creating a Forum

The following is an example for creating a forum with forum definition bean:

Example 9-1 Creating a Forum with a Valid Forum Definition Bean

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.ForumServiceSoapBindingStub;import oracle.discussions.ws.ForumServiceServiceLocator;import oracle.discussions.ws.ForumService;

public class WSClient{           private static AuthenticationService as = null;             public static String getCookie() throws Exception           {             //STEP - 1: 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 - 1: User Login        String cookie = getCookie();           //STEP - 2: Locate the web services end point.       //The web services locator contains the webservices end point address.       //Hence instantiate the service locator.        ForumServiceServiceLocator fssl = new ForumServiceServiceLocator();       //Get a handle to the actual web service.        ForumService fs = fssl.getForumService();             //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.        ((ForumServiceSoapBindingStub)fs).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)fs)._setProperty(HTTPConstants.HEADER_COOKIE,cookie);       //Invoke the actual web services call.        ForumDefinition fDefn = new ForumDefinition();        fDefn.setName("My Forum");        fDefn.setDisplayName("My Forum");        fDefn.setDescription("ForumCreated");        fDefn.setEmailAddress("myforum@stacx01.us.oracle.com");        fDefn.setWithAnnouncementBoard(false);        fDefn.setPublicForum(true);        fDefn.setEmailRoutingPolicy(2);      Forum forum = fs.create(-1,fDefn);      if(forum != null)      {          System.out.println("Is Public :" + forum.isPublicForum());          System.out.println("Forum is :" + forum.getId());          System.out.println("Type :" + forum.getContainerType());
          System.out.println("Creation date :" +
                              forum.getCreationDate().getTime());          System.out.println("Creator :" + forum.getCreator());          System.out.println("Description :" + forum.getDescription());          System.out.println("Display Path :" + forum.getDisplayPath());          System.out.println("Displayname :" + forum.getDisplayName());          LastPost lp = forum.getLastPost();          if(lp != null)          {              System.out.println("Lastpost Author :" + lp.getLastpostAuthor());              System.out.println("Last Posted date :" +
                                  lp.getLastpostDate().getTime());              System.out.println("Last post forum id :" +
                                  lp.getLastpostForumId());              System.out.println("Last post Topic id :" +
                                  lp.getLastpostTopicId());              System.out.println("Last post Message id :" +
                                  lp.getLastpostMessageId());          }
          System.out.println("is favorite :" + forum.isFavorite());          System.out.println("is new :" + forum.isNewFolder());          System.out.println("is new since last visit :" +
                                  forum.isNewSinceLastVisit());          System.out.println("is new since session :" +
                                  forum.isNewSinceSession());          System.out.println("name :" + forum.getName());          System.out.println("Id :" + forum.getId());          System.out.println("is locked :" + forum.isLocked());          System.out.println("thread count :" + forum.getThreadCount());          System.out.println("message count :" + forum.getMessageCount());          System.out.println("Rss Url :" + forum.getRssURL());          System.out.println("Webui URL :" + forum.getWebuiURL());          System.out.println("is category type :" + forum.isCategoryType());          System.out.println("Email Routing policy :"+
                                  forum.getEmailRoutingPolicy());       }       //STEP - 3: 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 create() method creates forums under the container represented by lParentId, with the properties specified in the fDefn bean array.

This method returns a forum bean that represents the forum object created on the server side.


Note:

An exception is raised if two forums at the same level have same name or same display name. After a forum is created, the forum name cannot be changed. Default settings are applied to the forum and you can update them later.

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

Cookie : JSESSIONID=8c57046a22b877e223ce6e5b4a4dae97fa9011e1fe8cIs Public :trueForum is :85769Type :2Creation date :Sun Feb 26 20:39:38 PST 2006Creator :td_superuserDescription :ForumCreatedDisplay Path :/My ForumDisplayname :My Forumis favorite :falseis new :falsesi new since last visit :falseis new since session :falsename :My forumId :85769is locked :falsethread count :0message count :0Rss Url :http://stacx01:8888/discussions/rss/board?fid=85769Webui URL :http://stacx01:8888/discussions/app/mainAction.do?fid=85769is category type :falseEmail Routing policy :2User logout.Done

Note:

The URLs mentioned in the sample output of Example 9-1 change as per the host on which the client is executing.

Updating Forum Settings

The following is an example for updating the forum settings:

Example 9-2 Updating Forum Settings

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.ForumServiceSoapBindingStub;import oracle.discussions.ws.ForumServiceServiceLocator;import oracle.discussions.ws.ForumService;

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 - 1: User Login      String cookie = getCookie();          //STEP - 2: Locate the Web Services end point.      //The web services locator contains the webservices end point address.            //Hence instantiate the service locator.             ForumServiceServiceLocator fssl = new ForumServiceServiceLocator();            //Get a handle to the actual web service.             ForumService fs = fssl.getForumService();                  //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.             ((ForumServiceSoapBindingStub)fs).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)fs)._setProperty(HTTPConstants.HEADER_
                                                    COOKIE,cookie);            //Invoke the actual web services call. The ID needs to be changed
            //accordingly             ForumSettings fSettings = fs.getForumSettings(6732);             if(fSettings != null)
             {               fSettings.setBeginQuotePrefix(fSettings.getBeginQuotePrefix());               fSettings.setAttachmentMaxSize(1000000);               fSettings.setCanAttach(true);               fSettings.setComposeEditor(2);               fSettings.setEditDeletePolicy(fSettings.getEditDeletePolicy());               fSettings.setFlatViewPagingSize(fSettings.getFlatViewPagingSize());               fSettings.setThreadView(2);
               fSettings.setEmailForwardPolicy(0);               fSettings.setEmailInboundPolicy(0);               fSettings.setOutgoingEmailDLSubjectFormat
                               (fSettings.getOutgoingEmailDLSubjectFormat());
               fSettings.setOutgoingEmailDLBodyFormat
                               (fSettings.getOutgoingEmailDLBodyFormat());               fSettings.setReplyPrefix("Re: From Announcements forum");               fSettings.setOriginalQuoted(fSettings.isOriginalQuoted());               fSettings.setPublicAccessPolicy(3);               fSettings.setEmailRoutingPolicy(2);               
              //The ID needs to be changed accordingly                 fSettings = fs.getForumSettings(6732);               if(fSettings != null)               {                  System.out.println("Retrieved changed forum settings");                  System.out.println("Begin Quote Prefix :" +
                                   fSettings.getBeginQuotePrefix());                  System.out.println("Attachment max size :" +
                                   fSettings.getAttachmentMaxSize());
                  System.out.println("Can Attach :" + fSettings.isCanAttach());                  System.out.println("Compose Editor :" +
                                   fSettings.getComposeEditor());                  System.out.println("Edit delete policy :" +
                                   fSettings.getEditDeletePolicy());                  System.out.println("Email Address " +
                                   fSettings.getEmailAddress());                  System.out.println("Flat view paging size :" +
                                   fSettings.getFlatViewPagingSize());                  System.out.println("Thread View :" + fSettings.getThreadView());                  System.out.println("Email forward policy :" +
                                   fSettings.getEmailForwardPolicy());                  System.out.println("Email inbound policy :" +
                             fSettings.getEmailInboundPolicy());             System.out.println("Outgoing email DL :" +
                             fSettings.getOutgoingEmailDL());             System.out.println("Outgoing email DL Subjet format: " +
                             fSettings.getOutgoingEmailDLSubjectFormat());             System.out.println("Outgoing email DL Body format :" +
                             fSettings.getOutgoingEmailDLBodyFormat());             System.out.println("Reply Prefix " + fSettings.getReplyPrefix());             System.out.println("Is original quoted :" +
                             fSettings.isOriginalQuoted());             System.out.println("Public access policy :" +
                             fSettings.getPublicAccessPolicy());             System.out.println("Email routing policy :" +
                             fSettings.getEmailRoutingPolicy());          }
      }       //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 updateForumSettings() method updates the settings for the forum represented by lForumId, with the settings supplied in forum settings bean, fs.

The fs bean represents the settings of a Oracle Discussions Forum. These settings define the forum description, display name of the forum, and other properties.

The setEmailAddress() method sets the e-mail address of the forum. The e-mail domain should be same as the domain for which Oracle Discussions internal administration is provisioned.

The setEmailForwardPolicy() method sets the e-mail forward policy of the forum. The valid values for the parameter policy are as follows:

The setEmailInboundPolicy() method sets the e-mail inbound policy of the forum. The valid values for the parameter policy are as follows:

The sample output for Example 9-2 is as follows:

Cookie : JSESSIONID=8c57046a22b88562b8545c3b459bbcae9546e94a8c49Retrieved changed forum settingsBegin Quote Prefix :On ${msg-sent-date}, ${msg-author} [${msg-from}] wrote ${msg-subject}:Attachment max size :1000000Can Attach :true
Compose Editor :2Edit delete policy :2Email Address changed_forum@stacx01.us.oracle.comFlat view paging size :10Thread View :2Email forward policy :0Email inbound policy :0Outgoing email DL :nullOutgoing email DL Subjet format: ${msg-subject} (${msg-board})Outgoing email DL Body format :New reply to topic <A href='${msg-thread-url}'>"${msg-thread}"</A> in Forum <A href='${msg-board-url}'>"${msg-board}"</A>.  <P> <B>From: </B><A href='mailto:${msg-from}'>${msg-author}</A><BR> <B>Subject: </B>${msg-subject}<BR> <B>Date: </B>${msg-sent-date}<BR> <BR> ${msg-body}<BR> <HR> View in <A href='${msg-url}'>Oracle Discussions</A>Reply Prefix Re: From Announcements forumIs original quoted :truePublic access policy :3Email routing policy :1User logout.Done

Note:

The e-mail ID in the sample output can change as per the e-mail address set to the forum of the actual user.

Listing the Topics in the Forum

The following is an example for listing the topics in the forum:

Example 9-3 Listing the Topics in the Forum

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.ForumServiceSoapBindingStub;import oracle.discussions.ws.ForumServiceServiceLocator;import oracle.discussions.ws.ForumService;

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 webservices end point address.       //Hence instantiate the service locator.        ForumServiceServiceLocator fssl = new ForumServiceServiceLocator();       //Get a handle to the actual web service.        ForumService fs = fssl.getForumService();             //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        ((ForumServiceSoapBindingStub)fs).setMaintainSession(true);       //Set the cookie retrieved in the call to login Web Service.             //The cookie asserts user's identity to the server.              ((javax.xml.rpc.Stub)fs)._setProperty(HTTPConstants.HEADER_
                                                       COOKIE,cookie);             //Invoke the actual web services call. The ID needs to be changed
             // accordingly
              Topic[] topics = fs.listTopics(6732,5,5,true,false);              if(topics != null)
              {                System.out.println("Retrieved :" + topics.length + " topics");                for(int i = 0 ; i < topics.length ; i++)                {                  if(topics[i] == null)                  {                    System.out.println("Topic not existing..:" + i);                    continue;                   }                  System.out.println("Subject :" + topics[i].getSubject());                  System.out.println("Web ui url :" + topics[i].getWebUIUrl());                  System.out.println("Web ui url :" + topics[i].getRssURL());
                  LastPost lp = topics[i].getLastPost();                  if(lp != null)                  {                    System.out.println("Lastpost Author :" +
                                             lp.getLastpostAuthor());                    System.out.println("Last Posted date :" +
                                             lp.getLastpostDate());                    System.out.println("Last post forum id :" +
                                             lp.getLastpostForumId());                    System.out.println("Last post Topic id :" +
                                             lp.getLastpostTopicId());                    System.out.println("Last post Message id :" +
                                             lp.getLastpostMessageId());                  }                 System.out.println("Msg Count :" + topics[i].getMsgCount());                 System.out.println("Subject :" + topics[i].getSubject());                 System.out.println("is Favorite :" + topics[i].isFavorite());                 System.out.println("is locked :" + topics[i].isLocked());                 System.out.println("Plain Text :" +
                                        topics[i].getBodyPlainText());                 String[] frmAdd = topics[i].getFromAddresses();                 if(frmAdd != null)                 {                   for(int j = 0 ; j < frmAdd.length ; j++)                      System.out.println("From Address :" + frmAdd[j]);                  }
                 System.out.println("Level :" + topics[i].getLevel());                 System.out.println("No of replies :" +
                                 topics[i].getNumberOfReplies());                 System.out.println("Oracle Msg Id :" + topics[i].getMessageId());                 System.out.println("is new since session :" +
                                 topics[i].isNewSinceSession());                 System.out.println("is new since last visit :" +
                                 topics[i].isNewSinceLastVisit());                 System.out.println("is new " + topics[i].isNewMessage());                 System.out.println("Has Attachments :" +
                                 topics[i].isHasAttachments());                 System.out.println("X Priority :" + topics[i].getXPriority());                 System.out.println("Sent dat :" + topics[i].getSentDate());                 System.out.println("Size :" + topics[i].getSize());                 System.out.println("Subject :" + topics[i].getSubject());          }                  }        //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 listTopics() method lists topics under the forum represented by lForumId. This method returns null if there are no topics under the forum. The listed topics can be sorted by creation date, by specifying bSortByCreation to true. The topics can also be sorted in the ascending order of the creation date, by specifying bAscending to true. This method has the following parameters:

The sample output for Example 9-3 is as follows:

Subject :Posted on 24thJan06988Web ui url :http://stacx01:8888/discussions/app/mainAction.do?fid=6732&tid=123545Rss url :http://stacx01:8888/discussions/rss/thread?fid=6732&tid=123545Lastpost Author :Admin <td_superuser@stacx01.us.oracle.com>Last Posted date : Sun Feb 26 19:54:18 PST 2006Last post forum id :6732Last post Topic id :123545Last post Message id :123545Msg Count :1Subject :Posted on 24thJan06988is Favorite :falseis locked :falsePlain Text :Posted on 24thJan06988From Address :Admin <td_superuser@stacx01.us.oracle.com>Level :0No of replies :0Oracle Msg Id :123545is new since session :falseis new since last visit :falseis new falseHas Attachments :falseX Priority :1Sent dat : Sun Feb 26 19:54:18 PST 2006Size :438Subject :Posted on 24thJan06988

Note:

The URLs mentioned in the sample output of Example 9-3 change as per the host on which the client is executing.