Search in sources :

Example 41 with RequestDispatcher

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

the class AddGroupDutySchedulesServlet method doPost.

/** {@inheritDoc} */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(true);
    Group group = (Group) userSession.getAttribute("group.modifyGroup.jsp");
    Vector<Object> newSchedule = new Vector<Object>();
    int dutyAddCount = WebSecurityUtils.safeParseInt(request.getParameter("numSchedules"));
    for (int j = 0; j < dutyAddCount; j++) {
        // add 7 false boolean values for each day of the week
        for (int i = 0; i < 7; i++) {
            newSchedule.addElement(Boolean.FALSE);
        }
        // add two strings for the begin and end time
        newSchedule.addElement("0");
        newSchedule.addElement("0");
        group.addDutySchedule((new DutySchedule(newSchedule)).toString());
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/userGroupView/groups/modifyGroup.jsp");
    dispatcher.forward(request, response);
}
Also used : Group(org.opennms.netmgt.config.groups.Group) HttpSession(javax.servlet.http.HttpSession) DutySchedule(org.opennms.netmgt.config.users.DutySchedule) Vector(java.util.Vector) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 42 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 43 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 44 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 45 with RequestDispatcher

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

the class UpdateUserServlet method doPost.

/** {@inheritDoc} */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(false);
    if (userSession != null) {
        User newUser = (User) userSession.getAttribute("user.modifyUser.jsp");
        try {
            UserFactory.init();
        } catch (Throwable e) {
            throw new ServletException("UpdateUserServlet:init Error initialising UserFactory " + e);
        }
        // get the rest of the user information from the form
        newUser.setFullName(request.getParameter("fullName"));
        newUser.setUserComments(request.getParameter("userComments"));
        String password = request.getParameter("password");
        if (password != null && !password.trim().equals("")) {
            final Password pass = new Password();
            pass.setEncryptedPassword(UserFactory.getInstance().encryptedPassword(password, true));
            pass.setSalt(true);
            newUser.setPassword(pass);
        }
        String tuiPin = request.getParameter("tuiPin");
        if (tuiPin != null && !tuiPin.trim().equals("")) {
            newUser.setTuiPin(tuiPin);
        }
        String email = request.getParameter(ContactType.email.toString());
        String pagerEmail = request.getParameter("pemail");
        String xmppAddress = request.getParameter(ContactType.xmppAddress.toString());
        String microblog = request.getParameter(ContactType.microblog.toString());
        String numericPage = request.getParameter("numericalService");
        String numericPin = request.getParameter("numericalPin");
        String textPage = request.getParameter("textService");
        String textPin = request.getParameter("textPin");
        String workPhone = request.getParameter(ContactType.workPhone.toString());
        String mobilePhone = request.getParameter(ContactType.mobilePhone.toString());
        String homePhone = request.getParameter(ContactType.homePhone.toString());
        newUser.clearContacts();
        Contact tmpContact = new Contact();
        tmpContact.setInfo(email);
        tmpContact.setType(ContactType.email.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(pagerEmail);
        tmpContact.setType(ContactType.pagerEmail.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(xmppAddress);
        tmpContact.setType(ContactType.xmppAddress.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(microblog);
        tmpContact.setType(ContactType.microblog.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(numericPin);
        tmpContact.setServiceProvider(numericPage);
        tmpContact.setType(ContactType.numericPage.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(textPin);
        tmpContact.setServiceProvider(textPage);
        tmpContact.setType(ContactType.textPage.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(workPhone);
        tmpContact.setType(ContactType.workPhone.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(mobilePhone);
        tmpContact.setType(ContactType.mobilePhone.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(homePhone);
        tmpContact.setType(ContactType.homePhone.toString());
        newUser.addContact(tmpContact);
        // build the duty schedule data structure
        List<Boolean> newSchedule = new ArrayList<Boolean>(7);
        ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su");
        Collection<String> dutySchedules = getDutySchedulesForUser(newUser);
        dutySchedules.clear();
        int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
        for (int duties = 0; duties < dutyCount; duties++) {
            newSchedule.clear();
            String deleteFlag = request.getParameter("deleteDuty" + duties);
            // don't save any duties that were marked for deletion
            if (deleteFlag == null) {
                for (int i = 0; i < 7; i++) {
                    String curDayFlag = request.getParameter("duty" + duties + days.format(i));
                    newSchedule.add(Boolean.valueOf(curDayFlag != null));
                }
                int startTime = WebSecurityUtils.safeParseInt(request.getParameter("duty" + duties + "Begin"));
                int stopTime = WebSecurityUtils.safeParseInt(request.getParameter("duty" + duties + "End"));
                DutySchedule newDuty = new DutySchedule(newSchedule, startTime, stopTime);
                dutySchedules.add(newDuty.toString());
            }
        }
        // The new list of roles will override the existing one.
        // If the new list is empty or null, that means the user should not have roles, and the existing ones should be removed.
        newUser.getRoles().clear();
        String[] configuredRoles = request.getParameterValues("configuredRoles");
        if (configuredRoles != null && configuredRoles.length > 0) {
            newUser.getRoles().clear();
            for (String role : configuredRoles) {
                newUser.addRole(role);
            }
        }
        userSession.setAttribute("user.modifyUser.jsp", newUser);
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(request.getParameter("redirect"));
    dispatcher.forward(request, response);
}
Also used : User(org.opennms.netmgt.config.users.User) HttpSession(javax.servlet.http.HttpSession) ChoiceFormat(java.text.ChoiceFormat) ArrayList(java.util.ArrayList) RequestDispatcher(javax.servlet.RequestDispatcher) Contact(org.opennms.netmgt.config.users.Contact) ServletException(javax.servlet.ServletException) DutySchedule(org.opennms.netmgt.config.users.DutySchedule) Password(org.opennms.netmgt.config.users.Password)

Aggregations

RequestDispatcher (javax.servlet.RequestDispatcher)203 ServletException (javax.servlet.ServletException)63 HttpSession (javax.servlet.http.HttpSession)58 IOException (java.io.IOException)41 SQLException (java.sql.SQLException)31 HttpServletRequest (javax.servlet.http.HttpServletRequest)30 HttpServletResponse (javax.servlet.http.HttpServletResponse)26 Properties (java.util.Properties)14 ServletContext (javax.servlet.ServletContext)12 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 WebUser (org.compiere.util.WebUser)9 ClienteDAO (br.senac.tads3.pi03b.gruposete.dao.ClienteDAO)8 PrintWriter (java.io.PrintWriter)8 ServletResponse (javax.servlet.ServletResponse)8 Cliente (br.senac.tads3.pi03b.gruposete.models.Cliente)7 ServletRequest (javax.servlet.ServletRequest)7 User (org.opennms.netmgt.config.users.User)7 HotelDAO (br.senac.tads3.pi03b.gruposete.dao.HotelDAO)6 VooDAO (br.senac.tads3.pi03b.gruposete.dao.VooDAO)6