Oracle® Discussions Application Developer's Guide
10g Release 1(10.1.2) B28208-02 |
|
Previous |
Next |
The MyDiscussions Service interface provides methods to access content of user interest. This interface has methods for the following operations:
Bookmarking Oracle Discussions elements
Selectively accessing content of user interest
Selectively accessing most popular or recent Oracle Discussions content
Searching the favorite container of a user
This interface also provides bulk methods to add or remove containers and topics to favorites container.
This chapter focusses on Searching the Favorite Container of a User.
The following is an example for searching the favorite container of a user:
Example 14-1 Searching the favorite container of a user
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.MyDiscussionsServiceSoapBindingStub;import oracle.discussions.ws.MyDiscussionsServiceServiceLocator;import oracle.discussions.ws.MyDiscussionsService; 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 webservices 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. MyDiscussionsServiceServiceLocator mdssl = new MyDiscussionsServiceServiceLocator(); //Get a handle to the actual web service. MyDiscussionsService mdsl = mdssl.getMyDiscussionsService(); //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. ((MyDiscussionsServiceSoapBindingStub)mdsl) .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)mdsl)._setProperty(HTTPConstants.HEADER_ COOKIE,cookie); //Invoke the actual web services call. SearchTerm st = new SearchTerm(); st.setAuthor("td_superuser"); ForumMessage[] topics = mdsl.search(st); if(topics != null) { for(int i = 0 ; i < topics.length ; i++) { System.out.println("Got Something"); System.out.println("Subject :" + topics[i].getSubject()); 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 date :" + topics[i].getSentDate()); System.out.println("Size :" + topics[i].getSize()); System.out.println("HTML ? :" + topics[i].isHTMLContentType()); System.out.println("WebUI URL :" + topics[i].getWebUIUrl()); } } //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 search()
method searches favorite containers of the user for the search criterion specified in the search term. It returns null
if there are no favorite containers for the user. The search criterion can be supplied in the search term. Wild-card searches are also possible. The search is limited to searching message subject and content. To search on a custom list of containers, use the search method in the Container Service interface.
The sample output for Example 14-1 is as follows:
Subject :To be EditedPlain Text :a<table border="1" cellpadding="1" cellspacing="1" width="500"><tbody><tr><td>Krishna<br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td><br></td></tr><tr><td><br></td><td><br></td><td>Chaitanya<br></td></tr></tbody></table><br><br><a href="http://www.oracle.com" target="_blank">Oracle</a><br>From Address :Admin <td_superuser@stacx01.us.oracle.com>Level :0No of replies :0Oracle Msg Id :81131is new since session :falseis new since last visit :falseis new falseHas Attachments :trueX Priority :1Sent date :java.util.GregorianCalendar[time=1137756640000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2006,MONTH=0,WEEK_OF_YEAR=3,WEEK_OF_MONTH=3,DAY_OF_MONTH=20,DAY_OF_YEAR=20,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=11,HOUR_OF_DAY=11,MINUTE=30,SECOND=40,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]Size :63580HTML ? :trueWebUI URL :http://stacx01:8888/discussions/app/mainAction.do?fid=6826&tid=81131&mid=81131#81131