Here is a code snippet that shows how to subscribe to a user state using Sun Diameter Sh API . The Notifications from the Home subscriber server(HSS) can be received by a Message Driver Bean(MDB). The code snippet of the MDB is also shown below.


try {
InitialContext context = new InitialContext();
UserProfileServer hss = (UserProfileServer) context.lookup("openims");
UserProfileConnection upc = hss.createConnection();
SubscribeKey subScribeKey = new SubscribeKey();
subScribeKey.addDataReference(DataReference.IMS_US ER_STATE);
subScribeKey.addServiceIndicator("default_sp");
subScribeKey.setExpiryTime("5000");
UserIdentity uID = new UserIdentity("sip:bob-AT-open-ims-DOT-test", UserIdentityType.PUBLIC_USER_ID);
subScribeKey.setUserIdentity(uID);
subScribeKey.validate();
UserProfileSubscriptionResponse response = upc.subscribe(subScribeKey, false);
ProfileData data = response.getProfileData();
} catch (ConnectException ex) {
Logger.getLogger(NotificationServlet.class.getName ()).log(Level.SEVERE, null, ex);
} catch (KeyValidationException ex) {
Logger.getLogger(NotificationServlet.class.getName ()).log(Level.SEVERE, null, ex);
} catch (NamingException ex) {
Logger.getLogger(NotificationServlet.class.getName ()).log(Level.SEVERE, null, ex);
}



@MessageDriven(mappedName = "SubscriptionNotifier",messageListenerInterface = com.sun.diameter.application.sh.api.UserProfileMes sageListener.class,
activationConfig = {
@ActivationConfigProperty(propertyName = "DestinationType", propertyValue = "com.sun.diameter.application.sh.api.UserProfileMes sageListener"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue = "SubscribeNotifierBean"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "SubscribeNotifierBean")
})
public class SubscribeNotifierBean implements UserProfileMessageListener {
public SubscribeNotifierBean() {
}
public void doPNR(UserProfileNotificationRequest upnr) {
try {
InitialContext context = new InitialContext();
// one can use the the realm name obtained from the UserProfileNotificationRequest to map to appropriate
//resource.
UserProfileServer hss = (UserProfileServer) context.lookup("openims");
hss.createConnection().sendPushNotificationRespons e(upnr, 2001, false);
} catch (ConnectException ex) {
Logger.getLogger(SubscribeNotifierBean.class.getNa me()).log(Level.SEVERE, null, ex);
} catch (NamingException ex) {
Logger.getLogger(SubscribeNotifierBean.class.getNa me()).log(Level.SEVERE, null, ex);
}
}


The below Admin console snaps of Sailfin 2.0 show Home Subscriber server (pone) configured with Connector Pool(openims_pool) and Connector resource (openims)




Here are simple steps :
1.Using Sailfin 2.0 Admin console(Sailfin 2.0 also supports cli commands)
a)Create a Diameter application
b)Create a Diameter Peer ---- Diameter Peer screen also allows you to configure connector pool and resource.
2.Write a SIP Servlet with code snippet shown above
3.Write a MDB as shown above
4.Deploy the sar and jar and you should be done.




More...