use of com.iplanet.services.comm.share.Notification in project OpenAM by OpenRock.
the class PolicyListenerRequest method policyChanged.
/**
* Handles policy change event.
*
* @param evt the policy event regarding the policy change.
*/
public void policyChanged(PolicyEvent evt) {
debug.message("PolicyListenerRequest.policyChanged()");
if (evt == null) {
debug.error("PolicyListenerRequest.policyChanged(PolicyEvent): " + "invalid policy event");
return;
}
// get the policy change type from the event
String changeType = null;
int type = evt.getChangeType();
if (type == PolicyEvent.POLICY_ADDED) {
changeType = PolicyChangeNotification.ADDED;
} else if (type == PolicyEvent.POLICY_REMOVED) {
changeType = PolicyChangeNotification.DELETED;
} else {
changeType = PolicyChangeNotification.MODIFIED;
}
// get the resource names from the event
Set resourceNames = evt.getResourceNames();
if (debug.messageEnabled()) {
debug.message("PolicyListenerRequest.policyChanged(PolicyEvent): " + "resource names from the policy event : " + resourceNames.toString());
}
PolicyService ps = new PolicyService();
PolicyNotification pn = new PolicyNotification();
PolicyChangeNotification pcn = new PolicyChangeNotification();
/*
* sets the service name and resource names which are affected
* by this policy change notification.
*/
pcn.setResourceNames(resourceNames);
pcn.setPolicyChangeType(changeType);
pcn.setServiceName(serviceName);
pn.setNotificationType(PolicyNotification.POLICY_CHANGE_TYPE);
pn.setPolicyChangeNotification(pcn);
ps.setMethodID(PolicyService.POLICY_NOTIFICATION_ID);
ps.setPolicyNotification(pn);
/*
* create a Notification object based on the policy change
* notification.
*/
Notification notification = new Notification(ps.toXMLString());
NotificationSet set = new NotificationSet(PolicyService.POLICY_SERVICE);
// add the notification to the notification set to be sent to the client
set.addNotification(notification);
if (debug.messageEnabled()) {
debug.message("PolicyListenerRequest.policyChanged(PolicyEvent): " + "the notification set sent is : " + set.toXMLString());
}
try {
// sends the notification to the client
PLLServer.send(new URL(notificationURL), set);
if (debug.messageEnabled()) {
debug.message("PolicyListenerRequest.policyChanged(PolicyEvent): " + "the policy change notification has been sent to " + notificationURL);
}
} catch (SendNotificationException e) {
debug.error("PolicyListenerRequest.policyChanged(): " + "PLLServer.send() failed", e);
} catch (MalformedURLException e) {
debug.error("PolicyListenerRequest.policyChanged(): " + "PLLServer.send() failed", e);
}
}
use of com.iplanet.services.comm.share.Notification in project OpenAM by OpenRock.
the class PLLNotificationServlet method handleNotification.
/*
* This method is used by doPost method. It gets the corresponding notification handler and passes the Notification
* objects to it for processing.
*
* @param notificationXML The XML String for the NotificationSet object.
*/
private void handleNotification(String notificationXML) throws ServletException {
NotificationSet notificationSet = NotificationSet.parseXML(notificationXML);
Vector<Notification> notifications = notificationSet.getNotifications();
if (!notifications.isEmpty()) {
// Each notification in this set shall have the same service id
String serviceID = notificationSet.getServiceID();
NotificationHandler notificationHandler = PLLClient.getNotificationHandler(serviceID);
if (notificationHandler == null) {
throw new ServletException(PLLBundle.getString("noNotificationHandler") + serviceID);
}
notificationHandler.process(notifications);
}
}
use of com.iplanet.services.comm.share.Notification in project OpenAM by OpenRock.
the class PolicyNotificationHandler method processPLLNotifications.
/**
* Processes PLL notifications
* @param notifications PLL notification to be processed
*/
void processPLLNotifications(Vector notifications) {
for (int i = 0; i < notifications.size(); i++) {
Notification notification = (Notification) notifications.elementAt(i);
if (debug.messageEnabled()) {
debug.message("PolicyNotificationHandler." + "processPLLNotifications():" + "got notification: " + notification.getContent());
}
try {
PolicyService ps = PolicyService.parseXML(notification.getContent());
PolicyNotification pn = ps.getPolicyNotification();
if (pn != null) {
processPolicyNotification(pn);
}
} catch (PolicyException pe) {
debug.error("PolicyNotificationHandler." + "processPLLNotifications():" + "invalid notifcation format", pe);
}
}
}
use of com.iplanet.services.comm.share.Notification in project OpenAM by OpenRock.
the class SMSJAXRPCObjectImpl method objectChanged.
// Implementation for SMSObjectListener
public synchronized void objectChanged(String name, int type) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
String cacheIndex = calendarToString(calendar);
Set modDNs = (Set) cache.get(cacheIndex);
if (modDNs == null) {
modDNs = new HashSet();
cache.put(cacheIndex, modDNs);
// Maintain cacheIndex
cacheIndices.addFirst(cacheIndex);
if (cacheIndices.size() > cacheSize) {
String index = (String) cacheIndices.removeLast();
cache.remove(index);
}
}
String modItem = null;
switch(type) {
case ADD:
modItem = "ADD:" + name;
break;
case DELETE:
modItem = "DEL:" + name;
break;
default:
modItem = "MOD:" + name;
}
modDNs.add(modItem);
// If notification URLs are present, send notifications
synchronized (notificationURLs) {
for (Map.Entry<String, URL> entry : notificationURLs.entrySet()) {
String id = entry.getKey();
URL url = entry.getValue();
// Construct NotificationSet
Notification notification = new Notification(modItem);
NotificationSet ns = new NotificationSet(JAXRPCUtil.SMS_SERVICE);
ns.addNotification(notification);
try {
PLLServer.send(url, ns);
if (debug.messageEnabled()) {
debug.message("SMSJAXRPCObjectImpl:objectChanged sent notification to " + "URL: " + url + " Data: " + ns);
}
} catch (SendNotificationException ne) {
if (debug.warningEnabled()) {
debug.warning("SMSJAXRPCObjectImpl:objectChanged failed sending " + "notification to: " + url + "\nRemoving " + "URL from notification list.", ne);
}
// Remove the URL from Notification List
notificationURLs.remove(id);
}
}
}
}
use of com.iplanet.services.comm.share.Notification in project OpenAM by OpenRock.
the class AgentsRepo method sendNotificationSet.
// If notification URLs are present, send notifications to clients/agents.
private void sendNotificationSet(int type, IdType agentIdTypeforNotificationSet, String agentNameforNotificationSet) {
try {
// If notification enabled is set to true ,send notifications.
Set<String> nSet = new HashSet<String>(2);
nSet.add(notificationURLenabled);
SSOToken adminToken = AccessController.doPrivileged(AdminTokenAction.getInstance());
Map<String, Set<String>> ansMap = getAttributes(adminToken, agentIdTypeforNotificationSet, agentNameforNotificationSet, nSet);
Set<String> neSet = ansMap.get(notificationURLenabled);
if (neSet != null && !neSet.isEmpty() && neSet.iterator().next().equalsIgnoreCase("true")) {
switch(type) {
case MODIFIED:
if (agentIdTypeforNotificationSet == null) {
break;
}
String modItem;
Set<String> aNameSet = new HashSet<String>(2);
if (debug.messageEnabled()) {
debug.message("AgentsRepo.sendNotificationSet(): agentIdTypeforNotificationSet " + agentIdTypeforNotificationSet);
debug.message("AgentsRepo.sendNotificationSet(): agentNameforNotificationSet " + agentNameforNotificationSet);
}
// notifications to all its members.
if (agentIdTypeforNotificationSet.equals(IdType.AGENTGROUP)) {
Set<String> members = getMembers(adminToken, agentIdTypeforNotificationSet, agentNameforNotificationSet, IdType.AGENTONLY);
for (String agent : members) {
aNameSet.add(agent);
//An agent group has been updated, so now we need to notify the internal cache for the
//group members so they return the changed inherited values as well.
repoListener.objectChanged(agent, IdType.AGENT, type, repoListener.getConfigMap());
repoListener.objectChanged(agent, IdType.AGENTONLY, type, repoListener.getConfigMap());
}
} else {
aNameSet.add(agentNameforNotificationSet);
}
if (debug.messageEnabled()) {
debug.message("AgentsRepo.sendNotificationSet(): aNameSet " + aNameSet);
}
if (!aNameSet.isEmpty()) {
for (String agentName : aNameSet) {
agentIdTypeforNotificationSet = IdType.AGENTONLY;
// To be consistent and for easy web agent
// parsing,the notification set should start with
// "AgentConfigChangeNotification"
StringBuilder xmlsb = new StringBuilder(1000);
xmlsb.append("<").append(AGENT_NOTIFICATION).append(" ").append(AGENT_ID).append("=\"").append(agentName).append("\"").append(" ").append(AGENT_IDTYPE).append("=\"").append(agentIdTypeforNotificationSet.getName()).append("\"/>");
modItem = xmlsb.toString();
if (debug.messageEnabled()) {
debug.message("AgentsRepo.sendNotificationSet(): modItem " + modItem);
}
// If notification URLs are present,send
// notifications
nSet = new HashSet<String>(2);
nSet.add(notificationURLname);
String nval;
ansMap = getAttributes(adminToken, agentIdTypeforNotificationSet, agentName, nSet);
Set<String> nvalSet = ansMap.get(notificationURLname);
if (nvalSet != null && !nvalSet.isEmpty()) {
nval = nvalSet.iterator().next();
try {
URL url = new URL(nval);
// Construct NotificationSet to be sent to
// Agents.
Notification notification = new Notification(modItem);
NotificationSet ns = new NotificationSet(AGENT_CONFIG_SERVICE);
ns.addNotification(notification);
try {
PLLServer.send(url, ns);
if (debug.messageEnabled()) {
debug.message("AgentsRepo:sendNotificationSet Sent Notification to URL: " + url + " Data: " + ns);
}
} catch (SendNotificationException ne) {
if (debug.warningEnabled()) {
debug.warning("AgentsRepo.sendNotificationSet: failed sending notification" + " to: " + url + " " + ne.getMessage());
}
}
} catch (MalformedURLException e) {
if (debug.warningEnabled()) {
debug.warning("AgentsRepo.sendNotificationSet:(): invalid URL: " + e.getMessage());
}
}
}
}
}
}
}
} catch (IdRepoException idpe) {
debug.error("AgentsRepo.sendNotificationSet(): Unable to send notification due to " + idpe);
} catch (SSOException ssoe) {
if (debug.warningEnabled()) {
debug.warning("AgentsRepo.sendNotificationSet(): Unable to send notification due to " + ssoe.getMessage());
}
}
}
Aggregations