Search in sources :

Example 51 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project opennms by OpenNMS.

the class AddNewInterfaceServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int nodeId = -1;
    String ipAddress = request.getParameter("ipAddress");
    try {
        nodeId = getNodeId(ipAddress);
    } catch (SQLException sqlE) {
        throw new ServletException("AddInterfaceServlet: failed to query if the ipaddress already exists", sqlE);
    }
    if (nodeId != -1) {
        RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/newInterface.jsp?action=redo");
        dispatcher.forward(request, response);
    } else {
        createAndSendNewSuspectInterfaceEvent(ipAddress);
        // forward the request for proper display
        RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/interfaceAdded.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 52 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project opennms by OpenNMS.

the class SetCriticalPathServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String nodeString = request.getParameter("node");
    String criticalIp = InetAddressUtils.normalize(request.getParameter("criticalIp"));
    String criticalSvc = request.getParameter("criticalSvc");
    String task = request.getParameter("task");
    int node = -1;
    try {
        node = WebSecurityUtils.safeParseInt(nodeString);
    } catch (NumberFormatException numE) {
        throw new ServletException(numE);
    }
    if (task.equals("Delete")) {
        try {
            deleteCriticalPath(node);
        } catch (SQLException e) {
            throw new ServletException("SetCriticalPathServlet: Error writing to database." + e);
        }
    } else if (task.equals("Submit")) {
        try {
            setCriticalPath(node, criticalIp, criticalSvc);
        } catch (SQLException e) {
            throw new ServletException("SetCriticalPathServlet: Error writing to database." + e);
        }
    } else {
        RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/nodemanagement/setPathOutage.jsp?node=" + node + "&task=Requested operation " + task + " not understood.");
        dispatcher.forward(request, response);
        return;
    }
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/nodemanagement/index.jsp?node=" + node);
    dispatcher.forward(request, response);
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 53 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project opennms by OpenNMS.

the class SnmpGetNodesServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession user = request.getSession(true);
    try {
        user.setAttribute("listAllnodes.snmpmanage.jsp", getAllNodes(user));
    } catch (SQLException e) {
        throw new ServletException(e);
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/snmpmanage.jsp");
    dispatcher.forward(request, response);
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) HttpSession(javax.servlet.http.HttpSession) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 54 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project opennms by OpenNMS.

the class SnmpManageNodesServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(false);
    List<SnmpManagedInterface> allInterfaces = getManagedInterfacesFromSession(userSession);
    // the node being modified
    String nodeIdString = request.getParameter("node");
    int currNodeId = WebSecurityUtils.safeParseInt(nodeIdString);
    String primeInt = null;
    for (final SnmpManagedInterface testInterface : allInterfaces) {
        if (testInterface.getNodeid() == currNodeId && PrimaryType.PRIMARY.getCode().equals(testInterface.getStatus())) {
            // Get the IP address of the primary SNMP interface
            primeInt = NetworkElementFactory.getInstance(this.getServletContext()).getIpPrimaryAddress(currNodeId);
        }
    }
    final DBUtils d = new DBUtils(getClass());
    try {
        Connection connection = DataSourceFactory.getInstance().getConnection();
        d.watch(connection);
        try {
            connection.setAutoCommit(false);
            PreparedStatement stmt = connection.prepareStatement(UPDATE_INTERFACE);
            d.watch(stmt);
            for (SnmpManagedInterface curInterface : allInterfaces) {
                String option = request.getParameter("collect-" + curInterface.getIfIndex());
                LOG.debug("option = {}", option);
                stmt.setString(1, option);
                stmt.setInt(2, curInterface.getSnmpInterfaceId());
                stmt.execute();
            }
            connection.commit();
        } finally {
            // close off the db connection
            connection.setAutoCommit(true);
        }
    } catch (SQLException e) {
        throw new ServletException(e);
    } finally {
        d.cleanUp();
    }
    // send the event to restart SNMP Collection
    if (primeInt != null) {
        sendSNMPRestartEvent(currNodeId, primeInt);
    }
    // forward the request for proper display
    // TODO This will redirect to the node page, but the URL will be admin/changeCollectStatus. Needs fixed.
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/element/node.jsp?node=" + currNodeId);
    dispatcher.forward(request, response);
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) HttpSession(javax.servlet.http.HttpSession) DBUtils(org.opennms.core.utils.DBUtils) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 55 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project opennms by OpenNMS.

the class ModifyUserServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(true);
    try {
        UserFactory.init();
        UserManager userFactory = UserFactory.getInstance();
        User user = userFactory.getUser(request.getParameter("userID"));
        userSession.setAttribute("user.modifyUser.jsp", user);
    } catch (Throwable e) {
        throw new ServletException("Couldn't initialize UserFactory", e);
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/userGroupView/users/modifyUser.jsp");
    dispatcher.forward(request, response);
}
Also used : ServletException(javax.servlet.ServletException) User(org.opennms.netmgt.config.users.User) HttpSession(javax.servlet.http.HttpSession) UserManager(org.opennms.netmgt.config.UserManager) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

RequestDispatcher (javax.servlet.RequestDispatcher)354 ServletException (javax.servlet.ServletException)98 HttpSession (javax.servlet.http.HttpSession)97 IOException (java.io.IOException)74 HttpServletRequest (javax.servlet.http.HttpServletRequest)56 HttpServletResponse (javax.servlet.http.HttpServletResponse)44 SQLException (java.sql.SQLException)31 User (com.zyf.bean.User)28 ServletContext (javax.servlet.ServletContext)26 Properties (java.util.Properties)14 Test (org.junit.Test)14 RelatorioDAO (br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO)13 RelatorioMudancas (br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas)12 PrintWriter (java.io.PrintWriter)12 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)11 Resource (org.apache.sling.api.resource.Resource)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 GenericValue (org.apache.ofbiz.entity.GenericValue)9 WebUser (org.compiere.util.WebUser)9