| Oracle® Workspaces Web Services Application Developer's Guide 10g Release 1 (10.1.2.2) Part Number B28207-01 |
|
|
View PDF |
The Announcements service allows users to create, update, retrieve, and delete announcements. An announcement is a message posted by a member of a workspace that all members of that workspace may see on the workspace home page.
The following sample creates an announcement that will expire seven days from the current date:
Example 11-1 AnnouncementsServiceSample.java
package oracle.sample.workspaces.ws;
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import oracle.workspaces.ws.AnnouncementsService;
import oracle.workspaces.ws.AnnouncementsServiceServiceLocator;
import oracle.workspaces.ws.AnnouncementsServiceSoapBindingStub;
import oracle.workspaces.ws.AuthenticationService;
import oracle.workspaces.ws.HomeService;
import oracle.workspaces.ws.beans.AnnouncementDefinition;
import oracle.workspaces.ws.beans.AnnouncementItem;
import oracle.workspaces.ws.beans.WorkspaceItem;
import oracle.workspaces.ws.exceptions.CwWSException;
import org.apache.axis.transport.http.HTTPConstants;
public class AnnouncementsServiceSample
{
public static AnnouncementsService configureAnnouncementsService(
String szAuthCookie) throws ServiceException
{
AnnouncementsServiceServiceLocator assl =
new AnnouncementsServiceServiceLocator();
AnnouncementsService aService = assl.getAnnouncementsService();
((AnnouncementsServiceSoapBindingStub)aService).
setMaintainSession(true);
((javax.xml.rpc.Stub)aService).
_setProperty(HTTPConstants.HEADER_COOKIE,szAuthCookie);
return aService;
}
public static AnnouncementItem createAnnouncement(
AnnouncementsService szAnnouncementsService,
String szWorkspaceID,
String szTitle,
String szBody) throws RemoteException, CwWSException
{
Calendar expirationTime = Calendar.getInstance();
expirationTime.set(Calendar.SECOND, 0);
expirationTime.add(Calendar.DAY_OF_YEAR, 7);
AnnouncementDefinition annDefn1 = new AnnouncementDefinition();
annDefn1.setTitle(szTitle);
annDefn1.setBody(szBody);
annDefn1.setExpirationTime(expirationTime);
annDefn1.setPlainText(true);
return szAnnouncementsService.createAnnouncement(
szWorkspaceID,
annDefn1);
}
public static void main(String[] args)
{
try {
// Get authentication cookie
AuthenticationService myAuthenticationService =
AuthenticationSample.configureAuthenticationService(
"rg4",
"welcome1");
String authCookie = AuthenticationSample.getAuthenticationCookie
(myAuthenticationService);
System.out.println("Retrieved authentication cookie : " + authCookie);
// Retrieve AnnouncementsService and set authentication cookie
AnnouncementsService myAnnouncementsService =
AnnouncementsServiceSample.
configureAnnouncementsService(authCookie);
// Retrieve HomeService and set authentication cookie
HomeService myHomeService =
HomeServiceSample.configureHomeService(authCookie);
// Create new workspace (or retrieve it if it already exists)
WorkspaceItem myWorkspace =
HomeServiceSample.createOrRetrieveWorkspace(
myHomeService,
"NewWorkspace",
"My New Workspace",
"Description of My New Workspace",
"WRITER",
"ENABLED");
System.out.println("Retrieved or created workspace");
// Create an announcement that will expire seven
// days from the current date
AnnouncementsServiceSample.createAnnouncement(
myAnnouncementsService,
myWorkspace.getWorkspaceUid(),
"My announcement title",
"My announcement body");
System.out.println("Created announcement");
myAuthenticationService.logout();
} catch (CwWSException cwwse)
{
System.out.println("CwWSException caught: " + cwwse.getMessage());
} catch (Exception e)
{
System.out.println("Exception caught: " + e.toString());
}
}
}