mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
nb endpoint additions
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
package io.nosqlbench.docsys.endpoints;
|
||||
|
||||
import io.nosqlbench.docsys.api.Docs;
|
||||
import io.nosqlbench.docsys.api.DocsBinder;
|
||||
import io.nosqlbench.docsys.api.DocsNameSpace;
|
||||
import io.nosqlbench.docsys.api.WebServiceObject;
|
||||
import io.nosqlbench.docsys.core.DocsysPathLoader;
|
||||
import io.nosqlbench.docsys.core.PathWalker;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.docsys.api.DocsNameSpace;
|
||||
import io.nosqlbench.docsys.api.Docs;
|
||||
import io.nosqlbench.docsys.api.DocsBinder;
|
||||
import io.nosqlbench.docsys.api.WebServiceObject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.IOException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -29,7 +29,7 @@ public class DocsysMarkdownEndpoint implements WebServiceObject {
|
||||
private DocsBinder enabled;
|
||||
private DocsBinder disabled;
|
||||
|
||||
private AtomicLong version = new AtomicLong(System.nanoTime());
|
||||
private final AtomicLong version = new AtomicLong(System.nanoTime());
|
||||
private final Set<String> enables = new HashSet<>();
|
||||
|
||||
@GET
|
||||
@@ -128,25 +128,51 @@ public class DocsysMarkdownEndpoint implements WebServiceObject {
|
||||
return list;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("file")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String getFileByPath(@QueryParam("path") String pathspec) {
|
||||
return getFile(pathspec);
|
||||
}
|
||||
|
||||
// @GET
|
||||
// @Path("file")
|
||||
// @Produces(MediaType.TEXT_PLAIN)
|
||||
// public String getFileByPath(@QueryParam("path") String pathspec) {
|
||||
// return getFile(pathspec);
|
||||
// }
|
||||
//
|
||||
/**
|
||||
* @param pathspec the path as known to the manifest
|
||||
* @return The contents of a file
|
||||
*/
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Path(value = "markdown/{pathspec:.*}")
|
||||
public String getFileInPath(@PathParam("pathspec") String pathspec) {
|
||||
return getFile(pathspec);
|
||||
@Path(value = "{pathspec:.*}")
|
||||
public Response getFileInPath(@PathParam("pathspec") String pathspec) {
|
||||
try {
|
||||
java.nio.file.Path path = findPath(pathspec);
|
||||
String contentType = Files.probeContentType(path);
|
||||
MediaType mediaType = MediaType.valueOf(contentType);
|
||||
|
||||
return Response.ok(path.toFile(),mediaType).build();
|
||||
} catch (Exception e) {
|
||||
return Response.serverError().entity(e.getMessage()).build();
|
||||
}
|
||||
}
|
||||
|
||||
private String getFile(String pathspec) {
|
||||
// private String getFile(String pathspec) {
|
||||
// pathspec = URLDecoder.decode(pathspec, StandardCharsets.UTF_8);
|
||||
// for (java.nio.file.Path path : enabled.getPaths()) {
|
||||
// java.nio.file.Path resolved = path.resolve(pathspec);
|
||||
// if (Files.isDirectory(resolved)) {
|
||||
// throw new RuntimeException("Path is a directory: '" + pathspec + "'");
|
||||
// }
|
||||
// if (Files.exists(resolved)) {
|
||||
// try {
|
||||
// String content = Files.readString(resolved, StandardCharsets.UTF_8);
|
||||
// return content;
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// throw new RuntimeException("Unable to find any valid file at '" + pathspec + "'");
|
||||
// }
|
||||
|
||||
public java.nio.file.Path findPath(String pathspec) {
|
||||
pathspec = URLDecoder.decode(pathspec, StandardCharsets.UTF_8);
|
||||
for (java.nio.file.Path path : enabled.getPaths()) {
|
||||
java.nio.file.Path resolved = path.resolve(pathspec);
|
||||
@@ -154,15 +180,11 @@ public class DocsysMarkdownEndpoint implements WebServiceObject {
|
||||
throw new RuntimeException("Path is a directory: '" + pathspec + "'");
|
||||
}
|
||||
if (Files.exists(resolved)) {
|
||||
try {
|
||||
String content = Files.readString(resolved, StandardCharsets.UTF_8);
|
||||
return content;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Unable to find any valid file at '" + pathspec + "'");
|
||||
|
||||
}
|
||||
|
||||
private void init(boolean reload) {
|
||||
|
||||
Reference in New Issue
Block a user