use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class GetCallerList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
boolean isCompression = false;
try {
manager = req.getParameter(GetCallerList.PARAMETER_CALLERMANAGER);
isCompression = (req.getParameter(GetCallList.PARAMETER_COMPRESSION) != null ? req.getParameter(GetCallList.PARAMETER_COMPRESSION).equalsIgnoreCase("true") : false);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallerList l = this.getRuntime().getCallerFactory().createCallerList();
String filter = null;
try {
filter = req.getParameter(GetCallerList.PARAMETER_FILTER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
String s = null;
ISearchTerm[] searchterms = null;
try {
s = req.getParameter(GetCallList.PARAMETER_SEARCHTERMS);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (s != null && s.length() > 0) {
searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
}
if (filter == null || filter.length() == 0) {
if (mgr.isSupported(ISearchableCallerRepository.class)) {
l = ((ISearchableCallerRepository) mgr).getCallers(new IFilter[] {}, searchterms);
} else
l = ((IReadCallerRepository) mgr).getCallers((IFilter) null);
this.m_logger.info("Filter parameter &filter= was not set.");
} else {
IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
if (mgr.isSupported(ISearchableCallerRepository.class)) {
l = ((ISearchableCallerRepository) mgr).getCallers(f, searchterms);
} else
l = ((IReadCallerRepository) mgr).getCallers(f);
}
try {
String xml = XMLSerializer.toXML(l, false);
if (isCompression && xml.length() > 1024) {
this.m_logger.info("Compressing requested data.");
this.m_logger.info("Uncompressed data size [bytes] : " + xml.length());
xml = CompressBase64.compressBase64Encode(xml);
this.m_logger.info("Compressed data size [bytes] : " + xml.length());
resp.setParameter("Content-Type", "application/janrufmonitor-compressed");
resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "true");
} else {
resp.setParameter("Content-Type", "text/xml");
resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "false");
}
resp.setParameter("Content-Length", Long.toString(xml.length()));
OutputStream ps = resp.getContentStreamForWrite();
ps.write(xml.getBytes());
ps.flush();
ps.close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class RemoveCallerList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(RemoveCallerList.PARAMETER_CALLERMANAGER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallerList l;
try {
l = XMLSerializer.toCallerList(this.getPostData(req));
if (l != null) {
this.m_logger.info("Removing caller list with " + l.size() + " entries.");
((IWriteCallerRepository) mgr).removeCaller(l);
resp.getContentStreamForWrite().close();
} else {
this.m_logger.severe("Invalid caller list transfered from client.");
throw new HandlerException("Invalid caller list transfered from client.", 500);
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class SetCallerList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(SetCallerList.PARAMETER_CALLERMANAGER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallerList l;
try {
l = XMLSerializer.toCallerList(this.getPostData(req));
if (l != null) {
this.m_logger.info("Setting caller list with " + l.size() + " entries.");
((IWriteCallerRepository) mgr).setCaller(l);
resp.getContentStreamForWrite().close();
} else {
this.m_logger.severe("Invalid caller list transfered from client.");
throw new HandlerException("Invalid caller list transfered from client.", 500);
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class LdapRepository method startup.
public void startup() {
super.startup();
if (this.isActive()) {
Thread t = new Thread() {
public void run() {
try {
ICallerList c = getProxy().getContacts(null);
if (m_logger.isLoggable(Level.INFO) && c.size() > 0)
m_logger.info("Found " + c.size() + " LDAP contacts to be synced.");
} catch (LdapContactsException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
};
t.setName("JAM-LdapUUIDCheck-Thread-(deamon)");
t.setDaemon(true);
t.start();
}
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class LdapRepository method getCallers.
public ICallerList getCallers(IFilter filter) {
try {
if (filter != null && filter.getType().equals(FilterType.ATTRIBUTE)) {
IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
IAttribute a = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
return getProxy().getContacts(a.getValue());
}
}
if (filter != null && filter.getType().equals(FilterType.PHONENUMBER)) {
ICallerList cl = getProxy().getContacts(null);
this.applyFilters(cl, new IFilter[] { filter });
return cl;
}
if (filter != null && filter.getType().equals(FilterType.CHARACTER)) {
ICallerList cl = getProxy().getContacts(null);
this.applyFilters(cl, new IFilter[] { filter });
return cl;
}
return getProxy().getContacts(null);
} catch (LdapContactsException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "loginerror", e));
}
return getRuntime().getCallerFactory().createCallerList();
}
Aggregations