Search in sources :

Example 1 with XssRequestWrapper

use of org.opennms.web.servlet.XssRequestWrapper in project opennms by OpenNMS.

the class AlarmDetailController method detail.

/**
     * {@inheritDoc}
     *
     * Display alarm detail page
     */
public ModelAndView detail(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
    OnmsAlarm m_alarm = null;
    XssRequestWrapper safeRequest = new XssRequestWrapper(httpServletRequest);
    String alarmIdString = "";
    List<OnmsAcknowledgment> acknowledgments = Collections.emptyList();
    // Try to parse alarm ID as string to integer
    try {
        alarmIdString = safeRequest.getParameter("id");
        int alarmId = Integer.parseInt(alarmIdString);
        acknowledgments = m_webAlarmRepository.getAcknowledgments(alarmId);
        // Get alarm by ID
        m_alarm = m_webAlarmRepository.getAlarm(alarmId);
        logger.debug("Alarm retrieved: '{}'", m_alarm.toString());
    } catch (NumberFormatException e) {
        logger.error("Could not parse alarm ID '{}' to integer.", safeRequest.getParameter("id"));
    } catch (Throwable e) {
        logger.error("Could not retrieve alarm from webAlarmRepository for ID='{}'", alarmIdString);
    }
    if (m_alarm == null) {
        throw new AlarmIdNotFoundException("Could not find alarm with ID: " + alarmIdString, alarmIdString);
    }
    // return to view WEB-INF/jsp/alarm/detail.jsp
    ModelAndView mv = new ModelAndView("alarm/detail");
    mv.addObject("alarm", m_alarm);
    mv.addObject("alarmId", alarmIdString);
    mv.addObject("acknowledgments", acknowledgments);
    return mv;
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) XssRequestWrapper(org.opennms.web.servlet.XssRequestWrapper) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ModelAndView(org.springframework.web.servlet.ModelAndView) AlarmIdNotFoundException(org.opennms.web.alarm.AlarmIdNotFoundException)

Aggregations

OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 AlarmIdNotFoundException (org.opennms.web.alarm.AlarmIdNotFoundException)1 XssRequestWrapper (org.opennms.web.servlet.XssRequestWrapper)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1