Java Code Examples for io.javalin.Context#status()

The following examples show how to use io.javalin.Context#status() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllReportsController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        List<Report> reports = reportDao.fetch();

        context.json(reports);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 2
Source File: RawFileController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("id"));
        String name = context.param("name");

        Report report = reportDao.fetch(id);

        File file = getReportFile(report, name);

        context.result(new FileInputStream(file))
                .header("Content-Length: ", String.valueOf(FileUtils.sizeOf(file)))
                .header("Content-Type", "application/octet-stream");
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 3
Source File: AllAggregatedReportsController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        List<Report> reports = reportDao.fetchAllAggregated();

        context.json(reports);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 4
Source File: SutNodeInfoController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int testId = Integer.parseInt(context.param("test"));

        List<SutNodeInfo> sutNodeInfo = dao.fetchByTest(testId);

        context.json(sutNodeInfo);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 5
Source File: LatencyReportController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("id"));

        Report report = reportDao.fetch(id);

        LatencyResponse response = new LatencyResponse();

        processReports(report, response);

        context.json(response);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 6
Source File: AggregatedLatencyReportController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int testId = Integer.parseInt(
                Objects.requireNonNull(context.param("id"), "The ID must be provided"));

        int testNumber = Integer.parseInt(
                Objects.requireNonNull(context.param("number"), "The test number must be provided"));

        Report report = reportDao.fetchAggregated(testId, testNumber);

        LatencyResponse response = new LatencyResponse();

        processReports(report, response);

        context.json(response);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 7
Source File: AggregatedLatencyStatisticsReportController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int testId = Integer.parseInt(context.param("id"));
        int testNumber = Integer.parseInt(context.param("number"));

        Report report = reportDao.fetchAggregated(testId, testNumber);

        LatencyStatisticsResponse response = new LatencyStatisticsResponse();

        processReports(report, response);

        context.json(response);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }


}
 
Example 8
Source File: LatencyStatisticsReportController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("id"));

        Report report = reportDao.fetch(id);

        LatencyStatisticsResponse response = new LatencyStatisticsResponse();

        processReports(report, response);

        context.json(response);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }


}
 
Example 9
Source File: ReportController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("id"));

        Report report = reportDao.fetch(id);

        if (report != null) {
            context.json(report);
        }
        else {
            context.status(404);
        }
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }


}
 
Example 10
Source File: RateReportController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("id"));

        Report report = reportDao.fetch(id);

        SingleData<Long> rateData = processReport(report, report.getTestHostRole());

        RateResponse rateResponse = new RateResponse();
        rateResponse.setPeriods(rateData.getPeriods());
        rateResponse.setRate(rateData.getValues());

        context.json(rateResponse);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 11
Source File: RateStatisticsReportController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("id"));

        Report report = reportDao.fetch(id);

        SingleData<Long> rateData = processReport(report, report.getTestHostRole());

        RateStatisticsResponse rateResponse = new RateStatisticsResponse();
        rateResponse.addStatistics(rateData.getStatistics());

        context.json(rateResponse);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 12
Source File: AggregatedRateStatisticsReportController.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int testId = Integer.parseInt(context.param("id"));
        int testNumber = Integer.parseInt(context.param("number"));
        String hostRole = context.param("role");

        Report report = reportDao.fetchAggregated(testId, testNumber);

        SingleData<Long> rateData = processReport(report, hostRole);

        RateStatisticsResponse rateResponse = new RateStatisticsResponse();
        rateResponse.addStatistics(rateData.getStatistics());

        context.json(rateResponse);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 13
Source File: TestPropertiesController.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("test"));
        int number = Integer.parseInt(context.param("number"));

        List<Report> reports = reportDao.fetch(id, number);
        List<ExtendedTestProperties> testPropertiesList = new LinkedList<>();

        for (Report report : reports) {
            String location = report.getLocation();
            File file = new File(location, "test.properties");

            TestProperties tp = new TestProperties();

            if (HostTypes.isWorker(report.getTestHostRole())) {
                PropertyReader reader = new PropertyReader();

                reader.read(file, tp);

                ExtendedTestProperties etp = new ExtendedTestProperties(tp);

                etp.setRole(report.getTestHostRole());
                testPropertiesList.add(etp);
            }
        }

        context.json(testPropertiesList);
    }
    catch (Throwable t) {
        logger.error(t.getMessage(), t);
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 14
Source File: AggregatedRateReportController.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int testId = Integer.parseInt(
                Objects.requireNonNull(context.param("id"), "The ID must be provided"));

        int testNumber = Integer.parseInt(
                Objects.requireNonNull(context.param("number"), "The test number must be provided"));

        String hostRole = context.param("role");

        Report report = reportDao.fetchAggregated(testId, testNumber);

        SingleData<Long> rateData = processReport(report, hostRole);

        RateResponse rateResponse = new RateResponse();
        rateResponse.setPeriods(rateData.getPeriods());
        rateResponse.setRate(rateData.getValues());

        context.json(rateResponse);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 15
Source File: ReportPropertiesController.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("id"));

        Report report = reportDao.fetch(id);

        String location = report.getLocation();
        File file = new File(location, "test.properties");

        TestProperties tp = new TestProperties();

        List<ExtendedTestProperties> testPropertiesList = new LinkedList<>();

        if (HostTypes.isWorker(report.getTestHostRole())) {
            PropertyReader reader = new PropertyReader();

            reader.read(file, tp);

            ExtendedTestProperties etp = new ExtendedTestProperties(tp);
            etp.setRole(report.getTestHostRole());
            testPropertiesList.add(etp);
            context.json(testPropertiesList);
        }
        else {
            context.status(500);
            context.result(String.format("Unhandled node type for the report: %s", report.getTestHostRole()));
        }
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        logger.error(t.getMessage(), t);
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}
 
Example 16
Source File: FileListController.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(Context context) {
    try {
        int id = Integer.parseInt(context.param("id"));

        Report report = reportDao.fetch(id);

        File location = new File(report.getLocation());

        if (!location.exists()) {
            context.status(404);
            context.result(String.format("Not found: %s", location.getPath()));

            return;
        }

        if (!location.isDirectory()) {
            throw new MaestroException("Invalid file type: expected a directory, but got something else");
        }

        File files[] = location.listFiles(file -> {
            String extensions[] = { ".csv", ".hdr", ".dat", ".properties", ".json", ".xz"};

            for (String extension : extensions) {
                if (file.getName().endsWith(extension)) {
                    return true;
                }
            }

            return false;
        });

        List<Archive> fileList = Arrays.asList(files).stream().map(f -> new Archive(f, id)).collect(Collectors.toList());

        context.json(fileList);
    }
    catch (DataNotFoundException e) {
        context.status(404);
        context.result(String.format("Not found: %s", e.getMessage()));
    }
    catch (Throwable t) {
        context.status(500);
        context.result(String.format("Internal server error: %s", t.getMessage()));
    }
}