use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.
the class DownloadReportController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String fileName = request.getParameter("fileName");
m_reportdConfigurationDao = BeanUtils.getBean("reportdContext", "reportdConfigDao", ReportdConfigurationDao.class);
final File storageDirectory = new File(m_reportdConfigurationDao.getStorageDirectory());
if (fileName != null) {
final File requestedFile = new File(fileName);
if (!requestedFile.getParentFile().getCanonicalFile().equals(storageDirectory.getCanonicalFile())) {
LOG.warn("User attempted to retrieve file {} but was restricted to {}", requestedFile, storageDirectory);
throw new IllegalArgumentException("Cannot retrieve reports from outside Reportd storage directory");
}
if (fileName.toLowerCase().endsWith(".pdf")) {
response.setContentType("application/pdf;charset=UTF-8");
}
if (fileName.toLowerCase().endsWith(".csv")) {
response.setContentType("text/csv;charset=UTF-8");
}
response.setHeader("Content-disposition", "inline; filename=" + fileName);
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "cache");
response.setHeader("Cache-Control", "must-revalidate");
StreamUtils.streamToStream(new FileInputStream(new File(fileName)), response.getOutputStream());
return null;
}
String[] requiredParameters = new String[] { "locatorId", "format" };
for (String requiredParameter : requiredParameters) {
if (request.getParameter(requiredParameter) == null) {
throw new MissingParameterException(requiredParameter, requiredParameters);
}
}
try {
Integer reportCatalogEntryId = Integer.valueOf(WebSecurityUtils.safeParseInt(request.getParameter("locatorId")));
String requestFormat = new String(request.getParameter("format"));
if ((ReportFormat.PDF == ReportFormat.valueOf(requestFormat)) || (ReportFormat.SVG == ReportFormat.valueOf(requestFormat))) {
response.setContentType("application/pdf;charset=UTF-8");
response.setHeader("Content-disposition", "inline; filename=" + reportCatalogEntryId.toString() + ".pdf");
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "cache");
response.setHeader("Cache-Control", "must-revalidate");
}
if (ReportFormat.CSV == ReportFormat.valueOf(requestFormat)) {
response.setContentType("text/csv;charset=UTF-8");
response.setHeader("Content-disposition", "inline; filename=" + reportCatalogEntryId.toString() + ".csv");
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "cache");
response.setHeader("Cache-Control", "must-revalidate");
}
m_reportStoreService.render(reportCatalogEntryId, ReportFormat.valueOf(requestFormat), (OutputStream) response.getOutputStream());
} catch (NumberFormatException e) {
// TODO something useful here.
}
return null;
}
use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.
the class GraphResultsController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String[] requiredParameters = new String[] { "resourceId", "reports" };
for (String requiredParameter : requiredParameters) {
if (request.getParameter(requiredParameter) == null) {
throw new MissingParameterException(requiredParameter, requiredParameters);
}
}
ResourceId[] resourceIds = Arrays.stream(request.getParameterValues("resourceId")).map(ResourceId::fromString).toArray(ResourceId[]::new);
String[] reports = request.getParameterValues("reports");
// see if the start and end time were explicitly set as params
String start = request.getParameter("start");
String end = request.getParameter("end");
String relativeTime = request.getParameter("relativetime");
final String startMonth = request.getParameter("startMonth");
final String startDate = request.getParameter("startDate");
final String startYear = request.getParameter("startYear");
final String startHour = request.getParameter("startHour");
final String endMonth = request.getParameter("endMonth");
final String endDate = request.getParameter("endDate");
final String endYear = request.getParameter("endYear");
final String endHour = request.getParameter("endHour");
long startLong = 0;
long endLong = 0;
if (start != null || end != null) {
String[] ourRequiredParameters = new String[] { "start", "end" };
if (start == null) {
throw new MissingParameterException("start", ourRequiredParameters);
}
if (end == null) {
throw new MissingParameterException("end", ourRequiredParameters);
}
//The following is very similar to RrdGraphController.parseTimes, but modified for the local context a bit
// There's merging possibilities, but I don't know how (common parent class seems wrong; service bean for a single
// method isn't much better. Ideas?
//Try a simple 'long' parsing. If either fails, do a full parse. If one is a straight 'long' but the other isn't
// that's fine, the TimeParser code will handle it fine (as long as we convert milliseconds to seconds)
// Indeed, we *have* to use TimeParse for both to ensure any relative references (using "start" or "end") work correctly.
// NB: can't do a "safe" parsing using the WebSecurityUtils; if we did, it would filter out all the possible rrdfetch
// format text and always work :)
boolean startIsInteger = false;
boolean endIsInteger = false;
// is expected for epoch times by TimeParser
try {
startLong = Long.valueOf(start);
startIsInteger = true;
start = "" + (startLong / 1000);
} catch (NumberFormatException e) {
}
try {
endLong = Long.valueOf(end);
endIsInteger = true;
end = "" + (endLong / 1000);
} catch (NumberFormatException e) {
}
if (!endIsInteger || !startIsInteger) {
//One or both of start/end aren't integers, so we need to do full parsing using TimeParser
TimeParser startParser = new TimeParser(start);
TimeParser endParser = new TimeParser(end);
try {
TimeSpec specStart = startParser.parse();
TimeSpec specEnd = endParser.parse();
long[] results = TimeSpec.getTimestamps(specStart, specEnd);
//Multiply by 1000. TimeSpec returns timestamps in Seconds, not Milliseconds.
startLong = results[0] * 1000;
endLong = results[1] * 1000;
} catch (RrdException e1) {
throw new IllegalArgumentException("Could not parse start '" + start + "' and end '" + end + "' as valid time specifications", e1);
}
}
} else if (startMonth != null || startDate != null || startYear != null || startHour != null || endMonth != null || endDate != null || endYear != null || endHour != null) {
String[] ourRequiredParameters = new String[] { "startMonth", "startDate", "startYear", "startHour", "endMonth", "endDate", "endYear", "endHour" };
for (String requiredParameter : ourRequiredParameters) {
if (request.getParameter(requiredParameter) == null) {
throw new MissingParameterException(requiredParameter, ourRequiredParameters);
}
}
Calendar startCal = Calendar.getInstance();
startCal.set(Calendar.MONTH, WebSecurityUtils.safeParseInt(startMonth));
startCal.set(Calendar.DATE, WebSecurityUtils.safeParseInt(startDate));
startCal.set(Calendar.YEAR, WebSecurityUtils.safeParseInt(startYear));
startCal.set(Calendar.HOUR_OF_DAY, WebSecurityUtils.safeParseInt(startHour));
startCal.set(Calendar.MINUTE, 0);
startCal.set(Calendar.SECOND, 0);
startCal.set(Calendar.MILLISECOND, 0);
Calendar endCal = Calendar.getInstance();
endCal.set(Calendar.MONTH, WebSecurityUtils.safeParseInt(endMonth));
endCal.set(Calendar.DATE, WebSecurityUtils.safeParseInt(endDate));
endCal.set(Calendar.YEAR, WebSecurityUtils.safeParseInt(endYear));
endCal.set(Calendar.HOUR_OF_DAY, WebSecurityUtils.safeParseInt(endHour));
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.SECOND, 0);
endCal.set(Calendar.MILLISECOND, 0);
startLong = startCal.getTime().getTime();
endLong = endCal.getTime().getTime();
} else {
if (relativeTime == null) {
relativeTime = s_periods[0].getId();
}
RelativeTimePeriod period = RelativeTimePeriod.getPeriodByIdOrDefault(s_periods, relativeTime, s_periods[0]);
long[] times = period.getStartAndEndTimes();
startLong = times[0];
endLong = times[1];
}
// The 'matching' parameter is going to work only for one resource.
String matching = request.getParameter("matching");
if (matching != null) {
reports = getSuggestedReports(resourceIds[0], matching);
}
ModelAndView modelAndView = null;
try {
GraphResults model = m_graphResultsService.findResults(resourceIds, reports, startLong, endLong, relativeTime);
modelAndView = new ModelAndView("/graph/results", "results", model);
} catch (Exception e) {
LOG.warn("Can't get graph results", e);
modelAndView = new ModelAndView("/graph/results-error");
}
modelAndView.addObject("loggedIn", request.getRemoteUser() != null);
return modelAndView;
}
use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.
the class NodeCategoryBoxController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String nodeIdString = request.getParameter("node");
if (nodeIdString == null) {
throw new MissingParameterException("node");
}
int nodeId = WebSecurityUtils.safeParseInt(nodeIdString);
List<OnmsCategory> categories = m_adminCategoryService.findByNode(nodeId);
ModelAndView modelAndView = new ModelAndView("/includes/nodeCategory-box", "categories", categories);
if (request.isUserInRole(Authentication.ROLE_ADMIN)) {
modelAndView.addObject("isAdmin", "true");
}
return modelAndView;
}
use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.
the class RrdGraphController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String[] requiredParameters = new String[] { "resourceId", "start", "end" };
for (String requiredParameter : requiredParameters) {
if (request.getParameter(requiredParameter) == null) {
throw new MissingParameterException(requiredParameter, requiredParameters);
}
}
ResourceId resourceId = ResourceId.fromString(request.getParameter("resourceId"));
long[] times = this.parseTimes(request);
long startTime = times[0];
long endTime = times[1];
InputStream tempIn;
if ("true".equals(request.getParameter("adhoc"))) {
String[] adhocRequiredParameters = new String[] { "title", "ds", "agfunction", "color", "dstitle", "style" };
for (String requiredParameter : adhocRequiredParameters) {
if (request.getParameter(requiredParameter) == null) {
throw new MissingParameterException(requiredParameter, adhocRequiredParameters);
}
}
String title = request.getParameter("title");
String[] dataSources = request.getParameterValues("ds");
String[] aggregateFunctions = request.getParameterValues("agfunction");
String[] colors = request.getParameterValues("color");
String[] dataSourceTitles = request.getParameterValues("dstitle");
String[] styles = request.getParameterValues("style");
tempIn = m_rrdGraphService.getAdhocGraph(resourceId, title, dataSources, aggregateFunctions, colors, dataSourceTitles, styles, startTime, endTime);
} else {
String report = request.getParameter("report");
if (report == null) {
throw new MissingParameterException("report");
}
String width = request.getParameter("width");
String height = request.getParameter("height");
tempIn = m_rrdGraphService.getPrefabGraph(resourceId, report, startTime, endTime, width != null && !width.isEmpty() ? Integer.valueOf(width) : null, height != null && !height.isEmpty() ? Integer.valueOf(height) : null);
}
response.setContentType("image/png");
StreamUtils.streamToStream(tempIn, response.getOutputStream());
tempIn.close();
return null;
}
use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.
the class CustomGraphEditDetailsController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String resourceId = request.getParameter(Parameters.resourceId.toString());
if (resourceId == null) {
throw new MissingParameterException(Parameters.resourceId.toString());
}
//optional parameter graphtype
String prefabReportName = request.getParameter(Parameters.graphtype.toString());
KscReportEditor editor = KscReportEditor.getFromSession(request.getSession(), true);
Report report = editor.getWorkingReport();
org.opennms.netmgt.config.kscReports.Graph sample_graph = editor.getWorkingGraph();
if (sample_graph == null) {
throw new IllegalArgumentException("Invalid working graph argument -- null pointer. Possibly missing prefab report in snmp-graph.properties?");
}
// Set the resourceId in the working graph in case it changed
sample_graph.setResourceId(resourceId);
OnmsResource resource = getKscReportService().getResourceFromGraph(sample_graph);
PrefabGraph[] graph_options = getResourceService().findPrefabGraphsForResource(resource);
PrefabGraph display_graph = null;
if (graph_options.length > 0) {
if (prefabReportName == null) {
display_graph = graph_options[0];
} else {
display_graph = getPrefabGraphFromList(graph_options, sample_graph.getGraphtype());
}
}
Calendar begin_time = Calendar.getInstance();
Calendar end_time = Calendar.getInstance();
KSC_PerformanceReportFactory.getBeginEndTime(sample_graph.getTimespan(), begin_time, end_time);
KscResultSet resultSet = new KscResultSet(sample_graph.getTitle(), begin_time.getTime(), end_time.getTime(), resource, display_graph);
ModelAndView modelAndView = new ModelAndView("KSC/customGraphEditDetails");
modelAndView.addObject("resultSet", resultSet);
modelAndView.addObject("prefabGraphs", graph_options);
modelAndView.addObject("timeSpans", getKscReportService().getTimeSpans(false));
modelAndView.addObject("timeSpan", sample_graph.getTimespan());
int graph_index = editor.getWorkingGraphIndex();
int max_graphs = report.getGraphs().size();
if (graph_index == -1) {
graph_index = max_graphs++;
}
modelAndView.addObject("graphIndex", graph_index);
modelAndView.addObject("maxGraphIndex", max_graphs);
return modelAndView;
}
Aggregations