use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.
the class Shutdown method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ClientStateManager.getInstance().fireState(IClientStateMonitor.SERVER_SHUTDOWN, "");
Thread t = new Thread(new DisconnectThread());
t.start();
try {
resp.getContentStreamForWrite().close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.
the class Configuration method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
try {
String uri_path = req.getURI().getPath().substring(1);
if (uri_path.indexOf("/") > 0) {
uri_path = uri_path.substring(uri_path.indexOf("/"));
this.handleFile(uri_path, resp);
return;
}
long start = System.currentTimeMillis();
StringBuffer html = new StringBuffer();
String namespace = req.getParameter(PARAMETER_CFG_NAMESPACE);
String action = req.getParameter(PARAMETER_CFG_ACTION);
if (action != null && namespace != null && action.indexOf(ACTION_CFG_SAVE) >= 0) {
// save the data from the POST request
String[] names = req.getParameterNames();
if (names != null) {
for (int i = 0; i < names.length; i++) {
if (!names[i].equalsIgnoreCase(PARAMETER_CFG_NAMESPACE) && !names[i].equalsIgnoreCase(PARAMETER_CFG_ACTION) && !names[i].equalsIgnoreCase("new_value") && !names[i].equalsIgnoreCase("new_type")) {
String value = req.getParameter(names[i]);
String type = null;
if (names[i].equalsIgnoreCase("new_key")) {
names[i] = req.getParameter("new_key");
value = req.getParameter("new_value");
type = req.getParameter("new_type");
}
if (value != null) {
this.getConfigManager().setProperty(namespace, names[i], value);
}
if (type != null) {
this.getConfigManager().setProperty(namespace, names[i], "type", type);
}
}
}
this.getConfigManager().saveConfiguration();
}
}
if (action != null && namespace != null && action.indexOf(ACTION_CFG_DELETE) >= 0) {
String param = action.substring((action.indexOf(":") >= 0 ? action.indexOf(":") + 1 : 0), (action.indexOf(">") >= 0 ? action.indexOf(">") : action.length()));
this.getConfigManager().removeProperty(namespace, param);
this.getConfigManager().saveConfiguration();
}
if (action != null && namespace != null && action.indexOf(ACTION_CFG_DEFAULT) >= 0) {
String param = action.substring((action.indexOf(":") >= 0 ? action.indexOf(":") + 1 : 0), (action.indexOf(">") >= 0 ? action.indexOf(">") : action.length()));
String value = this.getConfigManager().getProperty(namespace, param, "default");
this.getConfigManager().setProperty(namespace, param, value);
this.getConfigManager().saveConfiguration();
}
if (action != null && namespace != null && action.indexOf(ACTION_CFG_CLEAR) >= 0) {
String param = action.substring((action.indexOf(":") >= 0 ? action.indexOf(":") + 1 : 0), (action.indexOf(">") >= 0 ? action.indexOf(">") : action.length()));
this.getConfigManager().setProperty(namespace, param, "");
this.getConfigManager().saveConfiguration();
}
html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" + IJAMConst.CRLF);
html.append("<html>" + IJAMConst.CRLF);
html.append("<head>" + IJAMConst.CRLF);
html.append("<title>");
html.append(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()));
html.append((namespace != null ? " - " + this.getI18nManager().getString(namespace, "title", "label", getLanguage()) : ""));
html.append("</title>" + IJAMConst.CRLF);
html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" + IJAMConst.CRLF);
html.append("<link rel=\"stylesheet\" href=\"/config/web-config/styles/jam-styles.css\" type=\"text/css\">" + IJAMConst.CRLF);
html.append("<link rel=\"SHORTCUT ICON\" href=\"/config/web-config/images/favicon.ico\" type=\"image/ico\" />");
html.append("</head>" + IJAMConst.CRLF);
html.append("<body>" + IJAMConst.CRLF);
if (namespace == null || namespace.trim().length() == 0) {
// render overview page
html.append("<div id=\"header\"><h1>");
html.append("<img src=\"/config/web-config/images/logo.jpg\" id=\"logo\">");
html.append(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()) + IJAMConst.CRLF);
html.append(" - ");
html.append(getI18nManager().getString(getNamespace(), "overview", "label", getLanguage()) + IJAMConst.CRLF);
html.append("</h1></div>");
html.append("<h2>");
html.append(getI18nManager().getString(getNamespace(), "general", "label", getLanguage()) + IJAMConst.CRLF);
html.append("</h2>");
html.append("<table id=\"overview\">" + IJAMConst.CRLF);
String[] ns = this.getConfigManager().getConfigurationNamespaces();
html.append("<tr class=\"tableheader\">" + IJAMConst.CRLF);
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_mod", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_ns", "label", getLanguage()));
html.append("</th>");
html.append("</tr>" + IJAMConst.CRLF);
String p = null;
for (int i = 0; i < ns.length; i++) {
p = this.getI18nManager().getString(ns[i], "title", "label", getLanguage());
if (!p.startsWith("title") && (ns[i].toLowerCase().startsWith("janrufmonitor") || ns[i].toLowerCase().startsWith("manager.msnmanager") || ns[i].toLowerCase().startsWith("rules"))) {
html.append("<tr>" + IJAMConst.CRLF);
html.append("<td>");
html.append("<a href=\"");
html.append(URI_PATH_CONFIGURATION + "?" + PARAMETER_CFG_NAMESPACE + "=" + ns[i]);
html.append("\" target=\"_self\">");
html.append(p);
html.append("</a>");
html.append("</td>");
html.append("<td>");
html.append(ns[i] + IJAMConst.CRLF);
html.append("</td>");
html.append("</tr>" + IJAMConst.CRLF);
}
}
html.append("</table>" + IJAMConst.CRLF);
html.append("<h2>");
html.append(getI18nManager().getString(getNamespace(), "repository", "label", getLanguage()) + IJAMConst.CRLF);
html.append("</h2>");
html.append("<table id=\"overview\">" + IJAMConst.CRLF);
ns = this.getConfigManager().getConfigurationNamespaces();
html.append("<tr class=\"tableheader\">" + IJAMConst.CRLF);
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_mod", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_ns", "label", getLanguage()));
html.append("</th>");
html.append("</tr>" + IJAMConst.CRLF);
p = null;
for (int i = 0; i < ns.length; i++) {
p = this.getI18nManager().getString(ns[i], "title", "label", getLanguage());
if (!p.startsWith("title") && ns[i].toLowerCase().startsWith("repository")) {
html.append("<tr>" + IJAMConst.CRLF);
html.append("<td>");
html.append("<a href=\"");
html.append(URI_PATH_CONFIGURATION + "?" + PARAMETER_CFG_NAMESPACE + "=" + ns[i]);
html.append("\" target=\"_self\">");
html.append(p);
html.append("</a>");
html.append("</td>");
html.append("<td>");
html.append(ns[i] + IJAMConst.CRLF);
html.append("</td>");
html.append("</tr>" + IJAMConst.CRLF);
}
}
html.append("</table>" + IJAMConst.CRLF);
html.append("<h2>");
html.append(getI18nManager().getString(getNamespace(), "service", "label", getLanguage()) + IJAMConst.CRLF);
html.append("</h2>");
html.append("<table id=\"overview\">" + IJAMConst.CRLF);
ns = this.getConfigManager().getConfigurationNamespaces();
html.append("<tr class=\"tableheader\">" + IJAMConst.CRLF);
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_mod", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_ns", "label", getLanguage()));
html.append("</th>");
html.append("</tr>" + IJAMConst.CRLF);
p = null;
for (int i = 0; i < ns.length; i++) {
p = this.getI18nManager().getString(ns[i], "title", "label", getLanguage());
if (!p.startsWith("title") && ns[i].toLowerCase().startsWith("service")) {
html.append("<tr>" + IJAMConst.CRLF);
html.append("<td>");
html.append("<a href=\"");
html.append(URI_PATH_CONFIGURATION + "?" + PARAMETER_CFG_NAMESPACE + "=" + ns[i]);
html.append("\" target=\"_self\">");
html.append(p);
html.append("</a>");
html.append("</td>");
html.append("<td>");
html.append(ns[i] + IJAMConst.CRLF);
html.append("</td>");
html.append("</tr>" + IJAMConst.CRLF);
}
}
html.append("</table>" + IJAMConst.CRLF);
html.append("<h2>");
html.append(getI18nManager().getString(getNamespace(), "monitor", "label", getLanguage()) + IJAMConst.CRLF);
html.append("</h2>");
html.append("<table id=\"overview\">" + IJAMConst.CRLF);
ns = this.getConfigManager().getConfigurationNamespaces();
html.append("<tr class=\"tableheader\">" + IJAMConst.CRLF);
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_mod", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_ns", "label", getLanguage()));
html.append("</th>");
html.append("</tr>" + IJAMConst.CRLF);
p = null;
for (int i = 0; i < ns.length; i++) {
p = this.getI18nManager().getString(ns[i], "title", "label", getLanguage());
if (!p.startsWith("title") && ns[i].toLowerCase().startsWith("monitor")) {
html.append("<tr>" + IJAMConst.CRLF);
html.append("<td>");
html.append("<a href=\"");
html.append(URI_PATH_CONFIGURATION + "?" + PARAMETER_CFG_NAMESPACE + "=" + ns[i]);
html.append("\" target=\"_self\">");
html.append(p);
html.append("</a>");
html.append("</td>");
html.append("<td>");
html.append(ns[i] + IJAMConst.CRLF);
html.append("</td>");
html.append("</tr>" + IJAMConst.CRLF);
}
}
html.append("</table>" + IJAMConst.CRLF);
html.append("<h2>");
html.append(getI18nManager().getString(getNamespace(), "ui", "label", getLanguage()) + IJAMConst.CRLF);
html.append("</h2>");
html.append("<table id=\"overview\">" + IJAMConst.CRLF);
ns = this.getConfigManager().getConfigurationNamespaces();
html.append("<tr class=\"tableheader\">" + IJAMConst.CRLF);
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_mod", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_ns", "label", getLanguage()));
html.append("</th>");
html.append("</tr>" + IJAMConst.CRLF);
p = null;
for (int i = 0; i < ns.length; i++) {
p = this.getI18nManager().getString(ns[i], "title", "label", getLanguage());
if (!p.startsWith("title") && ns[i].toLowerCase().startsWith("ui.jface.application")) {
html.append("<tr>" + IJAMConst.CRLF);
html.append("<td>");
html.append("<a href=\"");
html.append(URI_PATH_CONFIGURATION + "?" + PARAMETER_CFG_NAMESPACE + "=" + ns[i]);
html.append("\" target=\"_self\">");
html.append(p);
html.append("</a>");
html.append("</td>");
html.append("<td>");
html.append(ns[i] + IJAMConst.CRLF);
html.append("</td>");
html.append("</tr>" + IJAMConst.CRLF);
}
}
html.append("</table>" + IJAMConst.CRLF);
} else {
html.append("<div id=\"header\"><h1>");
html.append("<img src=\"/config/web-config/images/logo.jpg\" id=\"logo\">");
html.append(getI18nManager().getString(getNamespace(), "title", "label", getLanguage()) + IJAMConst.CRLF);
html.append("</h1></div>");
Properties p = this.getConfigManager().getProperties(namespace);
html.append("<a href=\"" + URI_PATH_CONFIGURATION + "\" target=\"_self\" class=\"navlink\">" + getI18nManager().getString(getNamespace(), "tooverview", "label", getLanguage()) + "</a>" + IJAMConst.CRLF);
html.append("<a href=\"" + URI_PATH_CONFIGURATION + "?" + PARAMETER_CFG_NAMESPACE + "=" + namespace + "\" target=\"_self\" class=\"navlink\">" + getI18nManager().getString(getNamespace(), "refresh", "label", getLanguage()) + "</a>" + IJAMConst.CRLF);
html.append("<h2>");
html.append(getI18nManager().getString(namespace, "title", "label", getLanguage()) + IJAMConst.CRLF);
html.append("</h2>");
html.append("<form action=\"" + URI_PATH_CONFIGURATION + "?" + PARAMETER_CFG_NAMESPACE + "=" + namespace + "\" method=\"post\">");
html.append("<table id=\"configuration\">" + IJAMConst.CRLF);
html.append("<tr class=\"tableheader\">" + IJAMConst.CRLF);
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_parameter", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_type", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_access", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_curr_value", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_new_value", "label", getLanguage()));
html.append("</th>");
html.append("<th>");
html.append(getI18nManager().getString(getNamespace(), "column_action", "label", getLanguage()));
html.append("</th>");
html.append("</tr>" + IJAMConst.CRLF);
Iterator i = p.keySet().iterator();
String key = null;
String type = null;
String access = null;
while (i.hasNext()) {
key = (String) i.next();
type = getConfigManager().getProperty(namespace, key, "type");
access = getConfigManager().getProperty(namespace, key, "access");
html.append("<tr class=\"configentry\" id=\"" + access + "\">" + IJAMConst.CRLF);
html.append("<td class=\"parameter\">");
html.append(key);
html.append("</td>");
html.append("<td class=\"type\">");
html.append(type);
html.append("</td>");
html.append("<td class=\"access\">");
html.append(access);
html.append("</td>");
html.append("<td class=\"currentvalue\">");
html.append((p.getProperty(key).length() == 0 ? "(n/a)" : p.getProperty(key)));
html.append("</td>");
html.append("<td class=\"newvalue\">");
html.append((access.equalsIgnoreCase("system") ? " " : "<input type=\"text\" name=\"" + key + "\" class=\"newvalueinput\">"));
html.append("</td>");
html.append("<td class=\"actions\">");
html.append((access.equalsIgnoreCase("system") ? " " : "<button type=\"submit\" name=\"action\" class=\"actionbutton\" value=\"delete:" + key + "\"><div id=\"delete:" + key + "\">" + getI18nManager().getString(getNamespace(), "delete", "label", getLanguage()) + "</div></button>" + IJAMConst.CRLF));
html.append((access.equalsIgnoreCase("system") ? " " : "<button type=\"submit\" name=\"action\" class=\"actionbutton\" value=\"default:" + key + "\"><div id=\"default:" + key + "\">" + getI18nManager().getString(getNamespace(), "default", "label", getLanguage()) + "</div></button>" + IJAMConst.CRLF));
html.append((access.equalsIgnoreCase("system") ? " " : "<button type=\"submit\" name=\"action\" class=\"actionbutton\" value=\"clear:" + key + "\"><div id=\"clear:" + key + "\">" + getI18nManager().getString(getNamespace(), "clear", "label", getLanguage()) + "</div></button>" + IJAMConst.CRLF));
html.append("</td>");
html.append("</tr>" + IJAMConst.CRLF);
}
// add new parameter
html.append("<tr class=\"configentry\">" + IJAMConst.CRLF);
html.append("<td class=\"parameter\">");
html.append("<input type=\"text\" name=\"new_key\" class=\"newvalueinput\">");
html.append("</td>");
html.append("<td class=\"type\">");
html.append("<input type=\"text\" name=\"new_type\" class=\"newvalueinput\">");
html.append("</td>");
html.append("<td class=\"type\">");
html.append("user");
html.append("</td>");
html.append("<td class=\"currentvalue\">");
html.append(" ");
html.append("</td>");
html.append("<td class=\"newvalue\">");
html.append("<input type=\"text\" name=\"new_value\" class=\"newvalueinput\">");
html.append("</td>");
html.append("<td class=\"actions\">");
html.append(" ");
html.append("</td>");
html.append("</tr>" + IJAMConst.CRLF);
html.append("</table>" + IJAMConst.CRLF);
html.append("<button type=\"submit\" id=\"savebutton\" name=\"action\" value=\"save\"><div id=\"save\">" + getI18nManager().getString(getNamespace(), "save", "label", getLanguage()) + "</div></button>");
html.append("</form>" + IJAMConst.CRLF);
}
html.append("<div id=\"footer\">Created by jAnrufmonitor (" + (System.currentTimeMillis() - start) + " ms) on " + new Date().toString() + "</div>");
html.append("</body>" + IJAMConst.CRLF);
html.append("</html>" + IJAMConst.CRLF);
resp.setParameter("Content-Type", "text/html");
resp.setParameter("Content-Length", Long.toString(html.length()));
OutputStream ps = resp.getContentStreamForWrite();
ps.write(html.toString().getBytes());
ps.flush();
ps.close();
} catch (HandlerException e) {
throw e;
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.
the class GetCall method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallManager mgr = null;
String manager = null;
try {
manager = req.getParameter(GetCall.PARAMETER_CALLMANAGER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallManagerFactory().getDefaultCallManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallManagerFactory().getCallManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallRepository.class)) {
throw new HandlerException("Requested Callmanager does not exist or is not active.", 404);
}
String uuid = null;
try {
uuid = req.getParameter(GetCall.PARAMETER_UUID);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (uuid == null || uuid.length() == 0) {
this.m_logger.severe("Parameter &uuid= was empty or not set.");
throw new HandlerException("Parameter &uuid= was empty or not set.", 404);
}
try {
ICallList callList = ((IReadCallRepository) mgr).getCalls(new UUIDFilter(new String[] { uuid }));
if (callList.size() > 0) {
String xml = XMLSerializer.toXML(callList.get(0), false);
resp.setParameter("Content-Type", "text/xml");
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.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.
the class GetCallListCount method getAllowedMsnFilter.
private IFilter[] getAllowedMsnFilter(IHttpRequest req) throws HandlerException {
try {
boolean allowedForAllMsns = (SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName()) == null && SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress()) == null);
if (!allowedForAllMsns) {
String[] allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName());
if (allowedMSNs == null)
allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress());
if (allowedMSNs != null) {
IFilter[] allowedMsnFilter = new IFilter[allowedMSNs.length];
IMsn msn = null;
for (int i = 0; i < allowedMSNs.length; i++) {
msn = getRuntime().getMsnManager().createMsn(allowedMSNs[i]);
allowedMsnFilter[i] = new MsnFilter(msn);
m_logger.info("Adding allowed MSN filter for client: " + allowedMsnFilter[i].toString());
}
return allowedMsnFilter;
}
}
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new HandlerException(e.getMessage(), 500);
}
return new IFilter[0];
}
use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.
the class Reject method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
Thread sender = new Thread(new HandlerThread(this));
sender.start();
try {
resp.getContentStreamForWrite().close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
Aggregations