I'm trying to build an api server on Jetty.
I want to have multiple apis on routes that look like /apis/api1/endpoint, /apis/api2/endpoint, /apis/api3/endpoint, etc
Essentially I have a HandlerWrapper, that contains a HandlerList of ContextHandlerCollections that in essence just does:
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
}
Now when I try to do:
curl localhost:port/apis/api1/endpoint
I get a 404 not found but I see in the logs the statement "This is an api request".
Any hints?
I basically want one ContextHandlerCollection for each api1, api2 etc. And the ContextHandlerCollection should be composed of a set of endpoint-specific handlers to choose from.
What am I missing?
Cheers,
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…