Search in sources :

Example 1 with Stopwords

use of org.edamontology.edammap.core.preprocessing.Stopwords in project edammap by edamontology.

the class Server method run.

private static void run() throws IOException, ParseException {
    paramsMain.add(new Param("Ontology file", ServerArgs.EDAM, new File(args.getEdam()).getName(), "https://github.com/edamontology/edamontology/tree/master/releases"));
    for (Stopwords stopwords : Stopwords.values()) {
        stopwordsAll.put(stopwords, PreProcessor.getStopwords(stopwords));
    }
    processor = new Processor(args.getProcessorArgs());
    if (args.getProcessorArgs().getIdf() != null && !args.getProcessorArgs().getIdf().isEmpty()) {
        idf = new Idf(args.getProcessorArgs().getIdf());
    }
    if (args.getProcessorArgs().getIdfStemmed() != null && !args.getProcessorArgs().getIdfStemmed().isEmpty()) {
        idfStemmed = new Idf(args.getProcessorArgs().getIdfStemmed());
    }
    logger.info("Loading concepts");
    concepts = Edam.load(args.getEdam());
    logger.info("Configuring server");
    final ResourceConfig rc = new ResourceConfig().packages("org.edamontology.edammap.server");
    // TODO .property(JsonGenerator.PRETTY_PRINTING, true);
    HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(args.getBaseUri() + "/" + args.getPath() + "/api"), rc, false);
    final StaticHttpHandler filesHttpHandler = new StaticHttpHandler(args.getFiles());
    filesHttpHandler.setDirectorySlashOff(true);
    httpServer.getServerConfiguration().addHttpHandler(filesHttpHandler, "/" + args.getPath() + "/*");
    httpServer.getServerConfiguration().addHttpHandler(new HttpHandler() {

        @Override
        public void service(Request request, Response response) throws Exception {
            // TODO replace null with request.getParameterMap()
            String responseText = Resource.runGet(null, request);
            response.setContentType(MediaType.TEXT_HTML);
            response.setContentLength(responseText.length());
            response.getWriter().write(responseText);
        }
    }, "/" + args.getPath() + "/");
    if (args.getLog() != null) {
        Path accessDir = Paths.get(args.getLog() + "/access");
        if (!Files.exists(accessDir)) {
            Files.createDirectory(accessDir);
        }
        final AccessLogBuilder builder = new AccessLogBuilder(accessDir + "/edammap-access.log");
        builder.rotatedDaily();
        // builder.format(ApacheLogFormat.COMBINED); // TODO
        builder.instrument(httpServer.getServerConfiguration());
    }
    logger.info("Starting server");
    httpServer.start();
    logger.info("{} has started", version.getName());
}
Also used : Path(java.nio.file.Path) StaticHttpHandler(org.glassfish.grizzly.http.server.StaticHttpHandler) HttpHandler(org.glassfish.grizzly.http.server.HttpHandler) PreProcessor(org.edamontology.edammap.core.preprocessing.PreProcessor) Processor(org.edamontology.edammap.core.processing.Processor) Request(org.glassfish.grizzly.http.server.Request) AccessLogBuilder(org.glassfish.grizzly.http.server.accesslog.AccessLogBuilder) Idf(org.edamontology.edammap.core.idf.Idf) Stopwords(org.edamontology.edammap.core.preprocessing.Stopwords) ParseException(java.text.ParseException) IOException(java.io.IOException) Response(org.glassfish.grizzly.http.server.Response) StaticHttpHandler(org.glassfish.grizzly.http.server.StaticHttpHandler) Param(org.edamontology.edammap.core.output.Param) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ParseException (java.text.ParseException)1 Idf (org.edamontology.edammap.core.idf.Idf)1 Param (org.edamontology.edammap.core.output.Param)1 PreProcessor (org.edamontology.edammap.core.preprocessing.PreProcessor)1 Stopwords (org.edamontology.edammap.core.preprocessing.Stopwords)1 Processor (org.edamontology.edammap.core.processing.Processor)1 HttpHandler (org.glassfish.grizzly.http.server.HttpHandler)1 HttpServer (org.glassfish.grizzly.http.server.HttpServer)1 Request (org.glassfish.grizzly.http.server.Request)1 Response (org.glassfish.grizzly.http.server.Response)1 StaticHttpHandler (org.glassfish.grizzly.http.server.StaticHttpHandler)1 AccessLogBuilder (org.glassfish.grizzly.http.server.accesslog.AccessLogBuilder)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1