Oracle® Discussions Application Developer's Guide
10g Release 1(10.1.2) B28208-02 |
|
Previous |
Next |
The Message Service interface represents the operations related to Oracle Discussions Message. Messages are either new posts into a board (and therefore topics) or replies to other messages. Messages may contain attachments. In general, the first message of a thread is also referred to as the thread itself, while all its replies are just simply referred as messages. The Web Service interface provides for the following operations:
Replying to a message
Editing a message
Fetching the message details, given the message id
Retrieving the message in a raw byte format
Fetching parent topic, given a message
Clipping a message and all its replies into another topic
Hiding a message
Unhiding a message
Deleting a message
Apart from the preceding operations, it also provides bulk operations to hide or show multiple messages in a single invocation.
This chapter addresses the following tasks:
The following is an example for replying to a message:
Example 11-1 Replying to a Message
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.MessageServiceSoapBindingStub; import oracle.discussions.ws.MessageServiceServiceLocator; import oracle.discussions.ws.MessageService; 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. MessageServiceServiceLocator fssl = new MessageServiceServiceLocator(); //Get a handle to the actual web service. MessageService fs = fssl.getMessageService(); //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. ((MessageServiceSoapBindingStub)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. MessageDefinition mDefn = new MessageDefinition(); mDefn.setSubject("Yahoo Email Solution"); mDefn.setBody("<a href=\"http://www.yahoomail.com\">Dont Click</a>"); mDefn.setHTMLContentType(true); //The IDs need to be changed accordingly ForumMessage topic = fs.reply(15524,281488,281488,mDefn); if(topic != null) { System.out.println("Subject :" + topic.getSubject()); System.out.println("Plain Text :" + topic.getBodyPlainText()); String[] frmAdd = topic.getFromAddresses(); if(frmAdd != null) { for(int j = 0 ; j < frmAdd.length ; j++) System.out.println("From Address :" + frmAdd[j]); } System.out.println("Level :" + topic.getLevel()); System.out.println("No of replies :" + topic.getNumberOfReplies()); System.out.println("Oracle Msg Id :" + topic.getMessageId()); System.out.println("is new since session :" + topic.isNewSinceSession()); System.out.println("is new since last visit :" + topic.isNewSinceLastVisit()); System.out.println("is new " + topic.isNewMessage()); System.out.println("Has Attachments :" + topic.isHasAttachments()); System.out.println("X Priority :" + topic.getXPriority()); System.out.println("Sent dat :" + topic.getSentDate().getTime()); System.out.println("Size :" + topic.getSize()); System.out.println("Webui URL :" + topic.getWebUIUrl()); System.out.println("HTML ? :" + topic.isHTMLContentType()); System.out.println("Hidden :" + topic.isHidden()); } //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 reply()
method replies to the message specified by iMsgId
. The reply posted will be a child message of the message specified. Only users with forum writer or higher role can post a reply, unless the forum is public, with anonymous posting setting enabled.
The sample output for Example 11-1 is as follows:
Cookie : JSESSIONID=8c57046a22b81295628fa8f249819566d10096888122Subject :Yahoo Email SolutionPlain Text :<a href="http://www.yahoomail.com" target="_blank">Dont Click</a>From Address :Admin <td_superuser@stacx01.us.oracle.com>Level :1No of replies :0Oracle Msg Id :281489is new since session :trueis new since last visit :trueis new trueHas Attachments :falseX Priority :1Sent dat :Sun Feb 26 21:35:58 PST 2006Size :579Webui URL :http://stacx01:8888/discussions/app/mainAction.do?fid=15524&tid=281488&mid=281489#281489HTML ? :trueHidden :falseUser logout.Done
The following is an example for creating the message from byte:
Example 11-2 Creating the Message from Byte
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.MessageServiceSoapBindingStub;import oracle.discussions.ws.MessageServiceServiceLocator;import oracle.discussions.ws.MessageService; 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. MessageServiceServiceLocator fssl = new MessageServiceServiceLocator(); //Get a handle to the actual web service. MessageService fs = fssl.getMessageService(); //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. ((MessageServiceSoapBindingStub)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. byte[] bytes = fs.getMessageInByte(15524,281488,281488); if(bytes != null) { //The IDs will change accordingly ForumMessage topic = fs.createMessageFromByte(15524,281488,281488,bytes); if(topic != null) { System.out.println("Subject :" + topic.getSubject()); System.out.println("Plain Text :" + topic.getBodyPlainText()); String[] frmAdd = topic.getFromAddresses(); if(frmAdd != null) { for(int j = 0 ; j < frmAdd.length ; j++) System.out.println("From Address :" + frmAdd[j]); } System.out.println("Level :" + topic.getLevel()); System.out.println("No of replies :" + topic.getNumberOfReplies()); System.out.println("Oracle Msg Id :" + topic.getMessageId()); System.out.println("is new since session :" + topic.isNewSinceSession()); System.out.println("is new since last visit :" + topic.isNewSinceLastVisit()); System.out.println("is new " + topic.isNewMessage()); System.out.println("Has Attachments :" + topic.isHasAttachments()); System.out.println("X Priority :" + topic.getXPriority()); System.out.println("Sent dat :" + topic.getSentDate().getTime()); System.out.println("Size :" + topic.getSize()); System.out.println("Webui URL :" + topic.getWebUIUrl()); System.out.println("HTML ? :" + topic.isHTMLContentType()); System.out.println("Hidden :" + topic.isHidden()); } } //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 reply posted will be a child message of the message specified. The byte[]
array should be MIME-compatible. This is useful in creating messages with attachments. The entire message, along with all the headers and attachments, is converted into a byte array by createMessageFromByte()
. The same byte array can be used in creating the message. Only users with forum writer or higher role can post a reply, unless the forum is public, with the anonymous posting setting enabled.
Note: Threaded Discussions maintains the threading information for messages posted to a board. Threading information is used to sort a discussion thread in thread order. Such an operation is based on the usage of theReferences message header which keeps the IDs of the parent messages in a comma separated list. If the references header is absent, then messages are threaded based on the message subject.
|
The sample output for Example 11-2 is as follows:
Cookie : JSESSIONID=8c57046a22b888e1210975ab43f4b75ca85fa663c175Subject :Topic-1Plain Text :Topic-1From Address :Admin <td_superuser@stacx01.us.oracle.com>Level :1No of replies :0Oracle Msg Id :281490is new since session :trueis new since last visit :trueis new trueHas Attachments :falseX Priority :1Sent dat :Sun Feb 26 21:42:44 PST 2006Size :540Webui URL :http://stacx01:8888/discussions/app/mainAction.do?fid=15524&tid=281488&mid=281490#281490HTML ? :falseHidden :falseUser logout.Done
The following is an example for editing a message:
Example 11-3 Editing a Message
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.MessageServiceSoapBindingStub;import oracle.discussions.ws.MessageServiceServiceLocator;import oracle.discussions.ws.MessageService; 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. MessageServiceServiceLocator fssl = new MessageServiceServiceLocator(); //Get a handle to the actual web service. MessageService fs = fssl.getMessageService(); //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 ((MessageServiceSoapBindingStub)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 IDs need to be changed //accordingly ForumMessage topic = fs.editMessage(15524,281488,281488,"Edited Subject","Edited Body"); if(topic != null) { System.out.println("Subject :" + topic.getSubject()); System.out.println("Plain Text :" + topic.getBodyPlainText()); String[] frmAdd = topic.getFromAddresses(); if(frmAdd != null) { for(int j = 0 ; j < frmAdd.length ; j++) System.out.println("From Address :" + frmAdd[j]); } System.out.println("Level :" + topic.getLevel()); System.out.println("No of replies :" + topic.getNumberOfReplies()); System.out.println("Oracle Msg Id :" + topic.getMessageId()); System.out.println("is new since session :" + topic.isNewSinceSession()); System.out.println("is new since last visit :" + topic.isNewSinceLastVisit()); System.out.println("is new " + topic.isNewMessage()); System.out.println("Has Attachments :" + topic.isHasAttachments()); System.out.println("X Priority :" + topic.getXPriority()); System.out.println("Sent dat :" + topic.getSentDate().getTime()); System.out.println("Size :" + topic.getSize()); System.out.println("Webui URL :" + topic.getWebUIUrl()); System.out.println("HTML ? :" + topic.isHTMLContentType()); System.out.println("Hidden :" + topic.isHidden()); } //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 editMessage()
method edits the message subject and content. A message should have either a subject or a body. The topic posted will be of text or plain content type. The lForumId
and iTopicId
should represent the parent forum and topic of the message respectively. The old values of the message subject and content will be overwritten with the values that are provided.
The sample output for Example 11-3 is as follows:
Cookie : JSESSIONID=8c57046a22b88d154290041d4bd0bc48bff029d632b1Subject :Edited SubjectPlain Text :Edited BodyFrom Address :Admin <td_superuser@stacx01.us.oracle.com>Level :0No of replies :2Oracle Msg Id :281488is new since session :falseis new since last visit :falseis new falseHas Attachments :falseX Priority :1Sent dat :Sun Feb 26 20:13:13 PST 2006Size :472Webui URL :http://stacx01:8888/discussions/app/mainAction.do?fid=15524&tid=281488&mid=281488#281488HTML ? :falseHidden :falseUser logout.Done
The following is an example for editing a message with a byte array:
Example 11-4 Editing a Message with a 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.MessageServiceSoapBindingStub;import oracle.discussions.ws.MessageServiceServiceLocator;import oracle.discussions.ws.MessageService; 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. MessageServiceServiceLocator fssl = new MessageServiceServiceLocator(); //Get a handle to the actual web service. MessageService fs = fssl.getMessageService(); //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. ((MessageServiceSoapBindingStub)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 IDs need to be changed //accordingly Byte[] bytes = fs.getMessageInByte(15524,281488,281488); //The Ids need to be changed accordingly ForumMessage topic = fs.editMessageWithByte(15524,281488,281488,bytes); if(topic != null) { System.out.println("Subject :" + topic.getSubject()); System.out.println("Plain Text :" + topic.getBodyPlainText()); String[] frmAdd = topic.getFromAddresses(); if(frmAdd != null) { for(int j = 0 ; j < frmAdd.length ; j++) System.out.println("From Address :" + frmAdd[j]); } System.out.println("Level :" + topic.getLevel()); System.out.println("No of replies :" + topic.getNumberOfReplies()); System.out.println("Oracle Msg Id :" + topic.getMessageId()); System.out.println("is new since session :" + topic.isNewSinceSession()); System.out.println("is new since last visit :" + topic.isNewSinceLastVisit()); System.out.println("is new " + topic.isNewMessage()); System.out.println("Has Attachments :" + topic.isHasAttachments()); System.out.println("X Priority :" + topic.getXPriority()); System.out.println("Sent dat :" + topic.getSentDate().getTime()); System.out.println("Size :" + topic.getSize()); System.out.println("Webui URL :" + topic.getWebUIUrl()); System.out.println("HTML ? :" + topic.isHTMLContentType()); System.out.println("Hidden :" + topic.isHidden()); } //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 editMessageWithByte()
method edits the topic with the byte array supplied. The byte array should be MIME compatible. The entire message is replaced with the content of the byte array. A new MIME message object is constructed and it overwrites the entire old message.
The sample output for Example 11-4 is as follows:
Cookie : JSESSIONID=8c57046a22b88d154290041d4bd0bc48bff029d632b1Subject :Edited SubjectPlain Text :Edited BodyFrom Address :Admin <td_superuser@stacx01.us.oracle.com>Level :0No of replies :2Oracle Msg Id :281488is new since session :falseis new since last visit :falseis new falseHas Attachments :falseX Priority :1Sent dat :Sun Feb 26 20:13:13 PST 2006Size :472Webui URL :http://stacx01:8888/discussions/app/mainAction.do?fid=15524&tid=281488&mid=281488#281488HTML ? :falseHidden :falseUser logout.Done