68 IBM WebSphere Everyplace Access V5, Volume IV: Advanced Topics
}
public void setFlag(boolean flag){
this.flag = flag;
}
public String getFormText() {
return this.formText;
}
public String getFormSubject() {
return this.formSubject;
}
public String getFormTo() {
return this.formTo;
}
public String getFormToUID() {
return this.formToUID;
}
public String getFormFromUID() {
return this.formFromUID;
}
public String getFormPriority() {
return this.formPriority;
}
public boolean getFlag() {
return this.flag;
}
c. Define a method that sets up message information and delivery
preferences, and send this message to the Notification Manager. In the
example, this method is named getResults.
d. Declare some auxiliary variables for the message ID, WebSphere
Everyplace Access server name and the associated communication port
(Example 2-5 on page 69). The last two variables are used to build the
provider URL that is required for the communication between the portlet
and the Notification Manager component in the WebSphere Everyplace
Access server.
The context provider URL is specified in the XML file insBaseConfig.xml
that is located in ins_home\config\xml, where ins_home is the Intelligent
Notification Services home installation directory (for example, C:\Program
Files\WebSphere\INS).
Chapter 2. Simple notifications 69
Example 2-5 getResults method and auxiliary variables
public String getResults() {
String msgID = null;
int ipriority =0;
String hostName = "wea5d.itso.ral.ibm.com";
String port = "9814";
String providerUrl = "corbaloc:iiop:" + hostName + ":" + port;
e. Create a remote Notification Manager client instance, as shown in
Example 2-6.
Example 2-6 Notification Manager client instance
NotificationService nmClient = null;
try {
Hashtable env = new Hashtable();
env.put (Context.PROVIDER_URL, providerUrl);
nmClient = NmClientFactory.createRemoteNmClient(env);
f. Create a Notification object and set up the message information and
delivery preferences, as shown in Example 2-7.
Example 2-7 Notification object
Notification notf = new Notification();
notf.addDeliveryChannel (new MessageCenterDeliveryChannel() );
notf.addDeliveryChannel (new SametimeDeliveryChannel() );
notf.addDeliveryChannel (new EmailDeliveryChannel() );
if (formPriority.equals("MSG_PRIORITY_DEFAULT"))
ipriority = Request.MSG_PRIORITY_DEFAULT;
if (formPriority.equals("MSG_PRIORITY_FYI"))
ipriority = Request.MSG_PRIORITY_FYI;
if (formPriority.equals("MSG_PRIORITY_NORMAL"))
ipriority = Request.MSG_PRIORITY_NORMAL;
if (formPriority.equals("MSG_PRIORITY_URGENT"))
ipriority = Request.MSG_PRIORITY_URGENT;
notf.setMsgPriority(ipriority);
notf.setMultiDevices(true);
notf.setTextMsgType();
if (formTo.equals("UserID"))
notf.setToUserID(formToUID);
if (formTo.equals("UserGroup"))
notf.setToGroupID(formToUID);
notf.setFromUserID(formFromUID);
notf.setSubjectText(formSubject);
notf.setMsgText(formText);
70 IBM WebSphere Everyplace Access V5, Volume IV: Advanced Topics
g. Send the message to Notification Manager, as shown in Example 2-8.
Example 2-8 Send message to Notification Manager
msgID = nmClient.sendMessage(notf);
return "The message has been sent";
h. Finally, catch the exceptions, as shown in Example 2-9.
Example 2-9 Exceptions
catch (NmClientFactoryException cfe)
{
return "NmClientFactoryException encountered" + " " +
cfe.getMessage();
}
catch (Exception e) {
return "Exception ocurred" + " " + e.getMessage();
}
5. Open and modify the JSP file that is located in the html subfolder (Figure 2-3
on page 71). In this example, it is the SimpleNotificationPortletView.jsp file. In
that file:
a. Define a form and include the required fields to obtain information about
the message and delivery preferences.
b. Invoke the method that you created earlier to send the message to the
Notification Manager.
Optionally, you can create a JSP file to use with Pocket PC. The JSP file for
Pocket PC is located in the pda subdirectory, as shown in Figure 2-3 on
page 71.
6. Save the project.

Get IBM WebSphere Everyplace Access V5 Handbook for Developers and Administrators Volume IV: Advanced Topics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.