Oracle® Discussions Application Developer's Guide
10g Release 1(10.1.2) B28208-02 |
|
Previous |
Next |
The Subscription Service interface provides methods related to subscriptions on Oracle Discussions elements. Any Oracle Discussions element that is added as a favorite can be subscribed. After subscribing to an element, the subscribing user will receive e-mail notifications, if there is any change in the state of the element or any of its child elements. For example, if a user subscribes to a forum, the user will receive a notification on any change in any of the topics or messages in the forum or if there is any change in the forum state itself.
A subscription is removed under the following circumstances:
User access is removed on that element
The element is deleted
User unsubscribes that element
This chapter addresses the following tasks:
The following is an example for updating a container subscription:
Example 13-1 Updating a Subscription
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.SubscriptionServiceSoapBindingStub;import oracle.discussions.ws.SubscriptionServiceServiceLocator;import oracle.discussions.ws.SubscriptionService; 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. SubscriptionServiceServiceLocator sssl = new SubscriptionServiceServiceLocator(); //Get a handle to the actual web service. SubscriptionService ss = sssl.getSubscriptionService(); //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 ((SubscriptionServiceSoapBindingStub)ss).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)ss)._setProperty(HTTPConstants.HEADER_COOKIE,cookie); //Invoke the actual web services call. Subscription sub = new Subscription(); //The ID changes accordingly sub.setContainerId(85766); sub.setType(0); sub.setEmailAddress("tduser@stacx01.us.oracle.com"); //The ID changes accordingly sub.setTopicId(281487); ss.updateSubscription(sub); System.out.println("Subscription successfully updated"); //The IDs need to be changed accordingly sub = ss.getTopicSubscription(85766,281487); if(sub != null) { System.out.println("Author :" + sub.getEmailAddress()); System.out.println("Container id :" + sub.getContainerId()); System.out.println("Topic id :" + sub.getTopicId()); } //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 updateSubscription()
method updates the subscription corresponding to the container or the topic represented by the id
fields in the subscription bean. If the topic ID is 0
, and if the container ID represents a valid container, then the subscription represents a container subscription and is updated. If both topic and container IDs are greater than 0
, and if the IDs represent a valid topic, then the topic subscription is updated. This method returns a a subscription bean corresponding to the subscription with the updated values.
The getContainerSubscription()
method returns the subscription for the logged-in user on the container represented by lContainerId
. This method returns null
if the user does not have any subscription on the container.
The sample output for Example 13-1 is as follows:
Cookie : JSESSIONID=8c57046a22b89075a82ab179489c9d53ffc82b40f783Subscription successfully updatedAuthor :tduser@stacx01.us.oracle.comContainer id :85766Topic id :281487User logout.Done
The following is an example for unsubscribing from an existing container subscription:
Example 13-2 Unsubscribing to an Existing Subscription
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.SubscriptionServiceSoapBindingStub;import oracle.discussions.ws.SubscriptionServiceServiceLocator;import oracle.discussions.ws.SubscriptionService; /* * Tests the Oracle Discussions Web Services functionality. * Invokes various web services methods, to retrieve the results and * check if the results are fine. */ 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 SubscriptionServiceServiceLocator sssl = new SubscriptionServiceServiceLocator(); //Get a handle to the actual web service. SubscriptionService ss = sssl.getSubscriptionService(); //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. ((SubscriptionServiceSoapBindingStub)ss).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)ss)._setProperty(HTTPConstants.HEADER_ COOKIE,cookie); //Invoke the actual web services call. Subscription sub = new Subscription(); //The ID needs to be changed accordingly sub.setContainerId(85764); sub.setType(0); //The e-mail address needs to be changed accordingly sub.setEmailAddress("td_superuser@stacx01.us.oracle.com"); sub.setTopicId(0); ss.unsubscribe(sub); //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 unsubscribe()
method removes the user subscription on the subscription element represented by the ID fields in the subscription bean. If the topic ID is 0, and if container ID represents a valid container, then the subscription represents a container subscription, and is unsubscribed. On the other hand, if both topic and container IDs are greater than 0, and if the IDs represent a valid topic, then the topic subscription is removed. The e-mail address of the subscription should correspond to the subscriber.
The sample output for Example 13-2 is as follows:
Cookie : JSESSIONID=8c57046a22b86759fc2215c0485fa5a1a7d6f381d9dcSubscription successfully removedUser logout.Done
The following is an example unsubscribing from a topic subscription:
Example 13-3 Unsubscribing from a Topic Subscription
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.SubscriptionServiceSoapBindingStub;import oracle.discussions.ws.SubscriptionServiceServiceLocator;import oracle.discussions.ws.SubscriptionService; /* * Tests the Oracle Discussions Web Services functionality. * Invokes various web services methods, to retrieve the results and * check if the results are fine. */ 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 SubscriptionServiceServiceLocator sssl = new SubscriptionServiceServiceLocator(); //Get a handle to the actual web service. SubscriptionService ss = sssl.getSubscriptionService(); //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. ((SubscriptionServiceSoapBindingStub)ss).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)ss)._setProperty(HTTPConstants.HEADER_ COOKIE,cookie); //Invoke the actual web services call. Subscription sub = new Subscription(); //The ID needs to be changed accordingly sub.setContainerId(85764); sub.setType(0); //The e-mail address needs to be changed accordingly sub.setEmailAddress("td_superuser@stacx01.us.oracle.com"); //The ID needs to be changed accordingly sub.setTopicId(281784); ss.unsubscribe(sub); //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 sample output for Example 13-3 is as follows:
Cookie : JSESSIONID=8c57046a22b89bdff0080cd141e8940be470e31c2c8bSubscription successfully removedUser logout.Done