From c86791864172ea78e46b45897eebe4754e15567a Mon Sep 17 00:00:00 2001 From: Mihai Andronache Date: Sat, 28 Oct 2017 20:00:13 +0300 Subject: [PATCH] LogsResource added --- .../java/co/comdor/rest/LogsResource.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/java/co/comdor/rest/LogsResource.java diff --git a/src/main/java/co/comdor/rest/LogsResource.java b/src/main/java/co/comdor/rest/LogsResource.java new file mode 100644 index 0000000..2e5b098 --- /dev/null +++ b/src/main/java/co/comdor/rest/LogsResource.java @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2017, Mihai Emil Andronache + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1)Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2)Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3)Neither the name of comdor nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package co.comdor.rest; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; +import java.io.File; + +/** + * REST resource for log files. + * @author Mihai Andronache (amihaiemil@gmail.com) + * @version $Id$ + * @since 0.0.1 + */ +@Path("/logs/") +public final class LogsResource { + + /** + * Fetch the log file of an Action by name. + * @param name The log file's name. + * @return HTTP Response. + */ + @Path("/{name}") + @GET + public Response getActionLogs(@PathParam("name") final String name) { + final String logroot = System.getProperty("LOG_ROOT"); + Response response = Response.noContent().build(); + if(logroot != null) { + final File log = new File(logroot + "/comdor/ActionsLogs/" + name); + if(log.exists()) { + response = Response.ok() + .entity(log) + .header( + "Content-Type", + "text/plain; charset=UTF-8" + ).build(); + } + } + return response; + } +}