需要使用openapi 3.0记录jetty服务器rest api

mo49yndu  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(263)

我正在尝试将openapi3.0(或swagger)集成到具有 jetty server . 我的服务器使用连接线程池来接受请求,然后不同的处理程序调用相应的api来执行它们。服务器代码如下所示-

package com.example.hfs;

import com.example.hfs.handlers.*;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.util.thread.QueuedThreadPool;

public class StartHFS {

    public static void main(String[] args) throws Exception {
        System.out.println("StartHFS");

        // Create and configure a ThreadPool.
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setName("server");

        // Create a Server instance.
        Server server = new Server(threadPool);

        // HTTP configuration and connection factory.
        HttpConfiguration httpConfig = new HttpConfiguration();
        HttpConnectionFactory http11 = new HttpConnectionFactory(httpConfig);

        // Create a ServerConnector to accept connections from clients.
        ServerConnector connector = new ServerConnector(server, 1, 1, http11);
        connector.setPort(8080);
        connector.setHost("127.0.0.1");
        connector.setAcceptQueueSize(128);
        server.addConnector(connector);

        addHandlers(server);

        // Start the Server so it starts accepting connections from clients.
        server.start();
        server.join();

        System.out.println("StartHFS DONE");
    }

    static void addHandlers(final Server server) {
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        server.setHandler(contexts);

        ContextHandler logHandler = new ContextHandler("/log");
        logHandler.setHandler(new LoggingHandler());
        contexts.addHandler(logHandler);

        ContextHandler helloHandler = new ContextHandler("/hello");
        helloHandler.setHandler(new HelloHandler());
        contexts.addHandler(helloHandler);

        ContextHandler featureStoreHandler = new ContextHandler("/featurestore");
        featureStoreHandler.setHandler(new FeatureStoreHandler());
        contexts.addHandler(featureStoreHandler);

        ContextHandler featureGroupsHandler = new ContextHandler("/featuregroups");
        featureGroupsHandler.setHandler(new FeatureGroupsHandler());
        contexts.addHandler(featureGroupsHandler);

        // Add Swagger-UI handler
        ContextHandler swaggerUIHandler = new ContextHandler("/docs/");
        swaggerUIHandler.setHandler(new SwaggerUIHandler());
        contexts.addHandler(swaggerUIHandler); 
    }

由于我对这个jetty和openapi非常陌生,我不知道如何开始与这种类型的服务器集成?
我在这个github上尝试了这个解决方案,但无法理解如何将这个解决方案应用到我的服务器类型。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题