use of com.iplanet.services.comm.server.SendNotificationException 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.server.SendNotificationException 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());
}
}
}
use of com.iplanet.services.comm.server.SendNotificationException in project OpenAM by OpenRock.
the class DirectoryManagerImpl method processEntryChanged.
// Implementation to process entry changed events
protected static void processEntryChanged(String method, String name, int type, Set attrNames) {
debug.message("DirectoryManagerImpl.processEntryChaged method " + "processing");
initializeCacheSize();
// Construct the XML document for the event change
StringBuilder sb = new StringBuilder(100);
sb.append("<EventNotification><AttributeValuePair>").append("<Attribute name=\"method\" /><Value>").append(method).append("</Value></AttributeValuePair>").append("<AttributeValuePair><Attribute name=\"entityName\" />").append("<Value>").append(name).append("</Value></AttributeValuePair>");
if (method.equalsIgnoreCase("objectChanged") || method.equalsIgnoreCase("objectsChanged")) {
sb.append("<AttributeValuePair><Attribute name=\"eventType\" />").append("<Value>").append(type).append("</Value></AttributeValuePair>");
if (method.equalsIgnoreCase("objectsChanged")) {
sb.append("<AttributeValuePair><Attribute ").append("name=\"attrNames\"/>");
for (Iterator items = attrNames.iterator(); items.hasNext(); ) {
String attr = (String) items.next();
sb.append("<Value>").append(attr).append("</Value>");
}
sb.append("</AttributeValuePair>");
}
}
sb.append("</EventNotification>");
if (cacheSize > 0) {
Set<String> modDNs = getCachedValues(cache);
// Add to cache
modDNs.add(sb.toString());
if (debug.messageEnabled()) {
debug.message("DirectoryManagerImpl::processing entry change: " + sb.toString());
}
}
if (debug.messageEnabled()) {
debug.message("DirectoryManagerImpl = notificationURLS" + notificationURLs.values());
}
// If notification URLs are present, send notifications
NotificationSet ns = null;
synchronized (notificationURLs) {
for (Map.Entry<String, URL> entry : notificationURLs.entrySet()) {
String id = entry.getKey();
URL url = entry.getValue();
// Construct NotificationSet
if (ns == null) {
Notification notification = new Notification(sb.toString());
ns = new NotificationSet(com.iplanet.am.sdk.remote.RemoteServicesImpl.SDK_SERVICE);
ns.addNotification(notification);
}
try {
PLLServer.send(url, ns);
if (debug.messageEnabled()) {
debug.message("DirectorManagerImpl:sentNotification " + "URL: " + url + " Data: " + ns);
}
} catch (SendNotificationException ne) {
if (debug.warningEnabled()) {
debug.warning("DirectoryManagerImpl: 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.server.SendNotificationException in project OpenAM by OpenRock.
the class IdRepoJAXRPCObjectImpl method processEntryChanged_idrepo.
// Implementation to process entry changed events
protected static void processEntryChanged_idrepo(String method, String name, int type, Set attrNames) {
if (idRepoDebug.messageEnabled()) {
idRepoDebug.message("IdRepoJAXRPCObjectImpl.processEntryChaged " + "method processing method: " + method + " name: " + name + " type: " + type + " attrName: " + attrNames);
}
initializeCacheSize();
// Return if cache size is 0 or there are no remote clients
if (cacheSize == 0 && idRepoNotificationURLs.isEmpty()) {
if (idRepoDebug.messageEnabled()) {
idRepoDebug.message("IdRepoJAXRPCObjectImpl." + "processEntryChaged No registered notification URLs: " + idRepoNotificationURLs + " and cache size is: " + cacheSize);
}
return;
}
// Construct the XML document for the event change
StringBuilder sb = new StringBuilder(100);
sb.append("<EventNotification><AttributeValuePair>").append("<Attribute name=\"method\" /><Value>").append(method).append("</Value></AttributeValuePair>").append("<AttributeValuePair><Attribute name=\"entityName\" />").append("<Value>").append(XMLUtils.escapeSpecialCharacters(name)).append("</Value></AttributeValuePair>");
if (method.equalsIgnoreCase("objectChanged") || method.equalsIgnoreCase("objectsChanged")) {
sb.append("<AttributeValuePair><Attribute name=\"eventType\" />").append("<Value>").append(type).append("</Value></AttributeValuePair>");
if (method.equalsIgnoreCase("objectsChanged")) {
sb.append("<AttributeValuePair><Attribute ").append("name=\"attrNames\"/>");
for (Iterator items = attrNames.iterator(); items.hasNext(); ) {
String attr = (String) items.next();
sb.append("<Value>").append(attr).append("</Value>");
}
sb.append("</AttributeValuePair>");
}
}
sb.append("</EventNotification>");
// Update cache for polling by remote clients
if (cacheSize > 0) {
Set<String> modDNs = getCachedValues(idrepoCache);
// Add to cache
modDNs.add(sb.toString());
if (idRepoDebug.messageEnabled()) {
idRepoDebug.message("IdRepoJAXRPCObjectImpl.processing " + "entry change:" + sb.toString());
}
}
// If notification URLs are present, send notifications
if (idRepoDebug.messageEnabled()) {
idRepoDebug.message("IdRepoJAXRPCObjectImpl.processEntryChaged =" + " notificationURLS " + idRepoNotificationURLs.values());
}
NotificationSet ns = null;
synchronized (idRepoNotificationURLs) {
for (Map.Entry<String, URL> entry : idRepoNotificationURLs.entrySet()) {
String id = entry.getKey();
URL url = entry.getValue();
// Construct NotificationSet
if (ns == null) {
Notification notification = new Notification(sb.toString());
ns = new NotificationSet(IDREPO_SERVICE);
ns.addNotification(notification);
}
try {
PLLServer.send(url, ns);
if (idRepoDebug.messageEnabled()) {
idRepoDebug.message("IdRepoJAXRPCObjectImpl:" + "sentNotification URL: " + url + " Data: " + ns);
}
} catch (SendNotificationException ne) {
if (idRepoDebug.warningEnabled()) {
idRepoDebug.warning("IdRepoJAXRPCObjectImpl: failed " + "sending notification to: " + url + "\nRemoving " + "URL from notification list.", ne);
}
// Remove the URL from Notification List
idRepoNotificationURLs.remove(id);
}
}
}
}
use of com.iplanet.services.comm.server.SendNotificationException 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);
}
}
}
}
Aggregations