addpollerconfigservlet.java
来自「opennms得相关源码 请大家看看」· Java 代码 · 共 456 行 · 第 1/2 页
JAVA
456 行
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc. All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Copyright (C) 1999-2001 Oculan Corp. All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// For more information contact:// OpenNMS Licensing <license@opennms.org>// http://www.opennms.org/// http://www.opennms.com///package org.opennms.web.admin.pollerConfig;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.IOException;import java.io.StringWriter;import java.util.ArrayList;import java.util.Collection;import java.util.Enumeration;import java.util.HashMap;import java.util.Iterator;import java.util.Properties;import javax.servlet.ServletConfig;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.exolab.castor.xml.MarshalException;import org.exolab.castor.xml.Marshaller;import org.exolab.castor.xml.ValidationException;import org.opennms.core.resource.Vault;import org.opennms.core.utils.BundleLists;import org.opennms.netmgt.ConfigFileConstants;import org.opennms.netmgt.config.CapsdConfigFactory;import org.opennms.netmgt.config.PollerConfigFactory;import org.opennms.netmgt.config.capsd.CapsdConfiguration;import org.opennms.netmgt.config.capsd.ProtocolPlugin;import org.opennms.netmgt.config.poller.Monitor;import org.opennms.netmgt.config.poller.PollerConfiguration;import org.opennms.netmgt.config.poller.Service;import org.opennms.web.Util;/** * A servlet that handles managing or unmanaging interfaces and services on a * node * * @author <A HREF="mailto:jacinta@opennms.org">Jacinta Remedios </A> * @author <A HREF="http://www.opennms.org/">OpenNMS </A> */public class AddPollerConfigServlet extends HttpServlet { PollerConfiguration pollerConfig = null; CapsdConfiguration capsdConfig = null; protected String redirectSuccess; HashMap pollerServices = new HashMap(); HashMap capsdProtocols = new HashMap(); java.util.List capsdColl = new ArrayList(); org.opennms.netmgt.config.poller.Package pkg = null; Collection pluginColl = null; Properties props = new Properties(); PollerConfigFactory pollerFactory = null; CapsdConfigFactory capsdFactory = null; boolean errorflag = false; public void init() throws ServletException { String homeDir = Vault.getHomeDir(); ServletConfig config = this.getServletConfig(); ServletContext context = config.getServletContext(); Enumeration en = context.getAttributeNames(); try { props.load(new FileInputStream(ConfigFileConstants.getFile(ConfigFileConstants.POLLER_CONF_FILE_NAME))); String[] protocols = BundleLists.parseBundleList(this.props.getProperty("services")); PollerConfigFactory.init(); pollerFactory = PollerConfigFactory.getInstance(); pollerConfig = pollerFactory.getConfiguration(); if (pollerConfig == null) { // response.sendRedirect( "error.jsp?error=2"); errorflag = true; throw new ServletException("Poller Configuration file is empty"); } CapsdConfigFactory.init(); capsdFactory = CapsdConfigFactory.getInstance(); capsdConfig = capsdFactory.getConfiguration(); if (capsdConfig == null) { // response.sendRedirect( "error.jsp?error=3"); errorflag = true; throw new ServletException("Capsd Configuration file is empty"); } } catch (Exception e) { throw new ServletException(e.getMessage()); } initPollerServices(); initCapsdProtocols(); this.redirectSuccess = config.getInitParameter("redirect.success"); if (this.redirectSuccess == null) { throw new ServletException("Missing required init parameter: redirect.success"); } } public void reloadFiles() throws ServletException { String homeDir = Vault.getHomeDir(); ServletConfig config = this.getServletConfig(); ServletContext context = config.getServletContext(); Enumeration en = context.getAttributeNames(); try { props.load(new FileInputStream(ConfigFileConstants.getFile(ConfigFileConstants.POLLER_CONF_FILE_NAME))); String[] protocols = BundleLists.parseBundleList(this.props.getProperty("services")); PollerConfigFactory.init(); pollerFactory = PollerConfigFactory.getInstance(); pollerConfig = pollerFactory.getConfiguration(); if (pollerConfig == null) { // response.sendRedirect( "error.jsp?error=2"); errorflag = true; throw new ServletException("Poller Configuration file is empty"); } CapsdConfigFactory.init(); capsdFactory = CapsdConfigFactory.getInstance(); capsdConfig = capsdFactory.getConfiguration(); if (capsdConfig == null) { errorflag = true; // response.sendRedirect( "error.jsp?error=3"); throw new ServletException("Capsd Configuration file is empty"); } } catch (Exception e) { throw new ServletException(e.getMessage()); } initPollerServices(); initCapsdProtocols(); this.redirectSuccess = config.getInitParameter("redirect.success"); if (this.redirectSuccess == null) { throw new ServletException("Missing required init parameter: redirect.success"); } } public void initCapsdProtocols() { capsdProtocols = new HashMap(); pluginColl = capsdConfig.getProtocolPluginCollection(); if (pluginColl != null) { Iterator pluginiter = pluginColl.iterator(); while (pluginiter.hasNext()) { ProtocolPlugin plugin = (ProtocolPlugin) pluginiter.next(); capsdColl.add(plugin); capsdProtocols.put(plugin.getProtocol(), plugin); } } } public void initPollerServices() { pollerServices = new HashMap(); Collection packageColl = pollerConfig.getPackageCollection(); if (packageColl != null) { Iterator pkgiter = packageColl.iterator(); if (pkgiter.hasNext()) { pkg = (org.opennms.netmgt.config.poller.Package) pkgiter.next(); Collection svcColl = pkg.getServiceCollection(); Iterator svcIter = svcColl.iterator(); Service svcProp = null; while (svcIter.hasNext()) { svcProp = (Service) svcIter.next(); pollerServices.put(svcProp.getName(), svcProp); } } } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletConfig config = this.getServletConfig(); ServletContext context = config.getServletContext(); String user_id = request.getRemoteUser(); Enumeration en = context.getAttributeNames(); errorflag = false; reloadFiles(); // String query = request.getQueryString(); // if(query != null) { String check1 = request.getParameter("check1"); String name1 = request.getParameter("name1"); String protoArray1 = request.getParameter("protArray1"); String port1 = request.getParameter("port1"); java.util.List checkedList = new ArrayList(); java.util.List deleteList = new ArrayList(); if (name1 != null && !name1.equals("")) { addPollerInfo(check1, name1, port1, user_id, protoArray1, response, request); if (errorflag) return; checkedList.add(name1);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?