88 IBM WebSphere Everyplace Access V5, Volume IV: Advanced Topics
4. In a command line window, execute the instruction all on one line as shown in
Figure 3-2:
Figure 3-2 Running the content source program
3.3.3 Developing a content adapter application
This sample content adapter is deployed as a WebSphere Application Server
J2EE client application. To develop this content adapter:
1. Create an Application Client Project
a. Open the IBM WebSphere Studio Site Developer and select File
New
Project.
b. Select J2EE from the left panel and Application Client Project from the
right panel. Click Next.
c. Select Create J2EE 1.3 Application Client project. Click Next.
d. Enter a project name. In this example, it is MonitoringContentAdapter.
Select a EAR project. In this example, it is MonitoringContentAdapterEAR.
Click Next and click Finish.
2. Include in the Java classpath the Intelligent Notification Service JAR files
ins.jar and insSmClient.jar that are located in the directory ins_home\lib,
where ins_home is in the installation directory
C:\Program Files\WebSphere\INS.
a. Right click Project Name
Properties Java Build Path
Libraries.
b. Click Add External JARs... and browse the JAR files.
c. Click OK.
Note: The MonitoringContentFeed program requires the sample content
adapter application that is running to work appropriately. Refer to 3.3.4,
“Deploying a content adapter” on page 94 for instructions how to deploy a
content adapter application.
Chapter 3. Subscription-based notifications 89
3. Create a new package. In this example, the package is
com.ibm.pvc.ins.sm.apps.
4. Create into the new package a new Java file. In this example, the name of
this file is MonitoringContentAdapter.java.
5. Import the required packages as shown in Example 3-6.
Example 3-6 Required packages for MonitoringContentAdapter class
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PropertyResourceBundle;
import java.net.Socket;
import com.ibm.pvc.ins.sm.client.ConfigurationException;
import com.ibm.pvc.ins.sm.client.IQueueException;
import com.ibm.pvc.ins.sm.client.SmClientFactory;
import com.ibm.pvc.ins.sm.server.SubscriptionService;
import com.ibm.pvc.we.ins.context.util.SocketListener;
6. Create a new class that extends the SocketListener class. The
SocketListener class listens for an incoming connection request through
sockets. Declare auxiliary variables for the properties file (the fully qualified
class name) and the Subscription Manager client instance as shown in
Example 3-7.
Example 3-7 Auxiliary variables for MonitoringContentAdapter class
public class MonitoringContentAdapter extends SocketListener
{
private final static String propertiesFile = "MonitoringContentAdapter";
private SubscriptionService smClient;
7. Define the constructor method for this class, call the parent constructor to
listen for incoming connection on the specified port, and create a Subscription
Manager client remote instance (which is necessary to publish the content
source into the Subscription Manager).
The method createRemoteSmClient belongs to SmClientFactory class and
allows you to create a remote Subscription Manager client. If a parameter is
not specified, this method uses the default context provider URL
corbaloc:iiop:localhost:2809.
The context provider URL is specified in the XML file insBaseConfig.xml
located in ins_home\config\xml, where ins_home is the Intelligent Notification
90 IBM WebSphere Everyplace Access V5, Volume IV: Advanced Topics
Services home installation directory (for example C:\Program
Files\WebSphere\INS).
Example 3-8 Extension of MonitoringContentAdapter constructor
public MonitoringContentAdapter(int port, int threads) throws IOException,
IQueueException, ConfigurationException
{
super(port, threads);
smClient = SmClientFactory.createRemoteSmClient();
System.out.println("Connected to SM");
}
8. Define the SocketListener abstract method named processSocket. This
method processes input data that it receives by a socket connection.
The following is an explanation of how this method works:
a. The processSocket method receives as a parameter a socket object and
obtains its input stream. Auxiliary variables are declared to obtain
information of this input stream. In this example, it gets the server status
information.
Example 3-9 processSocket method implementation
public void processSocket(Socket socket)
{
try {
BufferedReader in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String sServerStatus = "ServerStatus: ";
String sServerStatusValue = "";
String st = "";
b. Review the entire input stream in search of the server status value.
Example 3-10 processSocket method implementation
do {
st = in.readLine();
if (st != null) {
if (st.startsWith(sServerStatus)) {
sServerStatusValue =
st.substring(sServerStatus.length()).trim();
System.out.println("Server Status = " + sServerStatusValue);
}
}
} while (st != null);

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.