我开始使用thorntail V4(www.thorntail.io)(以前称为wildfly swarm)来创建微服务。是的,我知道网站将其称为“概念证明”。 Thorntail船舶(www.undertow.io)。
有谁知道,如何添加或注册自定义功能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不允许这样做。
答案 0 :(得分:1)
您的处理程序应如下所示:
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