小编Abh*_*nan的帖子

Jetty:如何嵌套HandlerWrapper、HandlerList、ContextHandlerCollection、ContextHandler

我正在尝试在 Jetty 上构建一个 api 服务器。

我希望在 /apis/api1/endpoint、/apis/api2/endpoint、/apis/api3/endpoint 等路径上有多个 api

本质上我有一个 HandlerWrapper,它包含 ContextHandlerCollections 的 HandlerList,本质上只是做:

public void handle(...) {
    if (uri.startsWith("/apis/")) {
        log.info("This is an api request");
        this.getHandlerList.handle(...)
    } else {
        super.handle()
    }
}

private HandlerList getHandlerList() {
    HandlerList handlerList = new HandlerList();
    ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
    ContextHandler api1 = new ContextHandler("/apis/api1/endpoint");
    api1.setHandler(new Api1Handler());
    contextHandlerCollection.addHandler(api1);
    handlerList.addHandler(contextHandlerCollection);
    return handlerList
}
Run Code Online (Sandbox Code Playgroud)

现在当我尝试这样做时:

curl localhost:port/apis/api1/endpoint
Run Code Online (Sandbox Code Playgroud)

我收到 404 not found,但我在日志中看到语句“这是一个 api 请求”。

有什么提示吗?

我基本上希望每个 api1、api2 等都有一个 ContextHandlerCollection。并且 ContextHandlerCollection 应该由一组特定于端点的处理程序组成以供选择。

我缺少什么?

干杯,

java jetty embedded-jetty

0
推荐指数
1
解决办法
1672
查看次数

标签 统计

embedded-jetty ×1

java ×1

jetty ×1