gpt4 book ai didi

java - 如何向 thorntail 添加自定义 undertow HttpHandler (fka.wildfly swarm)

转载 作者:行者123 更新时间:2023-12-02 11:07:51 25 4
gpt4 key购买 nike

我开始使用thorntail V4 (www.thorntail.io)(以前称为wildfly swarm)来创建微服务。是的,我知道该网站将其称为“概念证明”。 Thorntail 附带 Undertow (www.undertow.io)。

有谁知道如何添加或注册自定义 undertow HttpHandler?

如何获取链中的下一个 HttpHandler 以便在 handleRequest() 中调用它?

我当前的 HttpHandler 如下所示:

import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

@ApplicationScoped
public class MyCustomHttpHandler implements HttpHandler {

@Inject
private HttpHandler next; // how do i get the next HttpHandler?

public MyCustomHttpHandler() {
System.out.println("MyCustomHttpHandler.java constructed"); // never gets called. How do i register it in Thorntail?
}

@Override
public void handleRequest(HttpServerExchange httpServerExchange) throws Exception {
// never gets called :/
System.out.println(String.format("HttpHandler next=%s", next));

// How do i get next? Is @Inject the way to go?
}
}

提前致谢。

顺便说一句。有人可以添加“thorntail”标签吗?我的 StackOverflow-Rep 不允许这样做。

最佳答案

您的处理程序应如下所示:

public class MyCustomHttpHandler implements HttpHandler {

private HttpHandler next;

public MyCustomHttpHandler(HttpHandler next) {
this.next = next;
System.out.println("MyCustomHttpHandler.java constructed"); // never gets called. How do i register it in Thorntail?
}

@Override
public void handleRequest(HttpServerExchange httpServerExchange) throws Exception {
// never gets called :/
System.out.println(String.format("HttpHandler next=%s", next));

// How do i get next? Is @Inject the way to go?
}
}

但是,目前看来 Thorntail v4 不支持将 HttpHandler 任意添加到链中。您可以在这里提出问题吗:https://github.com/thorntail/thorntail/issues

关于java - 如何向 thorntail 添加自定义 undertow HttpHandler (fka.wildfly swarm),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50816609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com