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
 

10 Understanding the Topic Service

The Topic Service interface represents the methods that operate on Oracle Discussions Topics. The interface provides the following operations:

It also provides bulk operations to create or delete multiple topics in one invocation. This chapter addresses the task of Creating a Topic.

Creating a Topic

The following is an example for creating a topic from the byte array:

Example 10-1 Creating a Topic from the Byte Array

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.TopicServiceSoapBindingStub;import oracle.discussions.ws.TopicServiceServiceLocator;import oracle.discussions.ws.TopicService;

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.              TopicServiceServiceLocator tssl = new TopicServiceServiceLocator();             //Get a handle to the actual web service.              TopicService ts = tssl.getTopicService();                   //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.              ((TopicServiceSoapBindingStub)ts).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)ts)._setProperty(HTTPConstants.HEADER_
                                                       COOKIE,cookie);             //Invoke the actual web services call.              byte[] bytes = null;
             //Create a MIME Compatible byte array              if(bytes != null)              {
               //The ID needs to be changed accordingly
                ForumMessage msg = ts.createTopicFromByte(15524,bytes);                if(msg != null)                {                 System.out.println("Subject :" + msg.getSubject());                 System.out.println("Web ui url :" + msg.getWebUIUrl());          System.out.println("Subject :" + msg.getSubject());          System.out.println("Plain Text :" + msg.getBodyPlainText());          String[] frmAdd = msg.getFromAddresses();          if(frmAdd != null)
          {              for(int j = 0 ; j < frmAdd.length ; j++)                  System.out.println("From Address :" + frmAdd[j]);          }          System.out.println("Level :" + msg.getLevel());          System.out.println("No of replies :" + msg.getNumberOfReplies());          System.out.println("Oracle Msg Id :" + msg.getMessageId());          System.out.println("is new since session :" + msg.isNewSinceSession());          System.out.println("is new since last visit :" +
                                       msg.isNewSinceLastVisit());          System.out.println("is new " + msg.isNewMessage());          System.out.println("Has Attachments :" + msg.isHasAttachments());          System.out.println("X Priority :" + msg.getXPriority());          System.out.println("Sent dat :" + msg.getSentDate());          System.out.println("Size :" + msg.getSize());          System.out.println("Subject :" + msg.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 createTopicFromByte() creates a topic from the specified byte array.

The byte[] array should be MIME compatible. It is useful in creating topics with attachments. The entire message, along with all the headers and attachments is converted into a byte[]. The same byte[] can be used in creating a topic. This method accepts two parameters:

The method returns ForumMessage which is a bean that represents the newly created topic.

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

Cookie : JSESSIONID=8c57046a22b87bc7c77f14844facb3d6e912391d9f5dSubject :Topic-1Web ui url :http://stacx01:8888/discussions/app/mainAction.do?fid=15524&tid=281488&mid=281488#281488Subject :Topic-1Plain Text :Topic-1From Address :Admin <td_superuser@stacx01.us.oracle.com>Level :0No of replies :0Oracle Msg Id :281488is new since session :trueis new since last visit :trueis new trueHas Attachments :falseX Priority :1Sent date : Sun Feb 26 19:54:18 PST 2006Size :405Subject :Topic-1User logout.Done